Class PluginMessageByteBuffer

java.lang.Object
wtf.choco.veinminer.network.PluginMessageByteBuffer

public class PluginMessageByteBuffer extends Object
A utility class to allow for reading and writing of complex types to/from a byte array.
  • Constructor Details

    • PluginMessageByteBuffer

      public PluginMessageByteBuffer(@NotNull @NotNull ByteBuffer buffer)
      Construct a new PluginMessageByteBuffer wrapping a ByteBuffer. Intended for reading data.
      Parameters:
      buffer - the buffer to wrap
    • PluginMessageByteBuffer

      public PluginMessageByteBuffer(byte[] data)
      Construct a new PluginMessageByteBuffer wrapping a byte array. Intended for reading data.
      Parameters:
      data - the data to wrap
    • PluginMessageByteBuffer

      public PluginMessageByteBuffer()
      Construct a new PluginMessageByteBuffer. Intended for writing data.
  • Method Details

    • writeInt

      public void writeInt(int value)
      Write a 4 byte integer.
      Parameters:
      value - the value to write
    • readInt

      public int readInt()
      Read a 4 byte integer.
      Returns:
      the read value
    • writeVarInt

      public void writeVarInt(int value)
      Write a variable-length integer.
      Parameters:
      value - the value to write
    • readVarInt

      public int readVarInt()
      Read a variable-length integer.
      Returns:
      the read value
      Throws:
      IllegalStateException - if the var int is too large
    • writeLong

      public void writeLong(long value)
      Write an 8 byte long.
      Parameters:
      value - the value to write
    • readLong

      public long readLong()
      Read an 8 byte long.
      Returns:
      the read value
    • writeVarLong

      public void writeVarLong(long value)
      Write a variable-length long.
      Parameters:
      value - the value to write
    • readVarLong

      public long readVarLong()
      Read a variable-length long.
      Returns:
      the read value
      Throws:
      IllegalStateException - if the var long is too large
    • writeBoolean

      public void writeBoolean(boolean value)
      Write a boolean primitive.
      Parameters:
      value - the value to write
    • readBoolean

      public boolean readBoolean()
      Read a boolean primitive.
      Returns:
      the read value
    • writeString

      public void writeString(@NotNull @NotNull String string)
      Write a UTF-8 String.
      Parameters:
      string - the string to write
    • readString

      @NotNull public @NotNull String readString()
      Read a UTF-8 String.
      Returns:
      the string
    • writeBytes

      public void writeBytes(byte[] bytes)
      Write an array of bytes.
      Parameters:
      bytes - the bytes to write
    • writeByteArray

      public void writeByteArray(byte[] bytes)
      Write an array of bytes prefixed by a variable-length int.
      Parameters:
      bytes - the bytes to write
    • readByteArray

      public byte[] readByteArray()
      Read an array of bytes prefixed by a variable-length int.
      Returns:
      the byte array
    • readBytes

      public byte[] readBytes()
      Read the remaining bytes in this buffer as an array.
      Returns:
      the bytes
    • readBytes

      public byte[] readBytes(int size)
      Read a set amount of bytes from this buffer as an array.
      Parameters:
      size - the amount of bytes to read
      Returns:
      the bytes
    • readBytes

      public void readBytes(byte[] destination)
      Read a set amount of bytes from this buffer into a destination array. This method will read up to destination.length bytes.
      Parameters:
      destination - the array in which the bytes should be written
    • writeByte

      public void writeByte(byte value)
      Write a raw byte.
      Parameters:
      value - the value to write
    • writeByte

      public void writeByte(int value)
      Write a raw byte.
      Parameters:
      value - the value to write
    • readByte

      public byte readByte()
      Read a raw byte.
      Returns:
      the byte
    • writeBlockPosition

      public void writeBlockPosition(@NotNull @NotNull BlockPosition position)
      Write a BlockPosition.
      Parameters:
      position - the position to write
    • readBlockPosition

      @NotNull public @NotNull BlockPosition readBlockPosition()
      Returns:
      the BlockPosition
    • writeNamespacedKey

      public void writeNamespacedKey(@NotNull @NotNull NamespacedKey key)
      Write a NamespacedKey.
      Parameters:
      key - the key to write
    • readNamespacedKey

      @NotNull public @NotNull NamespacedKey readNamespacedKey()
      Returns:
      the NamespacedKey
    • asByteArray

      public byte[] asByteArray()
      Get this byte buffer as a byte array (for writing).
      Returns:
      the byte array