This class leaves undefined the storage mechanism for the bytes (typically byte[] or
java.nio.ByteBuffer), while remaining definite that it is an indexable sequence of
bytes. A concrete class that extends this one must provide elementary accessors
byteAtImpl(int), storeAtImpl(byte, int) that abstract this storage, a factory
getNIOByteBufferImpl() for ByteBuffers that wrap the storage, and a factory
for slices getBufferSlice(int, int, int, int).
The sub-class constructor must specify the feature flags (see
BaseBuffer(int, int, int[], int[])), set index0, shape and
strides, and finally check the client capabilities with checkRequestFlags(int).
A sub-class intended to represent slices of an exporter that counts its exports, as part of a
locking protocol like bytearray's, must override getRoot() so that a call
to release() on a view of slice, propagates to the buffer view that provided the slice.
Access methods provided here necessarily work with the abstracted byteAtImpl(int),
storeAtImpl(byte, int) interface, but subclasses are able to override them with more
efficient versions that employ knowledge of the particular storage type used.
This base implementation is writable only if PyBUF#WRITABLE is in the feature flags
passed to the constructor. Otherwise, all methods for write access raise a TypeError
and isReadonly() returns true. However, a client intending to write should
have presented PyBUF#WRITABLE in its client request flags when getting the buffer, and
been prevented by a BufferError exception at that point.
At the time of writing, only one-dimensional buffers of item size one are used in the Jython core.
| Modifier and Type | Field and Description |
|---|---|
| protected int | |
| private int | gFeatureFlags
Bit pattern using the constants defined in |
| protected int | index0
Absolute byte-index in the storage of |
| protected BufferProtocol | obj
The object that exported this buffer (or |
| protected int[] | shape
The dimensions of the array represented by the buffer. |
| protected int[] | strides
Step sizes in the underlying buffer essential to correct translation of an index (or indices) into an index into the storage. |
| Access | Constructor and Description |
|---|---|
| protected | BaseBuffer(int
bit pattern that specifies the features allowed featureFlags, int index into storage of index0, int[] item[0,...,0]elements in each dimension shape, int[] between successive elements in each dimension strides)Construct an instance of |
| Modifier and Type | Method and Description |
|---|---|
| protected final void | addFeatureFlags(int
to set within the feature flags flags)Add to the features of this buffer expressed using the constants defined in |
| private static PyException | Returns: PyException (BufferError) specifying the mis-matchof the mis-match between buffer and requested features syndrome)General purpose method to construct an exception to throw according to the syndrome. |
| protected static PyException | Returns: the error as a PyExceptionConvenience method to create (for the caller to throw) a
|
| protected static PyException | Returns: the error as a PyExceptionname of operation or null operation)Convenience method to create (for the caller to throw) a
|
| protected static PyException | Returns: the error as a PyExceptionConvenience method to create (for the caller to throw) a
|
| public byte | byteAt(int
to retrieve from index)Implements org. Return the byte indexed from a one-dimensional buffer with item size one. |
| public byte | byteAt(int...
specifying location to retrieve from indices)Implements org. Return the byte indexed from an N-dimensional buffer with item size one. |
| protected abstract byte | Returns: the byte at byteIndexbyte-index of location to retrieve byteIndex)Retrieve the byte at the given index in the underlying storage treated as a flat sequence of bytes. |
| public int | byteIndex(int
item-index from consumer index)Implements org. Convert an item index (for a one-dimensional buffer) to an absolute byte index in the storage shared by the exporter. |
| public int | byteIndex(int...
n-dimensional item-index from consumer indices)Implements org. Convert a multi-dimensional item index to an absolute byte index in the storage shared by the exporter. |
| protected int | Returns: greatest absolute index in storageCalculate the absolute byte index in the storage array of the last item of the exported data (if we are not using indirection). |
| protected int | Returns: least absolute index in storageCalculate the absolute byte index in the storage array of the first item of the exported data (if we are not using indirection). |
| pack-priv int | Returns: number of dimensionsinto the buffer (to test) indices)Check the number of indices (but not their values), raising a Python BufferError if this does not match the number of dimensions. |
| pack-priv void | checkDimension(int
number of dimensions being assumed by caller n)Check that the number offered is in fact the number of dimensions in this buffer, raising a Python BufferError if this does not match the number of dimensions. |
| protected void | |
| protected void | checkRequestFlags(int
capabilities of and navigation assumed by the consumer flags)General purpose method to check the consumer request flags (typically the argument to
|
| protected void | |
| public void | |
| public void | copyFrom(byte[]
source byte array src, int location in source of first byte to copy srcPos, int starting item-index in the destination (i.e. destIndex, int this)number of items to copy in count)Implements org. Copy from a slice of a (Java) byte array into the buffer starting at a given destination item-index. |
| public void | copyFrom(PyBuffer
source buffer src)Implements org. Copy the whole of another |
| public void | copyTo(byte[]
destination byte array dest, int byte-index in the destination array of the byte [0] destPos)Implements org. Copy the contents of the buffer to the destination byte array. |
| public void | copyTo(int
starting item-index in the source buffer srcIndex, byte[] destination byte array dest, int byte-index in the destination array of the source item [0,...] destPos, int number of items to copy count)Implements org. Copy a simple slice of the buffer-view to the destination byte array, defined by a starting
item-index in the source buffer and the |
| protected static PyException | Returns: the error as a PyExceptionConvenience method to create (for the caller to throw) a
|
| public PyBuffer. | getBuf()
Implements org.
References Deprecated
PyBuffer.Pointer is deprecated or references (maybe indirectly) at least one deprecated element.
Return a structure describing the slice of a byte array that holds the data being exported to the consumer. |
| public synchronized PyBuffer | getBuffer(int
specifying features demanded and the navigational capabilities of the consumer flags)Implements org. Method by which the consumer requests the buffer from the exporter. |
| public synchronized BaseBuffer | getBufferAgain(int flags)
Allow an exporter to re-use this object again even if it has been "finally" released. |
| public PyBuffer | getBufferSlice(int
specifying features demanded and the navigational capabilities of the consumer flags, int index in the current buffer start, int number of items in the required slice count)Implements org. Equivalent to |
| protected final int | Returns: capabilities of and navigation required by the exporter/bufferGet the features of this buffer expressed using the constants defined in |
| public String | getFormat()
Implements org. A format string in the language of Python structs describing how the bytes of each item should be interpreted. |
| public int | getItemsize()
Implements org. The number of bytes stored in each indexable item. |
| public int | getLen()
Implements org. The total number of bytes represented by the view, which will be the product of the elements
of the |
| public int | |
| public ByteBuffer | getNIOByteBuffer()
Implements org. Obtain a |
| protected abstract ByteBuffer | getNIOByteBufferImpl()
Create a new |
| public final BufferProtocol | getObj()
Implements org. Return the underlying exporting object (or |
| public PyBuffer. | getPointer(int
in the buffer to position the pointer index)Implements org.
References Deprecated
PyBuffer.Pointer is deprecated or references (maybe indirectly) at least one deprecated element.
Return a structure describing the position in a byte array of a single item from the data being exported to the consumer. |
| public PyBuffer. | getPointer(int...
multidimensional index at which to position the pointer indices)Implements org.
References Deprecated
PyBuffer.Pointer is deprecated or references (maybe indirectly) at least one deprecated element.
Return a structure describing the position in a byte array of a single item from the data being exported to the consumer, in the case that array may be multi-dimensional. |
| protected PyBuffer | Returns: this buffer (or the root buffer if this is a sliced view)Some |
| public int[] | getShape()
Implements org. An array reporting the size of the buffer, considered as a multidimensional array, in each dimension and (by its length) giving the number of dimensions. |
| protected int | |
| public int[] | getStrides()
Implements org. The |
| public int[] | getSuboffsets()
Implements org. The |
| public boolean | hasArray()
Implements org. Report whether the exporter is able to offer direct access to the exported storage as a Java
byte array (through the API that involves class |
| public int | intAt(int
to retrieve from index)Implements org. Return the unsigned byte value indexed from a one-dimensional buffer with item size one. |
| public int | intAt(int...
specifying location to retrieve from indices)Implements org. Return the unsigned byte value indexed from an N-dimensional buffer with item size one. |
| private boolean | |
| public boolean | isContiguous(char
'C', 'F' or 'A', as the storage order is C, Fortran or either. order)Implements org. Enquire whether the array is represented contiguously in the backing storage, according to C or Fortran ordering. |
| private boolean | |
| public boolean | isReadonly()
Implements org. Determine whether the consumer is entitled to write to the exported storage. |
| public boolean | isReleased()
Implements org. True only if the buffer has been released with (the required number of calls to)
|
| protected static PyException | Returns: the error as a PyExceptionConvenience method to create (for the caller to throw) a
|
| public void | release()
Implements org. A buffer is (usually) a view onto to the internal state of an exporting object, and that object may have to restrict its behaviour while the buffer exists. |
| protected void | releaseAction()
This method will be called when the number of calls to |
| protected final void | removeFeatureFlags(int
to clear within the feature flags flags)Remove features from this buffer expressed using the constants defined in |
| protected final void | setFeatureFlags(int
new value for the feature flags flags)Set the features of this buffer expressed using the constants defined in |
| public void | storeAt(byte
to store value, int to location index)Implements org. Store the given byte at the indexed location in of a one-dimensional buffer with item size one. |
| public void | storeAt(byte
to store value, int... specifying location to store at indices)Implements org. Store the given byte at the indexed location in of an N-dimensional buffer with item size one. |
| protected abstract void | storeAtImpl(byte
to store value, int byte-index of location to retrieve byteIndex)Store the byte at the given index in the underlying storage treated as a flat sequence of bytes. |
| public String | toString()
Overrides java. Implements org. The toString() method of a buffer reproduces the values in the buffer (as unsigned integers)
as the character codes of a |