Package org.agrona

Class AbstractMutableDirectBuffer

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      long addressOffset()
      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 void boundsCheck0​(int index, int length)
      Perform bound checks.
      byte[] byteArray()
      Get the underlying byte[] 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)
      A hook to ensure the underlying buffer has enough capacity for writing data into the buffer.
      boolean equals​(java.lang.Object obj)
      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, java.nio.ByteBuffer dstBuffer, int length)
      Get from the underlying buffer into a supplied ByteBuffer current Buffer.position().
      void getBytes​(int index, java.nio.ByteBuffer dstBuffer, int dstOffset, int length)
      Get from the underlying buffer into a supplied ByteBuffer at an offset.
      void getBytes​(int index, MutableDirectBuffer dstBuffer, int dstIndex, int length)
      Get bytes from this DirectBuffer into the provided MutableDirectBuffer at given indices.
      char getChar​(int index)
      Get the value at a given index.
      char getChar​(int index, java.nio.ByteOrder byteOrder)
      Get the value at a given index.
      double getDouble​(int index)
      Get the value at a given index.
      double getDouble​(int index, java.nio.ByteOrder byteOrder)
      Get the value at a given index.
      float getFloat​(int index)
      Get the value at a given index.
      float getFloat​(int index, java.nio.ByteOrder byteOrder)
      Get the value at a given index.
      int getInt​(int index)
      Get the value at a given index.
      int getInt​(int index, java.nio.ByteOrder byteOrder)
      Get the value at a given index.
      long getLong​(int index)
      Get the value at a given index.
      long getLong​(int index, java.nio.ByteOrder byteOrder)
      Get the value at a given index.
      short getShort​(int index)
      Get the value at a given index.
      short getShort​(int index, java.nio.ByteOrder byteOrder)
      Get the value at a given index.
      java.lang.String getStringAscii​(int index)
      Get a String from bytes encoded in ASCII format that is length prefixed.
      java.lang.String 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, java.lang.Appendable appendable)
      Get part of a String from bytes encoded in ASCII format that is length prefixed and append to an Appendable.
      int getStringAscii​(int index, java.lang.Appendable appendable)
      Get a String from bytes encoded in ASCII format that is length prefixed and append to an Appendable.
      int getStringAscii​(int index, java.lang.Appendable appendable, java.nio.ByteOrder byteOrder)
      Get a String from bytes encoded in ASCII format that is length prefixed and append to an Appendable.
      java.lang.String getStringAscii​(int index, java.nio.ByteOrder byteOrder)
      Get a String from bytes encoded in ASCII format that is length prefixed.
      java.lang.String getStringUtf8​(int index)
      Get a String from bytes encoded in UTF-8 format that is length prefixed.
      java.lang.String getStringUtf8​(int index, int length)
      Get part of String from bytes encoded in UTF-8 format that is length prefixed.
      java.lang.String getStringUtf8​(int index, java.nio.ByteOrder byteOrder)
      Get a String from bytes encoded in UTF-8 format that is length prefixed.
      java.lang.String 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, java.lang.Appendable appendable)
      Get an encoded ASCII String from the buffer that does not have a length prefix and append to an Appendable.
      java.lang.String 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, java.nio.ByteBuffer srcBuffer, int length)
      Put bytes into the underlying buffer for the view.
      void putBytes​(int index, java.nio.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 source DirectBuffer into this MutableDirectBuffer at given indices.
      void putChar​(int index, char value)
      Put a value to a given index.
      void putChar​(int index, char value, java.nio.ByteOrder byteOrder)
      Put a value to a given index.
      void putDouble​(int index, double value)
      Put a value to a given index.
      void putDouble​(int index, double value, java.nio.ByteOrder byteOrder)
      Put a value to a given index.
      void putFloat​(int index, float value)
      Put a value to a given index.
      void putFloat​(int index, float value, java.nio.ByteOrder byteOrder)
      Put a value to a given index.
      void putInt​(int index, int value)
      Put a value to a given index.
      void putInt​(int index, int value, java.nio.ByteOrder byteOrder)
      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 putLong​(int index, long value, java.nio.ByteOrder byteOrder)
      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 putShort​(int index, short value, java.nio.ByteOrder byteOrder)
      Put a value to a given index.
      int putStringAscii​(int index, java.lang.CharSequence value)
      Encode a CharSequence as ASCII bytes to the buffer with a length prefix.
      int putStringAscii​(int index, java.lang.CharSequence value, java.nio.ByteOrder byteOrder)
      Encode a CharSequence as ASCII bytes to the buffer with a length prefix.
      int putStringAscii​(int index, java.lang.String value)
      Encode a String as ASCII bytes to the buffer with a length prefix.
      int putStringAscii​(int index, java.lang.String value, java.nio.ByteOrder byteOrder)
      Encode a String as ASCII bytes to the buffer with a length prefix.
      int putStringUtf8​(int index, java.lang.String value)
      Encode a String as UTF-8 bytes to the buffer with a length prefix.
      int putStringUtf8​(int index, java.lang.String value, int maxEncodedLength)
      Encode a String as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.
      int putStringUtf8​(int index, java.lang.String value, java.nio.ByteOrder byteOrder)
      Encode a String as UTF-8 bytes to the buffer with a length prefix.
      int putStringUtf8​(int index, java.lang.String value, java.nio.ByteOrder byteOrder, int maxEncodedLength)
      Encode a String as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.
      int putStringWithoutLengthAscii​(int index, java.lang.CharSequence value)
      Encode a CharSequence as ASCII bytes in the buffer without a length prefix.
      int putStringWithoutLengthAscii​(int index, java.lang.CharSequence value, int valueOffset, int length)
      Encode a CharSequence as ASCII bytes in the buffer without a length prefix taking a range of the value.
      int putStringWithoutLengthAscii​(int index, java.lang.String value)
      Encode a String as ASCII bytes in the buffer without a length prefix.
      int putStringWithoutLengthAscii​(int index, java.lang.String value, int valueOffset, int length)
      Encode a String as ASCII bytes in the buffer without a length prefix taking a range of the value.
      int putStringWithoutLengthUtf8​(int index, java.lang.String value)
      Encode a String 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
    • Field Detail

      • byteArray

        protected byte[] byteArray
        Byte array reference for on-heap buffers.
      • addressOffset

        protected long addressOffset
        Native address for off-heap buffer or a pointer to the beginning of the byte array.
      • capacity

        protected int capacity
        Buffer capacity in bytes.
    • Constructor Detail

      • AbstractMutableDirectBuffer

        protected AbstractMutableDirectBuffer()
        Default constructor.
    • Method Detail

      • addressOffset

        public long addressOffset()
        Reads the underlying offset to the memory address.
        Specified by:
        addressOffset in interface DirectBuffer
        Returns:
        the underlying offset to the memory address.
      • capacity

        public int capacity()
        Get the capacity of the underlying buffer.
        Specified by:
        capacity in interface DirectBuffer
        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 interface DirectBuffer
        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 interface MutableDirectBuffer
        Parameters:
        index - at which to start.
        length - of the run of bytes to set.
        value - the memory will be set to.
      • getLong

        public long getLong​(int index,
                            java.nio.ByteOrder byteOrder)
        Get the value at a given index.
        Specified by:
        getLong in interface DirectBuffer
        Parameters:
        index - in bytes from which to get.
        byteOrder - of the value to be read.
        Returns:
        the value for at a given index.
      • putLong

        public void putLong​(int index,
                            long value,
                            java.nio.ByteOrder byteOrder)
        Put a value to a given index.
        Specified by:
        putLong in interface MutableDirectBuffer
        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 interface DirectBuffer
        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 interface MutableDirectBuffer
        Parameters:
        index - in bytes for where to put.
        value - for at a given index.
      • getInt

        public int getInt​(int index,
                          java.nio.ByteOrder byteOrder)
        Get the value at a given index.
        Specified by:
        getInt in interface DirectBuffer
        Parameters:
        index - in bytes from which to get.
        byteOrder - of the value to be read.
        Returns:
        the value at a given index.
      • putInt

        public void putInt​(int index,
                           int value,
                           java.nio.ByteOrder byteOrder)
        Put a value to a given index.
        Specified by:
        putInt in interface MutableDirectBuffer
        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 interface DirectBuffer
        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 interface MutableDirectBuffer
        Parameters:
        index - in bytes for where to put.
        value - for at a given index.
      • getDouble

        public double getDouble​(int index,
                                java.nio.ByteOrder byteOrder)
        Get the value at a given index.
        Specified by:
        getDouble in interface DirectBuffer
        Parameters:
        index - in bytes from which to get.
        byteOrder - of the value to be read.
        Returns:
        the value at a given index.
      • putDouble

        public void putDouble​(int index,
                              double value,
                              java.nio.ByteOrder byteOrder)
        Put a value to a given index.
        Specified by:
        putDouble in interface MutableDirectBuffer
        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 interface DirectBuffer
        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 interface MutableDirectBuffer
        Parameters:
        index - in bytes for where to put.
        value - to be written.
      • getFloat

        public float getFloat​(int index,
                              java.nio.ByteOrder byteOrder)
        Get the value at a given index.
        Specified by:
        getFloat in interface DirectBuffer
        Parameters:
        index - in bytes from which to get.
        byteOrder - of the value to be read.
        Returns:
        the value at a given index.
      • putFloat

        public void putFloat​(int index,
                             float value,
                             java.nio.ByteOrder byteOrder)
        Put a value to a given index.
        Specified by:
        putFloat in interface MutableDirectBuffer
        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 interface DirectBuffer
        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 interface MutableDirectBuffer
        Parameters:
        index - in bytes for where to put.
        value - to be written.
      • getShort

        public short getShort​(int index,
                              java.nio.ByteOrder byteOrder)
        Get the value at a given index.
        Specified by:
        getShort in interface DirectBuffer
        Parameters:
        index - in bytes from which to get.
        byteOrder - of the value to be read.
        Returns:
        the value at a given index.
      • putShort

        public void putShort​(int index,
                             short value,
                             java.nio.ByteOrder byteOrder)
        Put a value to a given index.
        Specified by:
        putShort in interface MutableDirectBuffer
        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 interface DirectBuffer
        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 interface MutableDirectBuffer
        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 interface DirectBuffer
        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 interface MutableDirectBuffer
        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 interface DirectBuffer
        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 interface DirectBuffer
        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

        public void getBytes​(int index,
                             MutableDirectBuffer dstBuffer,
                             int dstIndex,
                             int length)
        Get bytes from this DirectBuffer into the provided MutableDirectBuffer at given indices.
        Specified by:
        getBytes in interface DirectBuffer
        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

        public void getBytes​(int index,
                             java.nio.ByteBuffer dstBuffer,
                             int length)
        Get from the underlying buffer into a supplied ByteBuffer current Buffer.position().

        The destination buffer will have its Buffer.position() advanced as a result.

        Specified by:
        getBytes in interface DirectBuffer
        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

        public void getBytes​(int index,
                             java.nio.ByteBuffer dstBuffer,
                             int dstOffset,
                             int length)
        Get from the underlying buffer into a supplied ByteBuffer at an offset.

        The destination buffer will not have its Buffer.position() advanced as a result.

        Specified by:
        getBytes in interface DirectBuffer
        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 interface MutableDirectBuffer
        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 interface MutableDirectBuffer
        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

        public void putBytes​(int index,
                             java.nio.ByteBuffer srcBuffer,
                             int length)
        Put bytes into the underlying buffer for the view. Bytes will be copied from current Buffer.position() for a given length.

        The source buffer will have its Buffer.position() advanced as a result.

        Specified by:
        putBytes in interface MutableDirectBuffer
        Parameters:
        index - in the underlying buffer to start from.
        srcBuffer - to copy the bytes from.
        length - of the supplied buffer to copy.
      • putBytes

        public void putBytes​(int index,
                             java.nio.ByteBuffer srcBuffer,
                             int srcIndex,
                             int length)
        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 interface MutableDirectBuffer
        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

        public void putBytes​(int index,
                             DirectBuffer srcBuffer,
                             int srcIndex,
                             int length)
        Put bytes from a source DirectBuffer into this MutableDirectBuffer at given indices.
        Specified by:
        putBytes in interface MutableDirectBuffer
        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

        public char getChar​(int index,
                            java.nio.ByteOrder byteOrder)
        Get the value at a given index.
        Specified by:
        getChar in interface DirectBuffer
        Parameters:
        index - in bytes from which to get.
        byteOrder - of the value to be read.
        Returns:
        the value at a given index.
      • putChar

        public void putChar​(int index,
                            char value,
                            java.nio.ByteOrder byteOrder)
        Put a value to a given index.
        Specified by:
        putChar in interface MutableDirectBuffer
        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 interface DirectBuffer
        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 interface MutableDirectBuffer
        Parameters:
        index - in bytes for where to put.
        value - to be written.
      • getStringAscii

        public java.lang.String getStringAscii​(int index)
        Get a String from bytes encoded in ASCII format that is length prefixed.
        Specified by:
        getStringAscii in interface DirectBuffer
        Parameters:
        index - at which the String begins.
        Returns:
        the String as represented by the ASCII encoded bytes.
      • getStringAscii

        public int getStringAscii​(int index,
                                  java.lang.Appendable appendable)
        Get a String from bytes encoded in ASCII format that is length prefixed and append to an Appendable.
        Specified by:
        getStringAscii in interface DirectBuffer
        Parameters:
        index - at which the String begins.
        appendable - to append the chars to.
        Returns:
        the number of bytes copied.
      • getStringAscii

        public java.lang.String getStringAscii​(int index,
                                               java.nio.ByteOrder byteOrder)
        Get a String from bytes encoded in ASCII format that is length prefixed.
        Specified by:
        getStringAscii in interface DirectBuffer
        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

        public int getStringAscii​(int index,
                                  java.lang.Appendable appendable,
                                  java.nio.ByteOrder byteOrder)
        Get a String from bytes encoded in ASCII format that is length prefixed and append to an Appendable.
        Specified by:
        getStringAscii in interface DirectBuffer
        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

        public java.lang.String getStringAscii​(int index,
                                               int length)
        Get part of a String from bytes encoded in ASCII format that is length prefixed.
        Specified by:
        getStringAscii in interface DirectBuffer
        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

        public int getStringAscii​(int index,
                                  int length,
                                  java.lang.Appendable appendable)
        Get part of a String from bytes encoded in ASCII format that is length prefixed and append to an Appendable.
        Specified by:
        getStringAscii in interface DirectBuffer
        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

        public int putStringAscii​(int index,
                                  java.lang.String value)
        Encode a String as ASCII bytes to the buffer with a length prefix.
        Specified by:
        putStringAscii in interface MutableDirectBuffer
        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

        public int putStringAscii​(int index,
                                  java.lang.CharSequence value)
        Encode a CharSequence as ASCII bytes to the buffer with a length prefix.
        Specified by:
        putStringAscii in interface MutableDirectBuffer
        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

        public int putStringAscii​(int index,
                                  java.lang.String value,
                                  java.nio.ByteOrder byteOrder)
        Encode a String as ASCII bytes to the buffer with a length prefix.
        Specified by:
        putStringAscii in interface MutableDirectBuffer
        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

        public int putStringAscii​(int index,
                                  java.lang.CharSequence value,
                                  java.nio.ByteOrder byteOrder)
        Encode a CharSequence as ASCII bytes to the buffer with a length prefix.
        Specified by:
        putStringAscii in interface MutableDirectBuffer
        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

        public java.lang.String getStringWithoutLengthAscii​(int index,
                                                            int length)
        Get an encoded ASCII String from the buffer that does not have a length prefix.
        Specified by:
        getStringWithoutLengthAscii in interface DirectBuffer
        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

        public int getStringWithoutLengthAscii​(int index,
                                               int length,
                                               java.lang.Appendable appendable)
        Get an encoded ASCII String from the buffer that does not have a length prefix and append to an Appendable.
        Specified by:
        getStringWithoutLengthAscii in interface DirectBuffer
        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

        public int putStringWithoutLengthAscii​(int index,
                                               java.lang.String value)
        Encode a String as ASCII bytes in the buffer without a length prefix.
        Specified by:
        putStringWithoutLengthAscii in interface MutableDirectBuffer
        Parameters:
        index - at which the String begins.
        value - of the String to be encoded.
        Returns:
        the number of bytes encoded.
      • putStringWithoutLengthAscii

        public int putStringWithoutLengthAscii​(int index,
                                               java.lang.CharSequence value)
        Encode a CharSequence as ASCII bytes in the buffer without a length prefix.
        Specified by:
        putStringWithoutLengthAscii in interface MutableDirectBuffer
        Parameters:
        index - at which the CharSequence begins.
        value - of the CharSequence to be encoded.
        Returns:
        the number of bytes encoded.
      • putStringWithoutLengthAscii

        public int putStringWithoutLengthAscii​(int index,
                                               java.lang.String value,
                                               int valueOffset,
                                               int length)
        Encode a String as ASCII bytes in the buffer without a length prefix taking a range of the value.
        Specified by:
        putStringWithoutLengthAscii in interface MutableDirectBuffer
        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

        public int putStringWithoutLengthAscii​(int index,
                                               java.lang.CharSequence value,
                                               int valueOffset,
                                               int length)
        Encode a CharSequence as ASCII bytes in the buffer without a length prefix taking a range of the value.
        Specified by:
        putStringWithoutLengthAscii in interface MutableDirectBuffer
        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

        public java.lang.String getStringUtf8​(int index)
        Get a String from bytes encoded in UTF-8 format that is length prefixed.
        Specified by:
        getStringUtf8 in interface DirectBuffer
        Parameters:
        index - at which the String begins.
        Returns:
        the String as represented by the UTF-8 encoded bytes.
      • getStringUtf8

        public java.lang.String getStringUtf8​(int index,
                                              java.nio.ByteOrder byteOrder)
        Get a String from bytes encoded in UTF-8 format that is length prefixed.
        Specified by:
        getStringUtf8 in interface DirectBuffer
        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

        public java.lang.String getStringUtf8​(int index,
                                              int length)
        Get part of String from bytes encoded in UTF-8 format that is length prefixed.
        Specified by:
        getStringUtf8 in interface DirectBuffer
        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

        public int putStringUtf8​(int index,
                                 java.lang.String value)
        Encode a String as UTF-8 bytes to the buffer with a length prefix.
        Specified by:
        putStringUtf8 in interface MutableDirectBuffer
        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

        public int putStringUtf8​(int index,
                                 java.lang.String value,
                                 java.nio.ByteOrder byteOrder)
        Encode a String as UTF-8 bytes to the buffer with a length prefix.
        Specified by:
        putStringUtf8 in interface MutableDirectBuffer
        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

        public int putStringUtf8​(int index,
                                 java.lang.String value,
                                 int maxEncodedLength)
        Encode a String as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.
        Specified by:
        putStringUtf8 in interface MutableDirectBuffer
        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

        public int putStringUtf8​(int index,
                                 java.lang.String value,
                                 java.nio.ByteOrder byteOrder,
                                 int maxEncodedLength)
        Encode a String as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.
        Specified by:
        putStringUtf8 in interface MutableDirectBuffer
        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

        public java.lang.String getStringWithoutLengthUtf8​(int index,
                                                           int length)
        Get an encoded UTF-8 String from the buffer that does not have a length prefix.
        Specified by:
        getStringWithoutLengthUtf8 in interface DirectBuffer
        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

        public int putStringWithoutLengthUtf8​(int index,
                                              java.lang.String value)
        Encode a String as UTF-8 bytes in the buffer without a length prefix.
        Specified by:
        putStringWithoutLengthUtf8 in interface MutableDirectBuffer
        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 interface DirectBuffer
        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 interface DirectBuffer
        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 interface DirectBuffer
        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 interface DirectBuffer
        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 interface MutableDirectBuffer
        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 interface MutableDirectBuffer
        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 NumberFormatException will be thrown.

        Specified by:
        putNaturalPaddedIntAscii in interface MutableDirectBuffer
        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 interface MutableDirectBuffer
        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 interface MutableDirectBuffer
        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 interface MutableDirectBuffer
        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 interface DirectBuffer
        Parameters:
        index - from which to check.
        length - in bytes of the range to check.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • compareTo

        public int compareTo​(DirectBuffer that)
        Specified by:
        compareTo in interface java.lang.Comparable<DirectBuffer>
      • boundsCheck0

        protected final void boundsCheck0​(int index,
                                          int length)
        Perform bound checks.
        Parameters:
        index - to verify.
        length - to verify.
      • ensureCapacity

        protected abstract void ensureCapacity​(int index,
                                               int length)
        A hook to ensure the underlying buffer has enough capacity for writing data into the buffer.
        Parameters:
        index - at which write occurs.
        length - in bytes.
      • 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)