Interface SerializableData

All Superinterfaces:
Data
All Known Implementing Classes:
SerializableDataImpl

public interface SerializableData
extends Data
Represents a Data object which can be serialized and read back.

See SerializableDataImpl for the default implementation.

  • Field Summary

    Fields 
    Modifier and Type Field Description
    static DataManager DATA_MANAGER  

    Fields inherited from interface net.minestom.server.data.Data

    EMPTY
  • Method Summary

    Modifier and Type Method Description
    default byte[] getIndexedSerializedData()
    Serializes the data into an array of bytes.
    byte[] getSerializedData​(it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> typeToIndexMap, boolean indexed)
    Serializes the data into an array of bytes.
    static it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> readDataIndexes​(BinaryReader binaryReader)
    Reads a data index map (type name -> type index).
    default void readIndexedSerializedData​(BinaryReader reader)
    Reads the index map and the data of a serialized SerializableData.
    void readSerializedData​(BinaryReader reader, it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> typeToIndexMap)
    Reads the data of a SerializableData when you already have the index map.
    <T> void set​(java.lang.String key, T value, java.lang.Class<T> type)
    Assigns a value to a specific key.
    static void writeDataIndexHeader​(BinaryWriter indexWriter, it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> typeToIndexMap)
    Writes the index info (class name -> class index), used to write the header for indexed serialized data.

    Methods inherited from interface net.minestom.server.data.Data

    copy, get, getKeys, getOrDefault, hasKey, isEmpty, set
  • Field Details

  • Method Details

    • set

      <T> void set​(@NotNull java.lang.String key, @Nullable T value, @Nullable java.lang.Class<T> type)
      Description copied from interface: Data
      Assigns a value to a specific key.
      Specified by:
      set in interface Data
      Type Parameters:
      T - the value generic
      Parameters:
      key - the key
      value - the value object, null to remove the key
      type - the value type, Data.set(String, Object) can be used instead. null if value is also null
    • getSerializedData

      @NotNull byte[] getSerializedData​(@NotNull it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> typeToIndexMap, boolean indexed)
      Serializes the data into an array of bytes.

      Use readIndexedSerializedData(BinaryReader) if indexed is true, readSerializedData(BinaryReader, Object2ShortMap) otherwise with the index map to convert it back to a SerializableData.

      Parameters:
      typeToIndexMap - the type to index map, will create entries if new types are discovered. The map is not thread-safe
      indexed - true to add the types index in the header
      Returns:
      the array representation of this data object
    • readSerializedData

      void readSerializedData​(@NotNull BinaryReader reader, @NotNull it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> typeToIndexMap)
      Reads the data of a SerializableData when you already have the index map.

      WARNING: the data to read should not have any index to read and your index map should be COMPLETE. Use readIndexedSerializedData(BinaryReader) if you need to read the header.

      Parameters:
      reader - the binary reader
      typeToIndexMap - the index map
    • getIndexedSerializedData

      @NotNull default byte[] getIndexedSerializedData()
      Serializes the data into an array of bytes.

      Use readIndexedSerializedData(BinaryReader) to convert it back to a SerializableData.

      This will create a type index map which will be present in the header.

      Returns:
      the array representation of this data object
    • readIndexedSerializedData

      default void readIndexedSerializedData​(@NotNull BinaryReader reader)
      Reads the index map and the data of a serialized SerializableData.

      Got from getIndexedSerializedData().

      Parameters:
      reader - the binary reader
    • writeDataIndexHeader

      static void writeDataIndexHeader​(@NotNull BinaryWriter indexWriter, @NotNull it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> typeToIndexMap)
      Writes the index info (class name -> class index), used to write the header for indexed serialized data.

      Sized by a var-int.

      Parameters:
      typeToIndexMap - the filled data index map
    • readDataIndexes

      @NotNull static it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> readDataIndexes​(@NotNull BinaryReader binaryReader)
      Reads a data index map (type name -> type index).

      Can then be used with readSerializedData(BinaryReader, Object2ShortMap).

      Parameters:
      binaryReader - the reader
      Returns:
      a map containing the indexes of your data