Package net.minestom.server.data
Class SerializableDataImpl
java.lang.Object
net.minestom.server.data.DataImpl
net.minestom.server.data.SerializableDataImpl
- All Implemented Interfaces:
Data
,SerializableData
public class SerializableDataImpl extends DataImpl implements SerializableData
SerializableData
implementation based on DataImpl
.-
Field Summary
-
Constructor Summary
Constructors Constructor Description SerializableDataImpl()
-
Method Summary
Modifier and Type Method Description Data
copy()
Copies this data.byte[]
getSerializedData(it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> typeToIndexMap, boolean indexed)
Serializes the data into an array of bytes.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)
Sets a value to a specific key.Methods inherited from class net.minestom.server.data.DataImpl
get, getKeys, getOrDefault, hasKey, isEmpty
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.minestom.server.data.Data
get, getKeys, getOrDefault, hasKey, isEmpty, set
Methods inherited from interface net.minestom.server.data.SerializableData
getIndexedSerializedData, readIndexedSerializedData
-
Constructor Details
-
SerializableDataImpl
public SerializableDataImpl()
-
-
Method Details
-
set
public <T> void set(@NotNull java.lang.String key, @Nullable T value, @Nullable java.lang.Class<T> type)Sets a value to a specific key.WARNING: the type needs to be registered in
DataManager
.- Specified by:
set
in interfaceData
- Specified by:
set
in interfaceSerializableData
- Overrides:
set
in classDataImpl
- Type Parameters:
T
- the value generic- Parameters:
key
- the keyvalue
- the value objecttype
- the value type- Throws:
java.lang.UnsupportedOperationException
- iftype
is not registered inDataManager
-
copy
Description copied from interface:Data
Copies this data. -
getSerializedData
@NotNull public byte[] getSerializedData(@NotNull it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> typeToIndexMap, boolean indexed)Description copied from interface:SerializableData
Serializes the data into an array of bytes.Use
SerializableData.readIndexedSerializedData(BinaryReader)
ifindexed
is true,SerializableData.readSerializedData(BinaryReader, Object2ShortMap)
otherwise with the index map to convert it back to aSerializableData
.- Specified by:
getSerializedData
in interfaceSerializableData
- 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
public void readSerializedData(@NotNull BinaryReader reader, @NotNull it.unimi.dsi.fastutil.objects.Object2ShortMap<java.lang.String> typeToIndexMap)Description copied from interface:SerializableData
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
SerializableData.readIndexedSerializedData(BinaryReader)
if you need to read the header.- Specified by:
readSerializedData
in interfaceSerializableData
- Parameters:
reader
- the binary readertypeToIndexMap
- the index map
-