Package net.minestom.server.data
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
-
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 serializedSerializableData
.void
readSerializedData(BinaryReader reader, it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> typeToIndexMap)
Reads the data of aSerializableData
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.
-
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 interfaceData
- Type Parameters:
T
- the value generic- Parameters:
key
- the keyvalue
- the value object, null to remove the keytype
- the value type,Data.set(String, Object)
can be used instead. null ifvalue
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)
ifindexed
is true,readSerializedData(BinaryReader, Object2ShortMap)
otherwise with the index map to convert it back to aSerializableData
.- Parameters:
typeToIndexMap
- the type to index map, will create entries if new types are discovered. The map is not thread-safeindexed
- 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 aSerializableData
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 readertypeToIndexMap
- the index map
-
getIndexedSerializedData
@NotNull default byte[] getIndexedSerializedData()Serializes the data into an array of bytes.Use
readIndexedSerializedData(BinaryReader)
to convert it back to aSerializableData
.This will create a type index map which will be present in the header.
- Returns:
- the array representation of this data object
-
readIndexedSerializedData
Reads the index map and the data of a serializedSerializableData
.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
-