Package org.apache.qpid.protonj2.buffer
Interface ProtonBufferComponent
- All Known Implementing Classes:
Netty4ToProtonBufferAdapter
,Netty5ToProtonBufferAdapter
,ProtonByteArrayBuffer
public interface ProtonBufferComponent
A buffer component represents a single component of the memory backing
a
ProtonBuffer
which could be a buffer that inherently made up of more
than one section of memory or it could be a intentional composite buffer
that collect individual buffers each with their own component backing.-
Method Summary
Modifier and TypeMethodDescriptionadvanceReadOffset
(int amount) Advances the internally maintained read offset for this component by the given amount.advanceWriteOffset
(int amount) Advances the internally maintained write offset for this component by the given amount.Creates and returns a newProtonBufferIterator
that iterates from the current read offset and continues until all readable bytes have been traversed.long
Gets the native address of the backing buffer if one exists otherwise returns 0.long
Gets the native address where reads from this buffer component should start.long
Gets the native address where write to this buffer component should start.byte[]
Returns the readable array if one exists or throws an exception.int
int
Returns the readable array if one exists or throws an exception.int
Returns the number of readable bytes in the buffer safely regards of the actual memory backing this component.byte[]
Returns the writable array if one exists or throws an exception.int
int
Returns the writableByteBuffer
if one exists or throws an exception.int
Returns the number of writable bytes in the buffer safely regards of the actual memory backing this component.boolean
boolean
unwrap()
Unwraps the backing resource of this buffer component which can be an external buffer type or other managed resource.
-
Method Details
-
unwrap
Object unwrap()Unwraps the backing resource of this buffer component which can be an external buffer type or other managed resource.- Returns:
- the resource backing this component or null if none exists.
-
getReadableBytes
int getReadableBytes()Returns the number of readable bytes in the buffer safely regards of the actual memory backing this component.- Returns:
- the number of readable bytes in this buffer component
-
hasReadbleArray
boolean hasReadbleArray()- Returns:
- true if the component is backed by a byte array that has a readable portion.
-
advanceReadOffset
Advances the internally maintained read offset for this component by the given amount. If the amount to advance is greater than the available readable bytes an exception is thrown.- Parameters:
amount
- The amount to advance the read offset of this component by.- Returns:
- this
ProtonBufferComponent
instance. - Throws:
UnsupportedOperationException
- if the component is not backed by a readable array.
-
getReadableArray
byte[] getReadableArray()Returns the readable array if one exists or throws an exception.- Returns:
- the readable array that backs this buffer component.
- Throws:
UnsupportedOperationException
- if the component is not backed by an array or has no readable bytes.
-
getReadableArrayOffset
int getReadableArrayOffset()- Returns:
- the offset into the readable array where the readable bytes begin.
- Throws:
UnsupportedOperationException
- if the component is not backed by a readable array.
-
getReadableArrayLength
int getReadableArrayLength()- Returns:
- the length of the readable array from the offset that is owned by this component..
- Throws:
UnsupportedOperationException
- if the component is not backed by a readable array.
-
getReadableBuffer
ByteBuffer getReadableBuffer()Returns the readable array if one exists or throws an exception.- Returns:
- the readable array that backs this buffer component.
- Throws:
UnsupportedOperationException
- if the component does not contain a readable portion.
-
getWritableBytes
int getWritableBytes()Returns the number of writable bytes in the buffer safely regards of the actual memory backing this component.- Returns:
- the number of writable bytes in this buffer component
-
advanceWriteOffset
Advances the internally maintained write offset for this component by the given amount. If the amount to advance is greater than the available writable bytes an exception is thrown.- Parameters:
amount
- The amount to advance the write offset of this component by.- Returns:
- this
ProtonBufferComponent
instance. - Throws:
UnsupportedOperationException
- if the component is not backed by a writable array.
-
hasWritableArray
boolean hasWritableArray()- Returns:
- true if the component is backed by a byte array that has writable bytes.
-
getWritableArray
byte[] getWritableArray()Returns the writable array if one exists or throws an exception.- Returns:
- the writable array that backs this buffer component.
- Throws:
UnsupportedOperationException
- if the component is not backed by an writable array.
-
getWritableArrayOffset
int getWritableArrayOffset()- Returns:
- the offset into the writable array where the writable bytes begin.
- Throws:
UnsupportedOperationException
- if the component is not backed by a writable array.
-
getWritableArrayLength
int getWritableArrayLength()- Returns:
- the length of the writable array from the offset that is owned by this component..
- Throws:
UnsupportedOperationException
- if the component is not backed by a writable array.
-
getWritableBuffer
ByteBuffer getWritableBuffer()Returns the writableByteBuffer
if one exists or throws an exception.- Returns:
- the writable buffer that backs this buffer component.
- Throws:
UnsupportedOperationException
- if the component does not contain a writable portion.
-
bufferIterator
ProtonBufferIterator bufferIterator()Creates and returns a newProtonBufferIterator
that iterates from the current read offset and continues until all readable bytes have been traversed. The source buffer read and write offsets are not modified by an iterator instance.The caller must ensure that the source buffer lifetime extends beyond the lifetime of the returned
ProtonBufferIterator
.- Returns:
- a new buffer iterator that iterates over the readable bytes.
-
getNativeAddress
long getNativeAddress()Gets the native address of the backing buffer if one exists otherwise returns 0.The returned address is the base address for the memory region that back this buffer which should not be used for reads and write as the backing region could be larger and not all portions of the backing region might be owned by this buffer component. The caller should use the methods
getNativeReadAddress()
andgetNativeWriteAddress()
which each use this method to compute where these value actually fall in the native memory region.- Returns:
- The native memory address for the region backing this buffer, if any, otherwise 0.
-
getNativeReadAddress
long getNativeReadAddress()Gets the native address where reads from this buffer component should start.- Returns:
- The native memory address where reads start, if any, otherwise 0.
-
getNativeWriteAddress
long getNativeWriteAddress()Gets the native address where write to this buffer component should start.- Returns:
- The native memory address where writing should start, if any, otherwise 0.
-