Class ProtonNettyByteBuffer
- java.lang.Object
-
- org.apache.qpid.protonj2.buffer.ProtonNettyByteBuffer
-
- All Implemented Interfaces:
Comparable<ProtonBuffer>
,ProtonBuffer
public final class ProtonNettyByteBuffer extends Object implements ProtonBuffer
Wrapper class for Netty ByteBuf instances
-
-
Constructor Summary
Constructors Constructor Description ProtonNettyByteBuffer(int maximumCapacity)
Creates aProtonNettyByteBuffer
that wraps an NettyByteBuf
that is not pooled and whose maximum capacity is set to the given value.ProtonNettyByteBuffer(io.netty.buffer.ByteBuf toWrap)
Creates a newProtonNettyByteBuffer
which wraps the given NettyByteBuf
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
capacity()
ProtonBuffer
capacity(int newCapacity)
Adjusts the capacity of this buffer.ProtonBuffer
clear()
Reset the read and write offsets to zero and clears the position markers if set previously, this method is not required to reset the data previously written to this buffer.int
compareTo(ProtonBuffer other)
Compares the remaining content of the current buffer with the remaining content of the given buffer, which must not be null.ProtonBuffer
copy()
Create a deep copy of the readable bytes of this ProtonBuffer, the returned buffer can be modified without affecting the contents or position markers of this instance.ProtonBuffer
copy(int index, int length)
Returns a copy of this buffer's sub-region.ProtonBuffer
duplicate()
Create a duplicate of this ProtonBuffer instance that shares the same backing data store and but maintains separate position index values.ProtonBuffer
ensureWritable(int minWritableBytes)
Ensures that the requested number of bytes is available for write operations in the current buffer, growing the buffer if needed to meet the requested writable capacity.boolean
equals(Object other)
byte[]
getArray()
Returns the backing array for this ProtonBuffer instance if there is such an array or throws an exception if this ProtonBuffer implementation has no backing array.int
getArrayOffset()
boolean
getBoolean(int index)
Gets a boolean from the specified index, this method will not modify the read or write index.byte
getByte(int index)
Gets a byte from the specified index, this method will not modify the read or write index.ProtonBuffer
getBytes(int index, byte[] destination)
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.ProtonBuffer
getBytes(int index, byte[] destination, int offset, int length)
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.ProtonBuffer
getBytes(int index, ByteBuffer destination)
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
until the destination's position reaches its limit.ProtonBuffer
getBytes(int index, ProtonBuffer destination)
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
until the destination becomes non-writable.ProtonBuffer
getBytes(int index, ProtonBuffer destination, int length)
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.ProtonBuffer
getBytes(int index, ProtonBuffer destination, int offset, int length)
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.char
getChar(int index)
Gets a 2-byte char from the specified index, this method will not modify the read or write index.double
getDouble(int index)
Gets a double from the specified index, this method will not modify the read or write index.float
getFloat(int index)
Gets a float from the specified index, this method will not modify the read or write index.int
getInt(int index)
Gets a int from the specified index, this method will not modify the read or write index.long
getLong(int index)
Gets a long from the specified index, this method will not modify the read or write index.int
getMaxWritableBytes()
Gets the current maximum number of bytes that can be written to this buffer.int
getReadableBytes()
int
getReadIndex()
short
getShort(int index)
Gets a short from the specified index, this method will not modify the read or write index.short
getUnsignedByte(int index)
Gets a unsigned byte from the specified index, this method will not modify the read or write index.long
getUnsignedInt(int index)
Gets a unsigned int from the specified index, this method will not modify the read or write index.int
getUnsignedShort(int index)
Gets a unsigned short from the specified index, this method will not modify the read or write index.int
getWritableBytes()
int
getWriteIndex()
boolean
hasArray()
int
hashCode()
boolean
isReadable()
boolean
isReadable(int minReadableBytes)
Check if the given number of bytes can be read from the buffer.boolean
isWritable()
boolean
isWritable(int minWritableBytes)
Check if the requested number of bytes can be written into this buffer.ProtonBuffer
markReadIndex()
Marks the current read index so that it can later be restored by a call toProtonBuffer.resetReadIndex()
, the initial mark value is 0.ProtonBuffer
markWriteIndex()
Marks the current write index so that it can later be restored by a call toProtonBuffer.resetWriteIndex()
, the initial mark value is 0.int
maxCapacity()
Returns the number of bytes that this buffer is allowed to grow to when write operations exceed the current capacity value.boolean
readBoolean()
Reads a boolean value from the buffer and advances the read index by one.byte
readByte()
Reads one byte from the buffer and advances the read index by one.ProtonBuffer
readBytes(byte[] destination)
Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the value of the length of the destination array.ProtonBuffer
readBytes(byte[] destination, int length)
Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the length value passed.ProtonBuffer
readBytes(byte[] destination, int offset, int length)
Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the length value passed, the bytes are read into the given buffer starting from the given offset value.ProtonBuffer
readBytes(ByteBuffer destination)
Transfers this buffer's data to the specified destination starting at the currentreadIndex
until the destination's position reaches its limit, and increases thereadIndex
by the number of the transferred bytes.ProtonBuffer
readBytes(ProtonBuffer destination)
Reads bytes from this buffer and writes them into the destination ProtonBuffer incrementing the read index by the value of the number of bytes written to the target.ProtonBuffer
readBytes(ProtonBuffer destination, int length)
Reads bytes from this buffer and writes them into the destination ProtonBuffer incrementing the read index by the number of bytes written.ProtonBuffer
readBytes(ProtonBuffer destination, int offset, int length)
Transfers this buffer's data to the specified destination starting at the currentreadIndex
and increases thereadIndex
by the number of the transferred bytes (=length
).double
readDouble()
Reads a double value from the buffer and advances the read index by eight.float
readFloat()
Reads a float value from the buffer and advances the read index by four.int
readInt()
Reads a integer value from the buffer and advances the read index by four.long
readLong()
Reads a long value from the buffer and advances the read index by eight.short
readShort()
Reads a short value from the buffer and advances the read index by two.ProtonBuffer
resetReadIndex()
Resets the current read index to the previously marked value.ProtonBuffer
resetWriteIndex()
Resets the current write index to the previously marked value.ProtonBuffer
setBoolean(int index, boolean value)
Sets the boolean value at the given write index in this buffer's backing data store.ProtonBuffer
setByte(int index, int value)
Sets the byte value at the given write index in this buffer's backing data store.ProtonBuffer
setBytes(int index, byte[] value)
Transfers the specified source array's data to this buffer starting at the specified absoluteindex
.ProtonBuffer
setBytes(int index, byte[] value, int offset, int length)
Transfers the specified source array's data to this buffer starting at the specified absoluteindex
.ProtonBuffer
setBytes(int index, ByteBuffer value)
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
until the source buffer's position reaches its limit.ProtonBuffer
setBytes(int index, ProtonBuffer value)
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
until the source buffer becomes unreadable.ProtonBuffer
setBytes(int index, ProtonBuffer value, int length)
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
.ProtonBuffer
setBytes(int index, ProtonBuffer value, int offset, int length)
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
.ProtonBuffer
setChar(int index, int value)
Sets the char value at the given write index in this buffer's backing data store.ProtonBuffer
setDouble(int index, double value)
Sets the double value at the given write index in this buffer's backing data store.ProtonBuffer
setFloat(int index, float value)
Sets the float value at the given write index in this buffer's backing data store.ProtonBuffer
setIndex(int readIndex, int writeIndex)
Used to set the read index and the write index in one call.ProtonBuffer
setInt(int index, int value)
Sets the int value at the given write index in this buffer's backing data store.ProtonBuffer
setLong(int index, long value)
Sets the long value at the given write index in this buffer's backing data store.ProtonBuffer
setReadIndex(int index)
Sets the read index for this buffer.ProtonBuffer
setShort(int index, int value)
Sets the short value at the given write index in this buffer's backing data store.ProtonBuffer
setWriteIndex(int index)
Sets the write index for this buffer.ProtonBuffer
skipBytes(int skippedBytes)
Increases the currentreadIndex
of this buffer by the specifiedlength
.ProtonBuffer
slice()
Create a new ProtonBuffer whose contents are a subsequence of the contents of thisProtonBuffer
.ProtonBuffer
slice(int index, int length)
Create a new ProtonBuffer whose contents are a subsequence of the contents of thisProtonBuffer
.ByteBuffer
toByteBuffer()
Returns a ByteBuffer that represents the readable bytes contained in this buffer.ByteBuffer
toByteBuffer(int index, int length)
Returns a ByteBuffer that represents the given span of bytes from the readable portion of this buffer.String
toString()
String
toString(Charset charset)
Returns a String created from the buffer's underlying bytes using the specifiedCharset
for the newly created String.io.netty.buffer.ByteBuf
unwrap()
Return the underlying buffer object that backs thisProtonBuffer
instance, or null if there is no backing object.ProtonBuffer
writeBoolean(boolean value)
Writes a single boolean to the buffer and advances the write index by one.ProtonBuffer
writeByte(int value)
Writes a single byte to the buffer and advances the write index by one.ProtonBuffer
writeBytes(byte[] value)
Writes the contents of the given byte array into the buffer and advances the write index by the length of the given array.ProtonBuffer
writeBytes(byte[] value, int length)
Writes the contents of the given byte array into the buffer and advances the write index by the length value given.ProtonBuffer
writeBytes(byte[] array, int offset, int length)
Writes the contents of the given byte array into the buffer and advances the write index by the length value given.ProtonBuffer
writeBytes(ByteBuffer value)
Transfers the specified source buffer's data to this buffer starting at the currentwriteIndex
until the source buffer's position reaches its limit, and increases thewriteIndex
by the number of the transferred bytes.ProtonBuffer
writeBytes(ProtonBuffer value)
Transfers the specified source buffer's data to this buffer starting at the currentwriteIndex
until the source buffer becomes unreadable, and increases thewriteIndex
by the number of the transferred bytes.ProtonBuffer
writeBytes(ProtonBuffer value, int length)
Transfers the specified source buffer's data to this buffer starting at the currentwriteIndex
and increases thewriteIndex
by the number of the transferred bytes (=length
).ProtonBuffer
writeBytes(ProtonBuffer value, int offset, int length)
Transfers the specified source buffer's data to this buffer starting at the currentwriteIndex
and increases thewriteIndex
by the number of the transferred bytes (=length
).ProtonBuffer
writeDouble(double value)
Writes a single double to the buffer and advances the write index by eight.ProtonBuffer
writeFloat(float value)
Writes a single float to the buffer and advances the write index by four.ProtonBuffer
writeInt(int value)
Writes a single integer to the buffer and advances the write index by four.ProtonBuffer
writeLong(long value)
Writes a single long to the buffer and advances the write index by eight.ProtonBuffer
writeShort(short value)
Writes a single short to the buffer and advances the write index by two.
-
-
-
Constructor Detail
-
ProtonNettyByteBuffer
public ProtonNettyByteBuffer(io.netty.buffer.ByteBuf toWrap)
Creates a newProtonNettyByteBuffer
which wraps the given NettyByteBuf
.- Parameters:
toWrap
- TheByteBuf
to wrap.
-
ProtonNettyByteBuffer
public ProtonNettyByteBuffer(int maximumCapacity)
Creates aProtonNettyByteBuffer
that wraps an NettyByteBuf
that is not pooled and whose maximum capacity is set to the given value.- Parameters:
maximumCapacity
- The maximum allowed capacity of the allocated NettyByteBuf
.
-
-
Method Detail
-
unwrap
public io.netty.buffer.ByteBuf unwrap()
Description copied from interface:ProtonBuffer
Return the underlying buffer object that backs thisProtonBuffer
instance, or null if there is no backing object. This method should be overridden in buffer abstraction when access to the underlying backing store is needed such as when wrapping pooled resources that need explicit release calls.- Specified by:
unwrap
in interfaceProtonBuffer
- Returns:
- an underlying buffer object or other backing store for this buffer.
-
capacity
public int capacity()
- Specified by:
capacity
in interfaceProtonBuffer
- Returns:
- the number of bytes this buffer can currently contain.
-
capacity
public ProtonBuffer capacity(int newCapacity)
Description copied from interface:ProtonBuffer
Adjusts the capacity of this buffer. If the new capacity is less than the current capacity, the content of this buffer is truncated. If the new capacity is greater than the current capacity, the buffer is appended with unspecified data whose length is new capacity - current capacity.- Specified by:
capacity
in interfaceProtonBuffer
- Parameters:
newCapacity
- the new maximum capacity value of this buffer.- Returns:
- this buffer for using in call chaining.
-
clear
public ProtonBuffer clear()
Description copied from interface:ProtonBuffer
Reset the read and write offsets to zero and clears the position markers if set previously, this method is not required to reset the data previously written to this buffer.- Specified by:
clear
in interfaceProtonBuffer
- Returns:
- this buffer for using in call chaining.
-
compareTo
public int compareTo(ProtonBuffer other)
Description copied from interface:ProtonBuffer
Compares the remaining content of the current buffer with the remaining content of the given buffer, which must not be null. Each byte is compared in turn as an unsigned value, returning upon the first difference. If no difference is found before the end of one buffer, the shorter buffer is considered less than the other, or else if the same length then they are considered equal.- Specified by:
compareTo
in interfaceComparable<ProtonBuffer>
- Specified by:
compareTo
in interfaceProtonBuffer
- Returns:
- a negative, zero, or positive integer when this buffer is less than, equal to, or greater than the given buffer.
- See Also:
Comparable.compareTo(Object)
-
copy
public ProtonBuffer copy()
Description copied from interface:ProtonBuffer
Create a deep copy of the readable bytes of this ProtonBuffer, the returned buffer can be modified without affecting the contents or position markers of this instance.- Specified by:
copy
in interfaceProtonBuffer
- Returns:
- a deep copy of this ProtonBuffer instance.
-
copy
public ProtonBuffer copy(int index, int length)
Description copied from interface:ProtonBuffer
Returns a copy of this buffer's sub-region. Modifying the content of the returned buffer or this buffer does not affect each other at all. This method does not modify the value returned fromProtonBuffer.getReadIndex()
orProtonBuffer.getWriteIndex()
of this buffer.- Specified by:
copy
in interfaceProtonBuffer
- Parameters:
index
- The index in this buffer where the copy should beginlength
- The number of bytes to copy to the new buffer from this one.- Returns:
- a new ProtonBuffer instance containing the copied bytes.
-
duplicate
public ProtonBuffer duplicate()
Description copied from interface:ProtonBuffer
Create a duplicate of this ProtonBuffer instance that shares the same backing data store and but maintains separate position index values. Changes to one buffer are visible in any of its duplicates. This method does not copy the read or write markers to the new buffer instance.- Specified by:
duplicate
in interfaceProtonBuffer
- Returns:
- a new ProtonBuffer instance that shares the backing data as this one.
-
ensureWritable
public ProtonBuffer ensureWritable(int minWritableBytes) throws IndexOutOfBoundsException, IllegalArgumentException
Description copied from interface:ProtonBuffer
Ensures that the requested number of bytes is available for write operations in the current buffer, growing the buffer if needed to meet the requested writable capacity. This method will not alter the write offset but may change the value returned from the capacity method if new buffer space is allocated.- Specified by:
ensureWritable
in interfaceProtonBuffer
- Parameters:
minWritableBytes
- The number of bytes beyond the current write index needed.- Returns:
- this buffer for using in call chaining.
- Throws:
IndexOutOfBoundsException
- if the amount given would result in the buffer exceeding the maximum capacity for this buffer.IllegalArgumentException
- if the amount given is less than zero.
-
getArray
public byte[] getArray()
Description copied from interface:ProtonBuffer
Returns the backing array for this ProtonBuffer instance if there is such an array or throws an exception if this ProtonBuffer implementation has no backing array.Changes to the returned array are visible to other users of this ProtonBuffer.
- Specified by:
getArray
in interfaceProtonBuffer
- Returns:
- the backing byte array for this ProtonBuffer.
-
getArrayOffset
public int getArrayOffset()
- Specified by:
getArrayOffset
in interfaceProtonBuffer
- Returns:
- the offset of the first byte in the backing array belonging to this buffer.
-
getBoolean
public boolean getBoolean(int index)
Description copied from interface:ProtonBuffer
Gets a boolean from the specified index, this method will not modify the read or write index.- Specified by:
getBoolean
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.- Returns:
- the value read from the given index.
-
getByte
public byte getByte(int index)
Description copied from interface:ProtonBuffer
Gets a byte from the specified index, this method will not modify the read or write index.- Specified by:
getByte
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.- Returns:
- the value read from the given index.
-
getBytes
public ProtonBuffer getBytes(int index, byte[] destination)
Description copied from interface:ProtonBuffer
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
. This method does not modifyreadIndex
orwriteIndex
of this buffer- Specified by:
getBytes
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.destination
- The buffer where the bytes read will be written to- Returns:
- this buffer for chaining
-
getBytes
public ProtonBuffer getBytes(int index, ByteBuffer destination)
Description copied from interface:ProtonBuffer
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
until the destination's position reaches its limit. This method does not modify#getReadIndex()
or#getWriteIndex()
of this buffer while the destination'sposition
will be increased.- Specified by:
getBytes
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.destination
- The buffer where the bytes read will be written to- Returns:
- this buffer for chaining
-
getBytes
public ProtonBuffer getBytes(int index, ProtonBuffer destination)
Description copied from interface:ProtonBuffer
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
until the destination becomes non-writable. This method is basically same withProtonBuffer.getBytes(int, ProtonBuffer, int, int)
, except that this method increases thewriteIndex
of the destination by the number of the transferred bytes whileProtonBuffer.getBytes(int, ProtonBuffer, int, int)
does not. This method does not modifyreadIndex
orwriteIndex
of the source buffer (i.e.this
).- Specified by:
getBytes
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.destination
- the destination buffer for the bytes to be read- Returns:
- this buffer for chaining
-
getBytes
public ProtonBuffer getBytes(int index, ProtonBuffer destination, int length)
Description copied from interface:ProtonBuffer
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
. This method is basically same withProtonBuffer.getBytes(int, ProtonBuffer, int, int)
, except that this method increases thewriteIndex
of the destination by the number of the transferred bytes whileProtonBuffer.getBytes(int, ProtonBuffer, int, int)
does not. This method does not modifyreadIndex
orwriteIndex
of the source buffer (i.e.this
).- Specified by:
getBytes
in interfaceProtonBuffer
- Parameters:
index
- the index in the buffer to start the read fromdestination
- the destination buffer for the bytes to be readlength
- the number of bytes to transfer- Returns:
- this buffer for chaining
-
getBytes
public ProtonBuffer getBytes(int index, ProtonBuffer destination, int offset, int length)
Description copied from interface:ProtonBuffer
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
. This method does not modifyreadIndex
orwriteIndex
of both the source (i.e.this
) and the destination.- Specified by:
getBytes
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.destination
- The buffer where the bytes read will be written tooffset
- The offset into the destination where the write startslength
- The number of bytes to transfer- Returns:
- this buffer for chaining
-
getBytes
public ProtonBuffer getBytes(int index, byte[] destination, int offset, int length)
Description copied from interface:ProtonBuffer
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
. This method does not modify#getReadIndex()
or#getWriteIndex()
of this buffer.- Specified by:
getBytes
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.destination
- The buffer where the bytes read will be written tooffset
- the offset into the destination to begin writing the bytes.length
- the number of bytes to transfer from this buffer to the target buffer.- Returns:
- this buffer for chaining
-
getChar
public char getChar(int index)
Description copied from interface:ProtonBuffer
Gets a 2-byte char from the specified index, this method will not modify the read or write index.- Specified by:
getChar
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.- Returns:
- the value read from the given index.
-
getDouble
public double getDouble(int index)
Description copied from interface:ProtonBuffer
Gets a double from the specified index, this method will not modify the read or write index.- Specified by:
getDouble
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.- Returns:
- the value read from the given index.
-
getFloat
public float getFloat(int index)
Description copied from interface:ProtonBuffer
Gets a float from the specified index, this method will not modify the read or write index.- Specified by:
getFloat
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.- Returns:
- the value read from the given index.
-
getInt
public int getInt(int index)
Description copied from interface:ProtonBuffer
Gets a int from the specified index, this method will not modify the read or write index.- Specified by:
getInt
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.- Returns:
- the value read from the given index.
-
getLong
public long getLong(int index)
Description copied from interface:ProtonBuffer
Gets a long from the specified index, this method will not modify the read or write index.- Specified by:
getLong
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.- Returns:
- the value read from the given index.
-
getReadIndex
public int getReadIndex()
- Specified by:
getReadIndex
in interfaceProtonBuffer
- Returns:
- the current value of the read index for this buffer.
-
getReadableBytes
public int getReadableBytes()
- Specified by:
getReadableBytes
in interfaceProtonBuffer
- Returns:
- the number of bytes available for reading from this buffer.
-
getShort
public short getShort(int index)
Description copied from interface:ProtonBuffer
Gets a short from the specified index, this method will not modify the read or write index.- Specified by:
getShort
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.- Returns:
- the value read from the given index.
-
getUnsignedByte
public short getUnsignedByte(int index)
Description copied from interface:ProtonBuffer
Gets a unsigned byte from the specified index, this method will not modify the read or write index.- Specified by:
getUnsignedByte
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.- Returns:
- the value read from the given index.
-
getUnsignedInt
public long getUnsignedInt(int index)
Description copied from interface:ProtonBuffer
Gets a unsigned int from the specified index, this method will not modify the read or write index.- Specified by:
getUnsignedInt
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.- Returns:
- the value read from the given index.
-
getUnsignedShort
public int getUnsignedShort(int index)
Description copied from interface:ProtonBuffer
Gets a unsigned short from the specified index, this method will not modify the read or write index.- Specified by:
getUnsignedShort
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the value should be read.- Returns:
- the value read from the given index.
-
getWritableBytes
public int getWritableBytes()
- Specified by:
getWritableBytes
in interfaceProtonBuffer
- Returns:
- the number of bytes that can be written to this buffer before the limit is hit.
-
getMaxWritableBytes
public int getMaxWritableBytes()
Description copied from interface:ProtonBuffer
Gets the current maximum number of bytes that can be written to this buffer. This is the same value that can be computed by subtracting the current write index from the maximum buffer capacity.- Specified by:
getMaxWritableBytes
in interfaceProtonBuffer
- Returns:
- the maximum number of bytes that can be written to this buffer before the limit is hit.
-
getWriteIndex
public int getWriteIndex()
- Specified by:
getWriteIndex
in interfaceProtonBuffer
- Returns:
- the current value of the write index for this buffer.
-
hasArray
public boolean hasArray()
- Specified by:
hasArray
in interfaceProtonBuffer
- Returns:
- true if this buffer has a backing byte array that can be accessed.
-
isReadable
public boolean isReadable()
- Specified by:
isReadable
in interfaceProtonBuffer
- Returns:
- true if the read index is less than the write index.
-
isReadable
public boolean isReadable(int minReadableBytes)
Description copied from interface:ProtonBuffer
Check if the given number of bytes can be read from the buffer.- Specified by:
isReadable
in interfaceProtonBuffer
- Parameters:
minReadableBytes
- the size that is desired in readable bytes- Returns:
- true if the buffer has at least the given number of readable bytes remaining.
-
isWritable
public boolean isWritable()
- Specified by:
isWritable
in interfaceProtonBuffer
- Returns:
- true if the buffer has bytes remaining between the write index and the capacity.
-
isWritable
public boolean isWritable(int minWritableBytes)
Description copied from interface:ProtonBuffer
Check if the requested number of bytes can be written into this buffer.- Specified by:
isWritable
in interfaceProtonBuffer
- Parameters:
minWritableBytes
- The number writable bytes that is being checked in this buffer.- Returns:
- true if the buffer has space left for the given number of bytes to be written.
-
markReadIndex
public ProtonBuffer markReadIndex()
Description copied from interface:ProtonBuffer
Marks the current read index so that it can later be restored by a call toProtonBuffer.resetReadIndex()
, the initial mark value is 0.- Specified by:
markReadIndex
in interfaceProtonBuffer
- Returns:
- this buffer for use in chaining.
-
markWriteIndex
public ProtonBuffer markWriteIndex()
Description copied from interface:ProtonBuffer
Marks the current write index so that it can later be restored by a call toProtonBuffer.resetWriteIndex()
, the initial mark value is 0.- Specified by:
markWriteIndex
in interfaceProtonBuffer
- Returns:
- this buffer for use in chaining.
-
maxCapacity
public int maxCapacity()
Description copied from interface:ProtonBuffer
Returns the number of bytes that this buffer is allowed to grow to when write operations exceed the current capacity value.- Specified by:
maxCapacity
in interfaceProtonBuffer
- Returns:
- the number of bytes this buffer is allowed to grow to.
-
readBoolean
public boolean readBoolean()
Description copied from interface:ProtonBuffer
Reads a boolean value from the buffer and advances the read index by one.- Specified by:
readBoolean
in interfaceProtonBuffer
- Returns:
- boolean value read from the buffer.
-
readByte
public byte readByte()
Description copied from interface:ProtonBuffer
Reads one byte from the buffer and advances the read index by one.- Specified by:
readByte
in interfaceProtonBuffer
- Returns:
- a single byte from the ProtonBuffer.
-
readBytes
public ProtonBuffer readBytes(byte[] destination)
Description copied from interface:ProtonBuffer
Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the value of the length of the destination array.- Specified by:
readBytes
in interfaceProtonBuffer
- Parameters:
destination
- The byte array to write into.- Returns:
- this ProtonBuffer for chaining.
-
readBytes
public ProtonBuffer readBytes(ByteBuffer destination)
Description copied from interface:ProtonBuffer
Transfers this buffer's data to the specified destination starting at the currentreadIndex
until the destination's position reaches its limit, and increases thereadIndex
by the number of the transferred bytes.- Specified by:
readBytes
in interfaceProtonBuffer
- Parameters:
destination
- The target ByteBuffer to write into.- Returns:
- this ProtonBuffer for chaining.
-
readBytes
public ProtonBuffer readBytes(byte[] destination, int length)
Description copied from interface:ProtonBuffer
Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the length value passed.- Specified by:
readBytes
in interfaceProtonBuffer
- Parameters:
destination
- The byte array to write into.length
- The number of bytes to read into the given array.- Returns:
- this ProtonBuffer for chaining.
-
readBytes
public ProtonBuffer readBytes(byte[] destination, int offset, int length)
Description copied from interface:ProtonBuffer
Reads bytes from this buffer and writes them into the destination byte array incrementing the read index by the length value passed, the bytes are read into the given buffer starting from the given offset value.- Specified by:
readBytes
in interfaceProtonBuffer
- Parameters:
destination
- The byte array to write into.offset
- The offset into the given array where bytes are written.length
- The number of bytes to read into the given array.- Returns:
- this ProtonBuffer for chaining.
-
readBytes
public ProtonBuffer readBytes(ProtonBuffer destination)
Description copied from interface:ProtonBuffer
Reads bytes from this buffer and writes them into the destination ProtonBuffer incrementing the read index by the value of the number of bytes written to the target. The number of bytes written will be the equal to the writable bytes of the target buffer. The write index of the target buffer will be incremented by the number of bytes written into it.- Specified by:
readBytes
in interfaceProtonBuffer
- Parameters:
destination
- The ProtonBuffer to write into.- Returns:
- this ProtonBuffer for chaining.
-
readBytes
public ProtonBuffer readBytes(ProtonBuffer destination, int length)
Description copied from interface:ProtonBuffer
Reads bytes from this buffer and writes them into the destination ProtonBuffer incrementing the read index by the number of bytes written. The write index of the target buffer will be incremented by the number of bytes written into it.- Specified by:
readBytes
in interfaceProtonBuffer
- Parameters:
destination
- The ProtonBuffer to write into.length
- The number of bytes to read into the given buffer.- Returns:
- this ProtonBuffer for chaining.
-
readBytes
public ProtonBuffer readBytes(ProtonBuffer destination, int offset, int length)
Description copied from interface:ProtonBuffer
Transfers this buffer's data to the specified destination starting at the currentreadIndex
and increases thereadIndex
by the number of the transferred bytes (=length
). This method does not modify the write index of the target buffer.- Specified by:
readBytes
in interfaceProtonBuffer
- Parameters:
destination
- The ProtonBuffer to write into.offset
- The offset into the given buffer where bytes are written.length
- The number of bytes to read into the given buffer.- Returns:
- this ProtonBuffer for chaining.
-
readDouble
public double readDouble()
Description copied from interface:ProtonBuffer
Reads a double value from the buffer and advances the read index by eight.- Specified by:
readDouble
in interfaceProtonBuffer
- Returns:
- double value read from the buffer.
-
readFloat
public float readFloat()
Description copied from interface:ProtonBuffer
Reads a float value from the buffer and advances the read index by four.- Specified by:
readFloat
in interfaceProtonBuffer
- Returns:
- float value read from the buffer.
-
readInt
public int readInt()
Description copied from interface:ProtonBuffer
Reads a integer value from the buffer and advances the read index by four.- Specified by:
readInt
in interfaceProtonBuffer
- Returns:
- integer value read from the buffer.
-
readLong
public long readLong()
Description copied from interface:ProtonBuffer
Reads a long value from the buffer and advances the read index by eight.- Specified by:
readLong
in interfaceProtonBuffer
- Returns:
- long value read from the buffer.
-
readShort
public short readShort()
Description copied from interface:ProtonBuffer
Reads a short value from the buffer and advances the read index by two.- Specified by:
readShort
in interfaceProtonBuffer
- Returns:
- short value read from the buffer.
-
resetReadIndex
public ProtonBuffer resetReadIndex()
Description copied from interface:ProtonBuffer
Resets the current read index to the previously marked value.- Specified by:
resetReadIndex
in interfaceProtonBuffer
- Returns:
- this buffer for use in chaining.
-
resetWriteIndex
public ProtonBuffer resetWriteIndex()
Description copied from interface:ProtonBuffer
Resets the current write index to the previously marked value.- Specified by:
resetWriteIndex
in interfaceProtonBuffer
- Returns:
- this buffer for use in chaining.
-
setBoolean
public ProtonBuffer setBoolean(int index, boolean value)
Description copied from interface:ProtonBuffer
Sets the boolean value at the given write index in this buffer's backing data store.- Specified by:
setBoolean
in interfaceProtonBuffer
- Parameters:
index
- The index to start the write from.value
- The value to write at the given index.- Returns:
- a reference to this ProtonBuffer for chaining.
-
setByte
public ProtonBuffer setByte(int index, int value)
Description copied from interface:ProtonBuffer
Sets the byte value at the given write index in this buffer's backing data store.- Specified by:
setByte
in interfaceProtonBuffer
- Parameters:
index
- The index to start the write from.value
- The value to write at the given index.- Returns:
- a reference to this ProtonBuffer for chaining.
-
setBytes
public ProtonBuffer setBytes(int index, byte[] value)
Description copied from interface:ProtonBuffer
Transfers the specified source array's data to this buffer starting at the specified absoluteindex
. This method does not modifyreadIndex
orwriteIndex
of this buffer.- Specified by:
setBytes
in interfaceProtonBuffer
- Parameters:
index
- The index in this buffer where the write operation starts.value
- The source buffer from which the bytes are read.- Returns:
- this buffer for chaining
-
setBytes
public ProtonBuffer setBytes(int index, ByteBuffer value)
Description copied from interface:ProtonBuffer
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
until the source buffer's position reaches its limit. This method does not modifyreadIndex
orwriteIndex
of this buffer.- Specified by:
setBytes
in interfaceProtonBuffer
- Parameters:
index
- The index in this buffer where the write operation starts.value
- The source buffer from which the bytes are read.- Returns:
- this buffer for chaining
-
setBytes
public ProtonBuffer setBytes(int index, ProtonBuffer value)
Description copied from interface:ProtonBuffer
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
until the source buffer becomes unreadable. This method is basically same withProtonBuffer.setBytes(int, ProtonBuffer, int, int)
, except that this method increases thereadIndex
of the source buffer by the number of the transferred bytes whileProtonBuffer.setBytes(int, ProtonBuffer, int, int)
does not. This method does not modifyreadIndex
orwriteIndex
of the source buffer (i.e.this
).- Specified by:
setBytes
in interfaceProtonBuffer
- Parameters:
index
- The index in this buffer where the write operation starts.value
- The source buffer from which the bytes are read.- Returns:
- this buffer for chaining
-
setBytes
public ProtonBuffer setBytes(int index, ProtonBuffer value, int length)
Description copied from interface:ProtonBuffer
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
. This method is basically same withProtonBuffer.setBytes(int, ProtonBuffer, int, int)
, except that this method increases thereadIndex
of the source buffer by the number of the transferred bytes whileProtonBuffer.setBytes(int, ProtonBuffer, int, int)
does not. This method does not modifyreadIndex
orwriteIndex
of the source buffer (i.e.this
).- Specified by:
setBytes
in interfaceProtonBuffer
- Parameters:
index
- The index in this buffer where the write operation starts.value
- The source buffer from which the bytes are read.length
- The number of bytes to transfer- Returns:
- this buffer for chaining
-
setBytes
public ProtonBuffer setBytes(int index, ProtonBuffer value, int offset, int length)
Description copied from interface:ProtonBuffer
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
. This method does not modifyreadIndex
orwriteIndex
of both the source (i.e.this
) and the destination.- Specified by:
setBytes
in interfaceProtonBuffer
- Parameters:
index
- The index in this buffer where the write operation starts.value
- The source buffer from which the bytes are read.offset
- The offset into the source where the set begins.length
- The number of bytes to transfer- Returns:
- this buffer for chaining
-
setBytes
public ProtonBuffer setBytes(int index, byte[] value, int offset, int length)
Description copied from interface:ProtonBuffer
Transfers the specified source array's data to this buffer starting at the specified absoluteindex
. This method does not modifyreadIndex
orwriteIndex
of this buffer.- Specified by:
setBytes
in interfaceProtonBuffer
- Parameters:
index
- The index in this buffer where the write operation starts.value
- The source buffer from which the bytes are read.offset
- The offset into the source where the set begins.length
- The number of bytes to transfer- Returns:
- this buffer for chaining
-
setChar
public ProtonBuffer setChar(int index, int value)
Description copied from interface:ProtonBuffer
Sets the char value at the given write index in this buffer's backing data store.- Specified by:
setChar
in interfaceProtonBuffer
- Parameters:
index
- The index to start the write from.value
- The value to write at the given index.- Returns:
- a reference to this ProtonBuffer for chaining.
-
setDouble
public ProtonBuffer setDouble(int index, double value)
Description copied from interface:ProtonBuffer
Sets the double value at the given write index in this buffer's backing data store.- Specified by:
setDouble
in interfaceProtonBuffer
- Parameters:
index
- The index to start the write from.value
- The value to write at the given index.- Returns:
- a reference to this ProtonBuffer for chaining.
-
setFloat
public ProtonBuffer setFloat(int index, float value)
Description copied from interface:ProtonBuffer
Sets the float value at the given write index in this buffer's backing data store.- Specified by:
setFloat
in interfaceProtonBuffer
- Parameters:
index
- The index to start the write from.value
- The value to write at the given index.- Returns:
- a reference to this ProtonBuffer for chaining.
-
setIndex
public ProtonBuffer setIndex(int readIndex, int writeIndex)
Description copied from interface:ProtonBuffer
Used to set the read index and the write index in one call. This methods allows for an update to the read index and write index to values that could not be set using simple setReadIndex and setWriteIndex call where the values would violate the constraints placed on them by the value of the other index.- Specified by:
setIndex
in interfaceProtonBuffer
- Parameters:
readIndex
- The new read index to assign to this buffer.writeIndex
- The new write index to assign to this buffer.- Returns:
- this buffer for use in chaining.
-
setInt
public ProtonBuffer setInt(int index, int value)
Description copied from interface:ProtonBuffer
Sets the int value at the given write index in this buffer's backing data store.- Specified by:
setInt
in interfaceProtonBuffer
- Parameters:
index
- The index to start the write from.value
- The value to write at the given index.- Returns:
- a reference to this ProtonBuffer for chaining.
-
setLong
public ProtonBuffer setLong(int index, long value)
Description copied from interface:ProtonBuffer
Sets the long value at the given write index in this buffer's backing data store.- Specified by:
setLong
in interfaceProtonBuffer
- Parameters:
index
- The index to start the write from.value
- The value to write at the given index.- Returns:
- a reference to this ProtonBuffer for chaining.
-
setReadIndex
public ProtonBuffer setReadIndex(int index)
Description copied from interface:ProtonBuffer
Sets the read index for this buffer.- Specified by:
setReadIndex
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the read index should be positioned.- Returns:
- this buffer for use in chaining.
-
setShort
public ProtonBuffer setShort(int index, int value)
Description copied from interface:ProtonBuffer
Sets the short value at the given write index in this buffer's backing data store.- Specified by:
setShort
in interfaceProtonBuffer
- Parameters:
index
- The index to start the write from.value
- The value to write at the given index.- Returns:
- a reference to this ProtonBuffer for chaining.
-
setWriteIndex
public ProtonBuffer setWriteIndex(int index)
Description copied from interface:ProtonBuffer
Sets the write index for this buffer.- Specified by:
setWriteIndex
in interfaceProtonBuffer
- Parameters:
index
- The index into the buffer where the write index should be positioned.- Returns:
- this buffer for use in chaining.
-
skipBytes
public ProtonBuffer skipBytes(int skippedBytes)
Description copied from interface:ProtonBuffer
Increases the currentreadIndex
of this buffer by the specifiedlength
.- Specified by:
skipBytes
in interfaceProtonBuffer
- Parameters:
skippedBytes
- the number of bytes in this buffer to skip.- Returns:
- this ProtonBuffer for chaining.
-
slice
public ProtonBuffer slice()
Description copied from interface:ProtonBuffer
Create a new ProtonBuffer whose contents are a subsequence of the contents of thisProtonBuffer
.The starting point of the new buffer starts at this buffer's current position, the marks and limits of the new buffer will be independent of this buffer however changes to the data backing the buffer will be visible in this buffer.
- Specified by:
slice
in interfaceProtonBuffer
- Returns:
- a new
ProtonBuffer
whose contents are a subsequence of this buffer.
-
slice
public ProtonBuffer slice(int index, int length)
Description copied from interface:ProtonBuffer
Create a new ProtonBuffer whose contents are a subsequence of the contents of thisProtonBuffer
.The starting point of the new buffer starts at given index into this buffer and spans the number of bytes given by the length. Changes to the contents of this buffer or to the produced slice buffer are visible in the other.
- Specified by:
slice
in interfaceProtonBuffer
- Parameters:
index
- The index in this buffer where the slice should begin.length
- The number of bytes to make visible to the new buffer from this one.- Returns:
- a new
ProtonBuffer
whose contents are a subsequence of this buffer.
-
toByteBuffer
public ByteBuffer toByteBuffer()
Description copied from interface:ProtonBuffer
Returns a ByteBuffer that represents the readable bytes contained in this buffer.This method should attempt to return a ByteBuffer that shares the backing data store with this buffer however if that is not possible it is permitted that the returned ByteBuffer contain a copy of the readable bytes of this ProtonBuffer.
- Specified by:
toByteBuffer
in interfaceProtonBuffer
- Returns:
- a ByteBuffer that represents the readable bytes of this buffer.
-
toByteBuffer
public ByteBuffer toByteBuffer(int index, int length)
Description copied from interface:ProtonBuffer
Returns a ByteBuffer that represents the given span of bytes from the readable portion of this buffer.This method should attempt to return a ByteBuffer that shares the backing data store with this buffer however if that is not possible it is permitted that the returned ByteBuffer contain a copy of the readable bytes of this ProtonBuffer.
- Specified by:
toByteBuffer
in interfaceProtonBuffer
- Parameters:
index
- The starting index in this where the ByteBuffer view should begin.length
- The number of bytes to include in the ByteBuffer view.- Returns:
- a ByteBuffer that represents the given view of this buffers readable bytes.
-
toString
public String toString(Charset charset)
Description copied from interface:ProtonBuffer
Returns a String created from the buffer's underlying bytes using the specifiedCharset
for the newly created String.- Specified by:
toString
in interfaceProtonBuffer
- Parameters:
charset
- theCharset
to use to construct the new string.- Returns:
- a string created from the buffer's underlying bytes using the given
Charset
.
-
writeBoolean
public ProtonBuffer writeBoolean(boolean value)
Description copied from interface:ProtonBuffer
Writes a single boolean to the buffer and advances the write index by one.- Specified by:
writeBoolean
in interfaceProtonBuffer
- Parameters:
value
- The boolean to write into the buffer.- Returns:
- this ProtonBuffer for chaining.
-
writeByte
public ProtonBuffer writeByte(int value)
Description copied from interface:ProtonBuffer
Writes a single byte to the buffer and advances the write index by one.- Specified by:
writeByte
in interfaceProtonBuffer
- Parameters:
value
- The byte to write into the buffer.- Returns:
- this ProtonBuffer for chaining.
-
writeBytes
public ProtonBuffer writeBytes(ByteBuffer value)
Description copied from interface:ProtonBuffer
Transfers the specified source buffer's data to this buffer starting at the currentwriteIndex
until the source buffer's position reaches its limit, and increases thewriteIndex
by the number of the transferred bytes.- Specified by:
writeBytes
in interfaceProtonBuffer
- Parameters:
value
- The source buffer from which the bytes are read.- Returns:
- this buffer for chaining
-
writeBytes
public ProtonBuffer writeBytes(byte[] value)
Description copied from interface:ProtonBuffer
Writes the contents of the given byte array into the buffer and advances the write index by the length of the given array.- Specified by:
writeBytes
in interfaceProtonBuffer
- Parameters:
value
- The byte array to write into the buffer.- Returns:
- this ProtonBuffer for chaining.
-
writeBytes
public ProtonBuffer writeBytes(byte[] value, int length)
Description copied from interface:ProtonBuffer
Writes the contents of the given byte array into the buffer and advances the write index by the length value given.- Specified by:
writeBytes
in interfaceProtonBuffer
- Parameters:
value
- The byte array to write into the buffer.length
- The number of bytes to write from the given array into this buffer- Returns:
- this ProtonBuffer for chaining.
-
writeBytes
public ProtonBuffer writeBytes(byte[] array, int offset, int length)
Description copied from interface:ProtonBuffer
Writes the contents of the given byte array into the buffer and advances the write index by the length value given. The bytes written into this buffer are read starting at the given offset into the passed in byte array.- Specified by:
writeBytes
in interfaceProtonBuffer
- Parameters:
array
- The byte array to write into the buffer.offset
- The offset into the given array to start reading from.length
- The number of bytes to write from the given array into this buffer- Returns:
- this ProtonBuffer for chaining.
-
writeBytes
public ProtonBuffer writeBytes(ProtonBuffer value)
Description copied from interface:ProtonBuffer
Transfers the specified source buffer's data to this buffer starting at the currentwriteIndex
until the source buffer becomes unreadable, and increases thewriteIndex
by the number of the transferred bytes. This method is basically same withProtonBuffer.writeBytes(ProtonBuffer, int, int)
, except that this method increases thereadIndex
of the source buffer by the number of the transferred bytes whileProtonBuffer.writeBytes(ProtonBuffer, int, int)
does not.- Specified by:
writeBytes
in interfaceProtonBuffer
- Parameters:
value
- The source buffer from which the bytes are read.- Returns:
- this ProtonBuffer for chaining.
-
writeBytes
public ProtonBuffer writeBytes(ProtonBuffer value, int length)
Description copied from interface:ProtonBuffer
Transfers the specified source buffer's data to this buffer starting at the currentwriteIndex
and increases thewriteIndex
by the number of the transferred bytes (=length
). This method is basically same withProtonBuffer.writeBytes(ProtonBuffer, int, int)
, except that this method increases thereadIndex
of the source buffer by the number of the transferred bytes (=length
) whileProtonBuffer.writeBytes(ProtonBuffer, int, int)
does not.- Specified by:
writeBytes
in interfaceProtonBuffer
- Parameters:
value
- The source buffer from which the bytes are read.length
- The number of bytes to transfer- Returns:
- this buffer for chaining
-
writeBytes
public ProtonBuffer writeBytes(ProtonBuffer value, int offset, int length)
Description copied from interface:ProtonBuffer
Transfers the specified source buffer's data to this buffer starting at the currentwriteIndex
and increases thewriteIndex
by the number of the transferred bytes (=length
). This method does not modify the read index of the source buffer.- Specified by:
writeBytes
in interfaceProtonBuffer
- Parameters:
value
- The source buffer from which the bytes are read.offset
- The offset in the source buffer to start writing into this buffer.length
- The number of bytes to transfer- Returns:
- this buffer for chaining
-
writeDouble
public ProtonBuffer writeDouble(double value)
Description copied from interface:ProtonBuffer
Writes a single double to the buffer and advances the write index by eight.- Specified by:
writeDouble
in interfaceProtonBuffer
- Parameters:
value
- The double to write into the buffer.- Returns:
- this ProtonBuffer for chaining.
-
writeFloat
public ProtonBuffer writeFloat(float value)
Description copied from interface:ProtonBuffer
Writes a single float to the buffer and advances the write index by four.- Specified by:
writeFloat
in interfaceProtonBuffer
- Parameters:
value
- The float to write into the buffer.- Returns:
- this ProtonBuffer for chaining.
-
writeInt
public ProtonBuffer writeInt(int value)
Description copied from interface:ProtonBuffer
Writes a single integer to the buffer and advances the write index by four.- Specified by:
writeInt
in interfaceProtonBuffer
- Parameters:
value
- The integer to write into the buffer.- Returns:
- this ProtonBuffer for chaining.
-
writeLong
public ProtonBuffer writeLong(long value)
Description copied from interface:ProtonBuffer
Writes a single long to the buffer and advances the write index by eight.- Specified by:
writeLong
in interfaceProtonBuffer
- Parameters:
value
- The long to write into the buffer.- Returns:
- this ProtonBuffer for chaining.
-
writeShort
public ProtonBuffer writeShort(short value)
Description copied from interface:ProtonBuffer
Writes a single short to the buffer and advances the write index by two.- Specified by:
writeShort
in interfaceProtonBuffer
- Parameters:
value
- The short to write into the buffer.- Returns:
- this ProtonBuffer for chaining.
-
-