Interface DataBuf.Mutable

All Superinterfaces:
AutoCloseable, DataBuf
Enclosing interface:
DataBuf

public static interface DataBuf.Mutable extends DataBuf
Represents a mutable version of a data buf.
Since:
4.0
  • Method Details

    • writeBoolean

      @NonNull DataBuf.Mutable writeBoolean(boolean b)
      Writes the given boolean at the current writer index, increasing the index by one.
      Parameters:
      b - the boolean to write.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeInt

      @NonNull DataBuf.Mutable writeInt(int integer)
      Writes the given integer at the current writer index, increasing the index by four.
      Parameters:
      integer - the integer to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeByte

      @NonNull DataBuf.Mutable writeByte(byte b)
      Writes the given byte at the current writer index, increasing the index by one.
      Parameters:
      b - the byte to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeShort

      @NonNull DataBuf.Mutable writeShort(short s)
      Writes the given short at the current writer index, increasing the index by two.
      Parameters:
      s - the short to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeLong

      @NonNull DataBuf.Mutable writeLong(long l)
      Writes the given long at the current writer index, increasing the index by eight.
      Parameters:
      l - the long to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeFloat

      @NonNull DataBuf.Mutable writeFloat(float f)
      Writes the given float at the current writer index, increasing the index by four.
      Parameters:
      f - the float to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeDouble

      @NonNull DataBuf.Mutable writeDouble(double d)
      Writes the given double at the current writer index, increasing the index by eight.
      Parameters:
      d - the double to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeChar

      @NonNull DataBuf.Mutable writeChar(char c)
      Writes the given UTF-16 char at the current writer index, increasing the index by two.
      Parameters:
      c - the char to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeByteArray

      @NonNull DataBuf.Mutable writeByteArray(byte[] b)
      Writes the given byte array into the buffer, prefixed by an integer containing the amount of bytes following in the array.

      This method call is equivalent to writeByteArray(b, b.length).

      Parameters:
      b - the byte array to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeByteArray

      @NonNull DataBuf.Mutable writeByteArray(byte[] b, int amount)
      Writes the given byte array into the buffer, prefixed by an integer containing the amount of bytes following in the array.
      Parameters:
      b - the byte array to write into the buffer.
      amount - the amount of bytes of the array to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeUniqueId

      Writes the unique id into the buffer by first writing the most significant bits of the id followed by the last significant bits of the id.
      Parameters:
      uuid - the id to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeString

      Writes the string into the buffer. This method does the same thing as writeByteArray(byte[]). The string gets converted into it's byte array representation and then written into the buffer like that.
      Parameters:
      string - the string to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeDataBuf

      Writes all data of the given data buffer into this data buffer starting at the current reader index of the given buffer.

      Buffers are not expected to be cross-implementation-compatible. For instance, a netty buffer can only be written to netty buffers.

      Parameters:
      buf - the buffer to write into this buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • writeObject

      Writes the given object into this buffer. The object is written using the default object mapper of the system.
      Parameters:
      obj - the object to write into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
      See Also:
    • writeNullable

      @NonNull <T> DataBuf.Mutable writeNullable(@Nullable T object, @NonNull @NonNull BiConsumer<DataBuf.Mutable, T> handlerWhenNonNull)
      Writes the given object null-safe into this buffer. It appends a boolean before the actual object data (if the object is present) whether the data is present. The writer consumer is only called when the data is present and can then safely proceed to write all the required data into the buffer. The supplied buffer is the same buffer used for calling the method.
      Type Parameters:
      T - the generic type of the object being written.
      Parameters:
      object - the object which should be safely written into this buffer.
      handlerWhenNonNull - the writer of the object when it's non-null.
      Returns:
      the same buffer used to call the method, for chaining.
    • ensureWriteable

      @NonNull DataBuf.Mutable ensureWriteable(int bytes)
      Ensures that this buffer has at least the given amount of bytes unused for writing data. If the buffer already has the amount of bytes present, this method returns immediately.
      Parameters:
      bytes - the bytes that must be available in the buffer.
      Returns:
      this buffer, for chaining.
      Throws:
      IllegalArgumentException - if the given byte count is negative.
    • asImmutable

      @NonNull @NonNull DataBuf asImmutable()
      Converts this buffer into an immutable version of it. The underlying buffer is not expected to be clones, that means that writes to this buffer are still reflected into the immutable version of it and vise-versa.
      Returns:
      an immutable version of this buffer.