Package org.agrona

Interface MutableDirectBuffer

All Superinterfaces:
Comparable<DirectBuffer>, DirectBuffer
All Known Subinterfaces:
AtomicBuffer
All Known Implementing Classes:
AbstractMutableDirectBuffer, ExpandableArrayBuffer, ExpandableDirectByteBuffer, UnsafeBuffer

public interface MutableDirectBuffer extends DirectBuffer
Abstraction over a range of buffer types that allows fields to be written in native typed fashion.

ByteOrder of a wrapped buffer is not applied to the MutableDirectBuffer. To control ByteOrder use the appropriate method with a ByteOrder overload.

  • Method Details

    • isExpandable

      boolean isExpandable()
      Is this buffer expandable to accommodate putting data into it beyond the current capacity?
      Returns:
      true is the underlying storage can expand otherwise false.
    • setMemory

      void setMemory(int index, int length, byte value)
      Set a region of memory to a given byte value.
      Parameters:
      index - at which to start.
      length - of the run of bytes to set.
      value - the memory will be set to.
    • putLong

      void putLong(int index, long value, ByteOrder byteOrder)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - for at a given index.
      byteOrder - of the value when written.
    • putLong

      void putLong(int index, long value)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - for at a given index.
    • putInt

      void putInt(int index, int value, ByteOrder byteOrder)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - to be written.
      byteOrder - of the value when written.
    • putInt

      void putInt(int index, int value)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - for at a given index.
    • putIntAscii

      int putIntAscii(int index, int value)
      Puts an ASCII encoded int into the buffer.
      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

      int putNaturalIntAscii(int index, int value)
      Puts an ASCII encoded int sized natural number into the buffer.
      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

      void putNaturalPaddedIntAscii(int index, int length, int value) throws NumberFormatException
      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.

      Parameters:
      index - the offset to start encoding at.
      length - the maximum length to encode.
      value - the value to encode.
      Throws:
      NumberFormatException - if the value won't fit within the length.
    • putNaturalIntAsciiFromEnd

      int putNaturalIntAsciiFromEnd(int value, int endExclusive)
      Encode a natural number starting at its end position.
      Parameters:
      value - the natural number to encode.
      endExclusive - index after the last character encoded.
      Returns:
      startInclusive index of first character encoded.
    • putNaturalLongAscii

      int putNaturalLongAscii(int index, long value)
      Puts an ASCII encoded long sized natural number into the buffer.
      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

      int putLongAscii(int index, long value)
      Puts an ASCII encoded long integer into the buffer.
      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.
    • putDouble

      void putDouble(int index, double value, ByteOrder byteOrder)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - to be written.
      byteOrder - of the value when written.
    • putDouble

      void putDouble(int index, double value)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - to be written.
    • putFloat

      void putFloat(int index, float value, ByteOrder byteOrder)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - to be written.
      byteOrder - of the value when written.
    • putFloat

      void putFloat(int index, float value)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - to be written.
    • putShort

      void putShort(int index, short value, ByteOrder byteOrder)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - to be written.
      byteOrder - of the value when written.
    • putShort

      void putShort(int index, short value)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - to be written.
    • putChar

      void putChar(int index, char value, ByteOrder byteOrder)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - to be written.
      byteOrder - of the value when written.
    • putChar

      void putChar(int index, char value)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - to be written.
    • putByte

      void putByte(int index, byte value)
      Put a value to a given index.
      Parameters:
      index - in bytes for where to put.
      value - to be written.
    • putBytes

      void putBytes(int index, byte[] src)
      Put an array of src into the underlying buffer.
      Parameters:
      index - in the underlying buffer to start from.
      src - to be copied into the underlying buffer.
    • putBytes

      void putBytes(int index, byte[] src, int offset, int length)
      Put an array into the underlying buffer.
      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

      void putBytes(int index, 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.

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

      void putBytes(int index, 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.

      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

      void putBytes(int index, DirectBuffer srcBuffer, int srcIndex, int length)
      Put bytes from a source DirectBuffer into this MutableDirectBuffer at given indices.
      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.
    • putStringAscii

      int putStringAscii(int index, String value)
      Encode a String as ASCII bytes to the buffer with a length prefix.
      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

      int putStringAscii(int index, CharSequence value)
      Encode a CharSequence as ASCII bytes to the buffer with a length prefix.
      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

      int putStringAscii(int index, String value, ByteOrder byteOrder)
      Encode a String as ASCII bytes to the buffer with a length prefix.
      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

      int putStringAscii(int index, CharSequence value, ByteOrder byteOrder)
      Encode a CharSequence as ASCII bytes to the buffer with a length prefix.
      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.
    • putStringWithoutLengthAscii

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

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

      int putStringWithoutLengthAscii(int index, 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.
      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

      int putStringWithoutLengthAscii(int index, 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.
      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.
    • putStringUtf8

      int putStringUtf8(int index, String value)
      Encode a String as UTF-8 bytes to the buffer with a length prefix.
      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

      int putStringUtf8(int index, String value, ByteOrder byteOrder)
      Encode a String as UTF-8 bytes to the buffer with a length prefix.
      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

      int putStringUtf8(int index, String value, int maxEncodedLength)
      Encode a String as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.
      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.
      Throws:
      IllegalArgumentException - if the encoded bytes are greater than maxEncodedLength.
    • putStringUtf8

      int putStringUtf8(int index, String value, ByteOrder byteOrder, int maxEncodedLength)
      Encode a String as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.
      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.
      Throws:
      IllegalArgumentException - if the encoded bytes are greater than maxEncodedLength.
    • putStringWithoutLengthUtf8

      int putStringWithoutLengthUtf8(int index, String value)
      Encode a String as UTF-8 bytes in the buffer without a length prefix.
      Parameters:
      index - at which the String begins.
      value - of the String to be encoded.
      Returns:
      the number of bytes encoded.