Interface Serializer<T>
- Type Parameters:
T
- Type of object that can be serialized and deserialized
- All Known Implementing Classes:
ArrayOrMatrixSerializer
,ArrayOrMatrixWithUnitSerializer
,BasicPrimitiveArrayOrMatrixSerializer
,BasicSerializer
,DoubleMatrixSerializer
,DoubleScalarSerializer
,DoubleVectorArraySerializer
,DoubleVectorSerializer
,FixedSizeObjectSerializer
,FloatMatrixSerializer
,FloatScalarSerializer
,FloatVectorSerializer
,ObjectArraySerializer
,ObjectMatrixSerializer
,ObjectSerializer
,ObjectWithUnitSerializer
public interface Serializer<T>
Interface to serialize and deserialize data.
Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.
version Jun 07, 2019
- Author:
- Alexander Verbraeck, Peter Knoppers
-
Method Summary
Modifier and TypeMethodDescriptionReturn a description of the type of data that this serializer handles.deSerialize
(byte[] buffer, Pointer pointer, EndianUtil endianUtil) Deserialize an object of type T.byte
Return the byte representation of the field type.int
Return the number of dimensions of the stored data.void
serialize
(T object, byte[] buffer, Pointer pointer, EndianUtil endianUtil) Serialize an object of type T; not including the prefix byte(s).void
serializeWithPrefix
(T object, byte[] buffer, Pointer pointer, EndianUtil endianUtil) Serialize an object of type T including the prefix byte(s).int
Compute the number of bytes needed to serialize an object of type T (excluding the byte(s) that indicate that an object of type T is next in the data stream).int
sizeWithPrefix
(T object) Compute the number of bytes needed to serialize an object of type T (including the byte(s) that indicate that an object of type T is next in the data stream).
-
Method Details
-
size
Compute the number of bytes needed to serialize an object of type T (excluding the byte(s) that indicate that an object of type T is next in the data stream).- Parameters:
object
- T; Instance of the object- Returns:
- int; the number of bytes needed to serialize an object of type T
- Throws:
SerializationException
- when theobject
cannot be serialized
-
sizeWithPrefix
Compute the number of bytes needed to serialize an object of type T (including the byte(s) that indicate that an object of type T is next in the data stream).- Parameters:
object
- T; Instance of the object- Returns:
- int; the number of bytes needed to serialize an object of type T
- Throws:
SerializationException
- when theobject
cannot be serialized
-
fieldType
byte fieldType()Return the byte representation of the field type.- Returns:
- byte
-
serialize
void serialize(T object, byte[] buffer, Pointer pointer, EndianUtil endianUtil) throws SerializationException Serialize an object of type T; not including the prefix byte(s).- Parameters:
object
- T; the object to serializebuffer
- byte[]; buffer for the serialized Tpointer
- Pointer; position in buffer where the first byte of the serialized T will be storedendianUtil
- EndianUtil; selects bigEndian or littleEndian encoding- Throws:
SerializationException
- when a matrix has size zero or is jagged
-
serializeWithPrefix
void serializeWithPrefix(T object, byte[] buffer, Pointer pointer, EndianUtil endianUtil) throws SerializationException Serialize an object of type T including the prefix byte(s).- Parameters:
object
- T; the object to serializebuffer
- byte[]; buffer for the serialized Tpointer
- Pointer; position in buffer where the first byte of the serialized T will be storedendianUtil
- EndianUtil; selects bigEndian or littleEndian encoding- Throws:
SerializationException
- when a matrix has size zero or is jagged
-
deSerialize
Deserialize an object of type T. Thepointer
should be on the first byte of the object; i.e. just after the prefix byte.- Parameters:
buffer
- byte[]; the bytes with serialized data that must be reconstructed into a Tpointer
- Pointer; position in the buffer where the first byte of the serialized T is locatedendianUtil
- EndianUtil; selects bigEndian or littleEndian encoding- Returns:
- T; a T object constructed from the data in the buffer
- Throws:
SerializationException
- when the input data cannot be deserialized
-
dataClassName
String dataClassName()Return a description of the type of data that this serializer handles. The result of this method should not be subject to localization because it is used in the SerialDataDecoder to identify the type of a serializer.- Returns:
- String; description of the type of data that this serializer handles
-
getNumberOfDimensions
int getNumberOfDimensions()Return the number of dimensions of the stored data.- Returns:
- int; 0 for plain data, 1 for array, 2 for matrix
-