Class DataType<T>

java.lang.Object
org.geysermc.geyser.api.network.message.DataType<T>
Type Parameters:
T - the type

public final class DataType<T> extends Object
Represents a data type that can be sent or received over the network.
Since:
2.9.2
  • Field Details

    • BOOLEAN

      public static final DataType<Boolean> BOOLEAN
      A DataType for reading and writing boolean values.
    • BYTE

      public static final DataType<Byte> BYTE
      A DataType for reading and writing byte values.
    • SHORT

      public static final DataType<Short> SHORT
      A DataType for reading and writing short values.
    • INT

      public static final DataType<Integer> INT
      A DataType for reading and writing integer values.
    • FLOAT

      public static final DataType<Float> FLOAT
      A DataType for reading and writing float values.
    • DOUBLE

      public static final DataType<Double> DOUBLE
      A DataType for reading and writing double values.
    • LONG

      public static final DataType<Long> LONG
      A DataType for reading and writing long values.
    • VAR_INT

      public static final DataType<Integer> VAR_INT
      A DataType for reading and writing variable-length integers.
    • UNSIGNED_VAR_INT

      public static final DataType<Integer> UNSIGNED_VAR_INT
      A DataType for reading and writing unsigned variable-length integers.
    • VAR_LONG

      public static final DataType<Long> VAR_LONG
      A DataType for reading and writing variable-length long values.
    • UNSIGNED_VAR_LONG

      public static final DataType<Long> UNSIGNED_VAR_LONG
      A DataType for reading and writing unsigned variable-length long values.
    • STRING

      public static final DataType<String> STRING
      A DataType for reading and writing strings.

      Note: Strings are encoded in UTF-8 format.

    • UUID

      public static final DataType<UUID> UUID
      A DataType for reading and writing UUIDs.
  • Method Details

    • read

      public <B extends MessageBuffer, C extends MessageCodec<B>> T read(C codec, B buffer)
      Reads a value of this data type from the given buffer using the specified codec.
      Parameters:
      codec - the codec to use for reading
      buffer - the buffer to read from
      Returns:
      the read value
    • write

      public <B extends MessageBuffer, C extends MessageCodec<B>> void write(C codec, B buffer, T value)
      Writes a value of this data type to the given buffer using the specified codec.
      Parameters:
      codec - the codec to use for writing
      buffer - the buffer to write to
      value - the value to write
    • of

      public static <T> DataType<T> of(DataType.Reader<T> reader, DataType.Writer<T> writer)
      Creates a new DataType with the specified reader and writer.
      Type Parameters:
      T - the type of values this DataType handles
      Parameters:
      reader - the reader to use for reading values of this type
      writer - the writer to use for writing values of this type
      Returns:
      a new DataType instance
    • optional

      public static <T> DataType<Optional<T>> optional(DataType<T> type)
      Creates an optional DataType based on the provided type.
      Type Parameters:
      T - the type of the value contained in the Optional
      Parameters:
      type - the underlying data type to be wrapped in an Optional
      Returns:
      a DataType that reads and writes Optional values
    • list

      public static <T> DataType<List<T>> list(DataType<T> type)
      Creates a DataType that represents a list of values of the specified type.
      Type Parameters:
      T - the type of the elements in the list
      Parameters:
      type - the underlying data type of the list elements
      Returns:
      a DataType that reads and writes lists of the specified type