Class ObjectMatrixSerializer<E>
- java.lang.Object
-
- org.djutils.serialization.serializers.BasicSerializer<T>
-
- org.djutils.serialization.serializers.ArrayOrMatrixSerializer<E[][],E>
-
- org.djutils.serialization.serializers.ObjectMatrixSerializer<E>
-
- Type Parameters:
E
- class of the single (not matrix or vector) type
- All Implemented Interfaces:
Serializer<E[][]>
public abstract class ObjectMatrixSerializer<E> extends ArrayOrMatrixSerializer<E[][],E>
Serializer for simple matrix (non-jagged, non-empty, 2D array) classes.Copyright (c) 2019-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.- Version:
- $Revision$, $LastChangedDate$, by $Author$,
- Author:
- Alexander Verbraeck, Peter Knoppers
-
-
Constructor Summary
Constructors Constructor Description ObjectMatrixSerializer(byte type, int dataSize, Class<E> dataClass, String dataClassName)
Construct a new ObjectMatrixSerializer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description E[][]
deSerialize(byte[] buffer, Pointer pointer, EndianUtil endianUtil)
Deserialize an object of type T.void
serialize(E[][] matrix, byte[] buffer, Pointer pointer, EndianUtil endianUtil)
Serialize an object of type T; not including the prefix byte(s).void
serializeWithPrefix(E[][] matrix, byte[] buffer, Pointer pointer, EndianUtil endianUtil)
Serialize an object of type T including the prefix byte(s).int
size(E[][] matrix)
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(E[][] matrix)
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).-
Methods inherited from class org.djutils.serialization.serializers.ArrayOrMatrixSerializer
deSerializeElement, getElementSize, getNumberOfDimensions, serializeElement
-
Methods inherited from class org.djutils.serialization.serializers.BasicSerializer
dataClassName, fieldType, toString
-
-
-
-
Constructor Detail
-
ObjectMatrixSerializer
public ObjectMatrixSerializer(byte type, int dataSize, Class<E> dataClass, String dataClassName)
Construct a new ObjectMatrixSerializer.- Parameters:
type
- byte; the field type (returned by thefieldType
method)dataSize
- int; the number of bytes needed to encode one additional array elementdataClass
- Class<E>; class of the single object that needs to be serializeddataClassName
- String; returned by the dataClassName method
-
-
Method Detail
-
size
public final int size(E[][] matrix) throws SerializationException
Description copied from interface:Serializer
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:
matrix
- 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
public final int sizeWithPrefix(E[][] matrix) throws SerializationException
Description copied from interface:Serializer
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:
matrix
- 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
-
serializeWithPrefix
public final void serializeWithPrefix(E[][] matrix, byte[] buffer, Pointer pointer, EndianUtil endianUtil) throws SerializationException
Description copied from interface:Serializer
Serialize an object of type T including the prefix byte(s).- Parameters:
matrix
- 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
-
serialize
public final void serialize(E[][] matrix, byte[] buffer, Pointer pointer, EndianUtil endianUtil) throws SerializationException
Description copied from interface:Serializer
Serialize an object of type T; not including the prefix byte(s).- Parameters:
matrix
- 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
public final E[][] deSerialize(byte[] buffer, Pointer pointer, EndianUtil endianUtil)
Description copied from interface:Serializer
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
-
-