T
- the type of data that can be serialized and deserialized by this adapterpublic class DelegatedAdapter<T> extends TypeAdapter<T>
Constructor and Description |
---|
DelegatedAdapter(DataType<T> dataType,
java.util.function.Function<? super T,byte[]> serializer,
java.util.function.BiFunction<byte[],java.lang.Integer,? extends T> deserializer,
java.util.function.ToIntFunction<? super T> sizer)
Creates a new adapter that uses the given functions.
|
Modifier and Type | Method and Description |
---|---|
T |
deserialize(byte[] buffer,
int bufferPosition)
Deserializes data from a byte buffer, beginning at the given position.
|
int |
getSerializedSize(T value)
Gets the size of a byte array that would encode the given value.
|
byte[] |
serialize(T data)
Serializes the given data as a byte array.
|
cleanUp, getCurrentFile, getDataType, setCurrentFile
public DelegatedAdapter(DataType<T> dataType, java.util.function.Function<? super T,byte[]> serializer, java.util.function.BiFunction<byte[],java.lang.Integer,? extends T> deserializer, java.util.function.ToIntFunction<? super T> sizer)
dataType
- the type of the data to serialize/deserializeserializer
- the function to use to serialize data objects to raw bytesdeserializer
- the function to use to deserialize raw bytes to data objectssizer
- the function to use to determine the serialized sizes
of data objectspublic final T deserialize(byte[] buffer, int bufferPosition)
Deserializer
buffer
- the byte buffer to deserialize frombufferPosition
- the position in the buffer to start deserializing frompublic final int getSerializedSize(T value)
Deserializer
public final byte[] serialize(T data)
Serializer
data
- the object to serialize