Class AbstractMutableDirectBuffer
- All Implemented Interfaces:
Comparable<DirectBuffer>
,DirectBuffer
,MutableDirectBuffer
- Direct Known Subclasses:
ExpandableArrayBuffer
,ExpandableDirectByteBuffer
,UnsafeBuffer
MutableDirectBuffer
interface.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected long
protected byte[]
protected int
Fields inherited from interface org.agrona.DirectBuffer
DISABLE_ARRAY_CONTENT_PRINTOUT_PROP_NAME, DISABLE_BOUNDS_CHECKS_PROP_NAME, SHOULD_BOUNDS_CHECK, STR_HEADER_LEN
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
Reads the underlying offset to the memory address.void
boundsCheck
(int index, int length) Check that a given length of bytes is within the bounds from a given index.protected final void
boundsCheck0
(int index, int length) byte[]
Get the underlyingbyte[]
if one exists.int
capacity()
Get the capacity of the underlying buffer.void
checkLimit
(int limit) Check that a given limit is not greater than the capacity of a buffer from a given offset.int
compareTo
(DirectBuffer that) protected abstract void
ensureCapacity
(int index, int length) boolean
byte
getByte
(int index) Get the value at a given index.void
getBytes
(int index, byte[] dst) Get from the underlying buffer into a supplied byte array.void
getBytes
(int index, byte[] dst, int offset, int length) Get bytes from the underlying buffer into a supplied byte array.void
getBytes
(int index, ByteBuffer dstBuffer, int length) Get from the underlying buffer into a suppliedByteBuffer
currentBuffer.position()
.void
getBytes
(int index, ByteBuffer dstBuffer, int dstOffset, int length) Get from the underlying buffer into a suppliedByteBuffer
at an offset.void
getBytes
(int index, MutableDirectBuffer dstBuffer, int dstIndex, int length) Get bytes from thisDirectBuffer
into the providedMutableDirectBuffer
at given indices.char
getChar
(int index) Get the value at a given index.char
Get the value at a given index.double
getDouble
(int index) Get the value at a given index.double
Get the value at a given index.float
getFloat
(int index) Get the value at a given index.float
Get the value at a given index.int
getInt
(int index) Get the value at a given index.int
Get the value at a given index.long
getLong
(int index) Get the value at a given index.long
Get the value at a given index.short
getShort
(int index) Get the value at a given index.short
Get the value at a given index.getStringAscii
(int index) Get a String from bytes encoded in ASCII format that is length prefixed.getStringAscii
(int index, int length) Get part of a String from bytes encoded in ASCII format that is length prefixed.int
getStringAscii
(int index, int length, Appendable appendable) Get part of a String from bytes encoded in ASCII format that is length prefixed and append to anAppendable
.int
getStringAscii
(int index, Appendable appendable) Get a String from bytes encoded in ASCII format that is length prefixed and append to anAppendable
.int
getStringAscii
(int index, Appendable appendable, ByteOrder byteOrder) Get a String from bytes encoded in ASCII format that is length prefixed and append to anAppendable
.getStringAscii
(int index, ByteOrder byteOrder) Get a String from bytes encoded in ASCII format that is length prefixed.getStringUtf8
(int index) Get a String from bytes encoded in UTF-8 format that is length prefixed.getStringUtf8
(int index, int length) Get part of String from bytes encoded in UTF-8 format that is length prefixed.getStringUtf8
(int index, ByteOrder byteOrder) Get a String from bytes encoded in UTF-8 format that is length prefixed.getStringWithoutLengthAscii
(int index, int length) Get an encoded ASCII String from the buffer that does not have a length prefix.int
getStringWithoutLengthAscii
(int index, int length, Appendable appendable) Get an encoded ASCII String from the buffer that does not have a length prefix and append to anAppendable
.getStringWithoutLengthUtf8
(int index, int length) Get an encoded UTF-8 String from the buffer that does not have a length prefix.int
hashCode()
int
parseIntAscii
(int index, int length) Parse the ASCII encoded integer value at a given index.long
parseLongAscii
(int index, int length) Parse the ASCII encoded long integer value at a given index.private long
parseLongAsciiOverflowCheck
(int index, int length, int[] maxValue, int startIndex, int end) int
parseNaturalIntAscii
(int index, int length) Parse the ASCII encoded int sized natural value at a given index.long
parseNaturalLongAscii
(int index, int length) Parse the ASCII encoded long sized natural value at a given index.private int
parsePositiveIntAscii
(int index, int length, int startIndex, int end) private long
parsePositiveIntAsciiOverflowCheck
(int index, int length, int startIndex, int end) private long
parsePositiveLongAscii
(int index, int length, int startIndex, int end) void
putByte
(int index, byte value) Put a value to a given index.void
putBytes
(int index, byte[] src) Put an array of src into the underlying buffer.void
putBytes
(int index, byte[] src, int offset, int length) Put an array into the underlying buffer.void
putBytes
(int index, ByteBuffer srcBuffer, int length) Put bytes into the underlying buffer for the view.void
putBytes
(int index, ByteBuffer srcBuffer, int srcIndex, int length) Put bytes into the underlying buffer for the view.void
putBytes
(int index, DirectBuffer srcBuffer, int srcIndex, int length) Put bytes from a sourceDirectBuffer
into thisMutableDirectBuffer
at given indices.void
putChar
(int index, char value) Put a value to a given index.void
Put a value to a given index.void
putDouble
(int index, double value) Put a value to a given index.void
Put a value to a given index.void
putFloat
(int index, float value) Put a value to a given index.void
Put a value to a given index.void
putInt
(int index, int value) Put a value to a given index.void
Put a value to a given index.int
putIntAscii
(int index, int value) Puts an ASCII encoded int into the buffer.void
putLong
(int index, long value) Put a value to a given index.void
Put a value to a given index.int
putLongAscii
(int index, long value) Puts an ASCII encoded long integer into the buffer.int
putNaturalIntAscii
(int index, int value) Puts an ASCII encoded int sized natural number into the buffer.int
putNaturalIntAsciiFromEnd
(int value, int endExclusive) Encode a natural number starting at its end position.int
putNaturalLongAscii
(int index, long value) Puts an ASCII encoded long sized natural number into the buffer.void
putNaturalPaddedIntAscii
(int offset, int length, int value) Encode a natural number with a specified maximum length.private static void
putPositiveIntAscii
(byte[] dest, long offset, int value, int digitCount) private static void
putPositiveLongAscii
(byte[] dest, long offset, long value, int digitCount) void
putShort
(int index, short value) Put a value to a given index.void
Put a value to a given index.int
putStringAscii
(int index, CharSequence value) Encode aCharSequence
as ASCII bytes to the buffer with a length prefix.int
putStringAscii
(int index, CharSequence value, ByteOrder byteOrder) Encode aCharSequence
as ASCII bytes to the buffer with a length prefix.int
putStringAscii
(int index, String value) Encode aString
as ASCII bytes to the buffer with a length prefix.int
putStringAscii
(int index, String value, ByteOrder byteOrder) Encode aString
as ASCII bytes to the buffer with a length prefix.int
putStringUtf8
(int index, String value) Encode aString
as UTF-8 bytes to the buffer with a length prefix.int
putStringUtf8
(int index, String value, int maxEncodedLength) Encode aString
as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.int
putStringUtf8
(int index, String value, ByteOrder byteOrder) Encode aString
as UTF-8 bytes to the buffer with a length prefix.int
putStringUtf8
(int index, String value, ByteOrder byteOrder, int maxEncodedLength) Encode aString
as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.int
putStringWithoutLengthAscii
(int index, CharSequence value) Encode aCharSequence
as ASCII bytes in the buffer without a length prefix.int
putStringWithoutLengthAscii
(int index, CharSequence value, int valueOffset, int length) Encode aCharSequence
as ASCII bytes in the buffer without a length prefix taking a range of the value.int
putStringWithoutLengthAscii
(int index, String value) Encode aString
as ASCII bytes in the buffer without a length prefix.int
putStringWithoutLengthAscii
(int index, String value, int valueOffset, int length) Encode aString
as ASCII bytes in the buffer without a length prefix taking a range of the value.int
putStringWithoutLengthUtf8
(int index, String value) Encode aString
as UTF-8 bytes in the buffer without a length prefix.void
setMemory
(int index, int length, byte value) Set a region of memory to a given byte value.private void
throwParseIntError
(int index, int length) private void
throwParseIntOverflowError
(int index, int length) private void
throwParseLongError
(int index, int length) private void
throwParseLongOverflowError
(int index, int length) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.agrona.DirectBuffer
byteBuffer, wrap, wrap, wrap, wrap, wrap, wrap, wrap, wrapAdjustment
Methods inherited from interface org.agrona.MutableDirectBuffer
isExpandable
-
Field Details
-
byteArray
protected byte[] byteArray -
addressOffset
protected long addressOffset -
capacity
protected int capacity
-
-
Constructor Details
-
AbstractMutableDirectBuffer
public AbstractMutableDirectBuffer()
-
-
Method Details
-
byteArray
public byte[] byteArray()Get the underlyingbyte[]
if one exists.NB: there may not be a one-to-one mapping between indices on this buffer and the underlying
byte[]
, seeDirectBuffer.wrapAdjustment()
.- Specified by:
byteArray
in interfaceDirectBuffer
- Returns:
- the underlying
byte[]
if one exists. - See Also:
-
addressOffset
public long addressOffset()Reads the underlying offset to the memory address.- Specified by:
addressOffset
in interfaceDirectBuffer
- Returns:
- the underlying offset to the memory address.
-
capacity
public int capacity()Get the capacity of the underlying buffer.- Specified by:
capacity
in interfaceDirectBuffer
- Returns:
- the capacity of the underlying buffer in bytes.
-
checkLimit
public void checkLimit(int limit) Check that a given limit is not greater than the capacity of a buffer from a given offset.Can be overridden in a DirectBuffer subclass to enable an extensible buffer or handle retry after a flush.
- Specified by:
checkLimit
in interfaceDirectBuffer
- Parameters:
limit
- up to which access is required.
-
setMemory
public void setMemory(int index, int length, byte value) Set a region of memory to a given byte value.- Specified by:
setMemory
in interfaceMutableDirectBuffer
- Parameters:
index
- at which to start.length
- of the run of bytes to set.value
- the memory will be set to.
-
getLong
Get the value at a given index.- Specified by:
getLong
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.byteOrder
- of the value to be read.- Returns:
- the value for at a given index.
-
putLong
Put a value to a given index.- Specified by:
putLong
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- for at a given index.byteOrder
- of the value when written.
-
getLong
public long getLong(int index) Get the value at a given index.- Specified by:
getLong
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.- Returns:
- the value for at a given index.
-
putLong
public void putLong(int index, long value) Put a value to a given index.- Specified by:
putLong
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- for at a given index.
-
getInt
Get the value at a given index.- Specified by:
getInt
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.byteOrder
- of the value to be read.- Returns:
- the value at a given index.
-
putInt
Put a value to a given index.- Specified by:
putInt
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- to be written.byteOrder
- of the value when written.
-
getInt
public int getInt(int index) Get the value at a given index.- Specified by:
getInt
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.- Returns:
- the value for a given index.
-
putInt
public void putInt(int index, int value) Put a value to a given index.- Specified by:
putInt
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- for at a given index.
-
getDouble
Get the value at a given index.- Specified by:
getDouble
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.byteOrder
- of the value to be read.- Returns:
- the value at a given index.
-
putDouble
Put a value to a given index.- Specified by:
putDouble
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- to be written.byteOrder
- of the value when written.
-
getDouble
public double getDouble(int index) Get the value at a given index.- Specified by:
getDouble
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.- Returns:
- the value at a given index.
-
putDouble
public void putDouble(int index, double value) Put a value to a given index.- Specified by:
putDouble
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- to be written.
-
getFloat
Get the value at a given index.- Specified by:
getFloat
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.byteOrder
- of the value to be read.- Returns:
- the value at a given index.
-
putFloat
Put a value to a given index.- Specified by:
putFloat
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- to be written.byteOrder
- of the value when written.
-
getFloat
public float getFloat(int index) Get the value at a given index.- Specified by:
getFloat
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.- Returns:
- the value at a given index.
-
putFloat
public void putFloat(int index, float value) Put a value to a given index.- Specified by:
putFloat
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- to be written.
-
getShort
Get the value at a given index.- Specified by:
getShort
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.byteOrder
- of the value to be read.- Returns:
- the value at a given index.
-
putShort
Put a value to a given index.- Specified by:
putShort
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- to be written.byteOrder
- of the value when written.
-
getShort
public short getShort(int index) Get the value at a given index.- Specified by:
getShort
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.- Returns:
- the value at a given index.
-
putShort
public void putShort(int index, short value) Put a value to a given index.- Specified by:
putShort
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- to be written.
-
getByte
public byte getByte(int index) Get the value at a given index.- Specified by:
getByte
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.- Returns:
- the value at a given index.
-
putByte
public void putByte(int index, byte value) Put a value to a given index.- Specified by:
putByte
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- to be written.
-
getBytes
public void getBytes(int index, byte[] dst) Get from the underlying buffer into a supplied byte array. This method will try to fill the supplied byte array.- Specified by:
getBytes
in interfaceDirectBuffer
- Parameters:
index
- in the underlying buffer to start from.dst
- into which the dst will be copied.
-
getBytes
public void getBytes(int index, byte[] dst, int offset, int length) Get bytes from the underlying buffer into a supplied byte array.- Specified by:
getBytes
in interfaceDirectBuffer
- Parameters:
index
- in the underlying buffer to start from.dst
- into which the bytes will be copied.offset
- in the supplied buffer to start the copy.length
- of the supplied buffer to use.
-
getBytes
Get bytes from thisDirectBuffer
into the providedMutableDirectBuffer
at given indices.- Specified by:
getBytes
in interfaceDirectBuffer
- Parameters:
index
- in this buffer to begin getting the bytes.dstBuffer
- to which the bytes will be copied.dstIndex
- in the channel buffer to which the byte copy will begin.length
- of the bytes to be copied.
-
getBytes
Get from the underlying buffer into a suppliedByteBuffer
currentBuffer.position()
.The destination buffer will have its
Buffer.position()
advanced as a result.- Specified by:
getBytes
in interfaceDirectBuffer
- Parameters:
index
- in the underlying buffer to start from.dstBuffer
- into which the bytes will be copied.length
- of the supplied buffer to use.
-
getBytes
Get from the underlying buffer into a suppliedByteBuffer
at an offset.The destination buffer will not have its
Buffer.position()
advanced as a result.- Specified by:
getBytes
in interfaceDirectBuffer
- Parameters:
index
- in the underlying buffer to start from.dstBuffer
- into which the bytes will be copied.dstOffset
- in the target buffer.length
- of the supplied buffer to use.
-
putBytes
public void putBytes(int index, byte[] src) Put an array of src into the underlying buffer.- Specified by:
putBytes
in interfaceMutableDirectBuffer
- Parameters:
index
- in the underlying buffer to start from.src
- to be copied into the underlying buffer.
-
putBytes
public void putBytes(int index, byte[] src, int offset, int length) Put an array into the underlying buffer.- Specified by:
putBytes
in interfaceMutableDirectBuffer
- Parameters:
index
- in the underlying buffer to start from.src
- to be copied to the underlying buffer.offset
- in the supplied buffer to begin the copy.length
- of the supplied buffer to copy.
-
putBytes
Put bytes into the underlying buffer for the view. Bytes will be copied from currentBuffer.position()
for a given length.The source buffer will have its
Buffer.position()
advanced as a result.- Specified by:
putBytes
in interfaceMutableDirectBuffer
- Parameters:
index
- in the underlying buffer to start from.srcBuffer
- to copy the bytes from.length
- of the supplied buffer to copy.
-
putBytes
Put bytes into the underlying buffer for the view. Bytes will be copied from the buffer index to the buffer index + length.The source buffer will not have its
Buffer.position()
advanced as a result.- Specified by:
putBytes
in interfaceMutableDirectBuffer
- Parameters:
index
- in the underlying buffer to start from.srcBuffer
- to copy the bytes from (does not change position).srcIndex
- in the source buffer from which the copy will begin.length
- of the bytes to be copied.
-
putBytes
Put bytes from a sourceDirectBuffer
into thisMutableDirectBuffer
at given indices.- Specified by:
putBytes
in interfaceMutableDirectBuffer
- Parameters:
index
- in this buffer to begin putting the bytes.srcBuffer
- from which the bytes will be copied.srcIndex
- in the source buffer from which the byte copy will begin.length
- of the bytes to be copied.
-
getChar
Get the value at a given index.- Specified by:
getChar
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.byteOrder
- of the value to be read.- Returns:
- the value at a given index.
-
putChar
Put a value to a given index.- Specified by:
putChar
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- to be written.byteOrder
- of the value when written.
-
getChar
public char getChar(int index) Get the value at a given index.- Specified by:
getChar
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.- Returns:
- the value at a given index.
-
putChar
public void putChar(int index, char value) Put a value to a given index.- Specified by:
putChar
in interfaceMutableDirectBuffer
- Parameters:
index
- in bytes for where to put.value
- to be written.
-
getStringAscii
Get a String from bytes encoded in ASCII format that is length prefixed.- Specified by:
getStringAscii
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.- Returns:
- the String as represented by the ASCII encoded bytes.
-
getStringAscii
Get a String from bytes encoded in ASCII format that is length prefixed and append to anAppendable
.- Specified by:
getStringAscii
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.appendable
- to append the chars to.- Returns:
- the number of bytes copied.
-
getStringAscii
Get a String from bytes encoded in ASCII format that is length prefixed.- Specified by:
getStringAscii
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.byteOrder
- for the length at the beginning of the String.- Returns:
- the String as represented by the ASCII encoded bytes.
-
getStringAscii
Get a String from bytes encoded in ASCII format that is length prefixed and append to anAppendable
.- Specified by:
getStringAscii
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.appendable
- to append the chars to.byteOrder
- for the length at the beginning of the String.- Returns:
- the number of bytes copied.
-
getStringAscii
Get part of a String from bytes encoded in ASCII format that is length prefixed.- Specified by:
getStringAscii
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.length
- of the String in bytes to decode.- Returns:
- the String as represented by the ASCII encoded bytes.
-
getStringAscii
Get part of a String from bytes encoded in ASCII format that is length prefixed and append to anAppendable
.- Specified by:
getStringAscii
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.length
- of the String in bytes to decode.appendable
- to append the chars to.- Returns:
- the number of bytes copied.
-
putStringAscii
Encode aString
as ASCII bytes to the buffer with a length prefix.- Specified by:
putStringAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the String should be encoded.value
- of the String to be encoded.- Returns:
- the number of bytes put into the buffer.
-
putStringAscii
Encode aCharSequence
as ASCII bytes to the buffer with a length prefix.- Specified by:
putStringAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the CharSequence should be encoded.value
- of the CharSequence to be encoded.- Returns:
- the number of bytes put into the buffer.
-
putStringAscii
Encode aString
as ASCII bytes to the buffer with a length prefix.- Specified by:
putStringAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the String should be encoded.value
- of the String to be encoded.byteOrder
- for the length prefix.- Returns:
- the number of bytes put into the buffer.
-
putStringAscii
Encode aCharSequence
as ASCII bytes to the buffer with a length prefix.- Specified by:
putStringAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the CharSequence should be encoded.value
- of the CharSequence to be encoded.byteOrder
- for the length prefix.- Returns:
- the number of bytes put into the buffer.
-
getStringWithoutLengthAscii
Get an encoded ASCII String from the buffer that does not have a length prefix.- Specified by:
getStringWithoutLengthAscii
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.length
- of the String in bytes to decode.- Returns:
- the String as represented by the Ascii encoded bytes.
-
getStringWithoutLengthAscii
Get an encoded ASCII String from the buffer that does not have a length prefix and append to anAppendable
.- Specified by:
getStringWithoutLengthAscii
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.length
- of the String in bytes to decode.appendable
- to append the chars to.- Returns:
- the number of bytes copied.
-
putStringWithoutLengthAscii
Encode aString
as ASCII bytes in the buffer without a length prefix.- Specified by:
putStringWithoutLengthAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the String begins.value
- of the String to be encoded.- Returns:
- the number of bytes encoded.
-
putStringWithoutLengthAscii
Encode aCharSequence
as ASCII bytes in the buffer without a length prefix.- Specified by:
putStringWithoutLengthAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the CharSequence begins.value
- of the CharSequence to be encoded.- Returns:
- the number of bytes encoded.
-
putStringWithoutLengthAscii
Encode aString
as ASCII bytes in the buffer without a length prefix taking a range of the value.- Specified by:
putStringWithoutLengthAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the String begins.value
- of the String to be encoded.valueOffset
- in the value String to begin.length
- of the value String to encode. If this is greater than valueOffset - value length then the lesser will be used.- Returns:
- the number of bytes encoded.
-
putStringWithoutLengthAscii
Encode aCharSequence
as ASCII bytes in the buffer without a length prefix taking a range of the value.- Specified by:
putStringWithoutLengthAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the CharSequence begins.value
- of the CharSequence to be encoded.valueOffset
- in the value CharSequence to begin.length
- of the value CharSequence to encode. If this is greater than valueOffset - value length then the lesser will be used.- Returns:
- the number of bytes encoded.
-
getStringUtf8
Get a String from bytes encoded in UTF-8 format that is length prefixed.- Specified by:
getStringUtf8
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.- Returns:
- the String as represented by the UTF-8 encoded bytes.
-
getStringUtf8
Get a String from bytes encoded in UTF-8 format that is length prefixed.- Specified by:
getStringUtf8
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.byteOrder
- for the length at the beginning of the String.- Returns:
- the String as represented by the UTF-8 encoded bytes.
-
getStringUtf8
Get part of String from bytes encoded in UTF-8 format that is length prefixed.- Specified by:
getStringUtf8
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.length
- of the String in bytes to decode.- Returns:
- the String as represented by the UTF-8 encoded bytes.
-
putStringUtf8
Encode aString
as UTF-8 bytes to the buffer with a length prefix.- Specified by:
putStringUtf8
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the String should be encoded.value
- of the String to be encoded.- Returns:
- the number of bytes put into the buffer.
-
putStringUtf8
Encode aString
as UTF-8 bytes to the buffer with a length prefix.- Specified by:
putStringUtf8
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the String should be encoded.value
- of the String to be encoded.byteOrder
- for the length prefix.- Returns:
- the number of bytes put into the buffer.
-
putStringUtf8
Encode aString
as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.- Specified by:
putStringUtf8
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the String should be encoded.value
- of the String to be encoded.maxEncodedLength
- to be checked before writing to the buffer.- Returns:
- the number of bytes put into the buffer.
-
putStringUtf8
Encode aString
as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.- Specified by:
putStringUtf8
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the String should be encoded.value
- of the String to be encoded.byteOrder
- for the length prefix.maxEncodedLength
- to be checked before writing to the buffer.- Returns:
- the number of bytes put into the buffer.
-
getStringWithoutLengthUtf8
Get an encoded UTF-8 String from the buffer that does not have a length prefix.- Specified by:
getStringWithoutLengthUtf8
in interfaceDirectBuffer
- Parameters:
index
- at which the String begins.length
- of the String in bytes to decode.- Returns:
- the String as represented by the UTF-8 encoded bytes.
-
putStringWithoutLengthUtf8
Encode aString
as UTF-8 bytes in the buffer without a length prefix.- Specified by:
putStringWithoutLengthUtf8
in interfaceMutableDirectBuffer
- Parameters:
index
- at which the String begins.value
- of the String to be encoded.- Returns:
- the number of bytes encoded.
-
parseNaturalIntAscii
public int parseNaturalIntAscii(int index, int length) Parse the ASCII encoded int sized natural value at a given index.- Specified by:
parseNaturalIntAscii
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.length
- the length in bytes to parse.- Returns:
- the value at a given index.
-
parseNaturalLongAscii
public long parseNaturalLongAscii(int index, int length) Parse the ASCII encoded long sized natural value at a given index.- Specified by:
parseNaturalLongAscii
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.length
- the length in bytes to parse.- Returns:
- the value at a given index.
-
parseIntAscii
public int parseIntAscii(int index, int length) Parse the ASCII encoded integer value at a given index.- Specified by:
parseIntAscii
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.length
- the length in bytes to parse.- Returns:
- the value at a given index.
-
parseLongAscii
public long parseLongAscii(int index, int length) Parse the ASCII encoded long integer value at a given index.- Specified by:
parseLongAscii
in interfaceDirectBuffer
- Parameters:
index
- in bytes from which to get.length
- the length in bytes to parse.- Returns:
- the value at a given index.
-
putIntAscii
public int putIntAscii(int index, int value) Puts an ASCII encoded int into the buffer.- Specified by:
putIntAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- the offset at which to put the int.value
- the int to write.- Returns:
- the number of bytes that the int took up encoded.
-
putNaturalIntAscii
public int putNaturalIntAscii(int index, int value) Puts an ASCII encoded int sized natural number into the buffer.- Specified by:
putNaturalIntAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- the offset at which to put the int.value
- the int to write.- Returns:
- the number of bytes that the int took up encoded.
-
putNaturalPaddedIntAscii
public void putNaturalPaddedIntAscii(int offset, int length, int value) Encode a natural number with a specified maximum length.If ascii encoding of the number is less than the specified length then the start will be pre-padded with zeros, if the value takes up more space than the allowed length then a
will be thrown.NumberFormatException
- Specified by:
putNaturalPaddedIntAscii
in interfaceMutableDirectBuffer
- Parameters:
offset
- the offset to start encoding at.length
- the maximum length to encode.value
- the value to encode.
-
putNaturalIntAsciiFromEnd
public int putNaturalIntAsciiFromEnd(int value, int endExclusive) Encode a natural number starting at its end position.- Specified by:
putNaturalIntAsciiFromEnd
in interfaceMutableDirectBuffer
- Parameters:
value
- the natural number to encode.endExclusive
- index after the last character encoded.- Returns:
- startInclusive index of first character encoded.
-
putNaturalLongAscii
public int putNaturalLongAscii(int index, long value) Puts an ASCII encoded long sized natural number into the buffer.- Specified by:
putNaturalLongAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- the offset at which to put the int.value
- the int to write.- Returns:
- the number of bytes that the int took up encoded.
-
putLongAscii
public int putLongAscii(int index, long value) Puts an ASCII encoded long integer into the buffer.- Specified by:
putLongAscii
in interfaceMutableDirectBuffer
- Parameters:
index
- the offset at which to put the int.value
- the int to write.- Returns:
- the number of bytes that the int took up encoded.
-
boundsCheck
public void boundsCheck(int index, int length) Check that a given length of bytes is within the bounds from a given index.- Specified by:
boundsCheck
in interfaceDirectBuffer
- Parameters:
index
- from which to check.length
- in bytes of the range to check.
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareTo
in interfaceComparable<DirectBuffer>
-
boundsCheck0
protected final void boundsCheck0(int index, int length) -
ensureCapacity
protected abstract void ensureCapacity(int index, int length) -
parsePositiveIntAscii
private int parsePositiveIntAscii(int index, int length, int startIndex, int end) -
parsePositiveIntAsciiOverflowCheck
private long parsePositiveIntAsciiOverflowCheck(int index, int length, int startIndex, int end) -
throwParseIntError
private void throwParseIntError(int index, int length) -
throwParseIntOverflowError
private void throwParseIntOverflowError(int index, int length) -
parsePositiveLongAscii
private long parsePositiveLongAscii(int index, int length, int startIndex, int end) -
parseLongAsciiOverflowCheck
private long parseLongAsciiOverflowCheck(int index, int length, int[] maxValue, int startIndex, int end) -
throwParseLongError
private void throwParseLongError(int index, int length) -
throwParseLongOverflowError
private void throwParseLongOverflowError(int index, int length) -
putPositiveIntAscii
private static void putPositiveIntAscii(byte[] dest, long offset, int value, int digitCount) -
putPositiveLongAscii
private static void putPositiveLongAscii(byte[] dest, long offset, long value, int digitCount)
-