Class ArrayOrMatrixWithUnitSerializer<U extends Unit<U>,T>
java.lang.Object
org.djutils.serialization.serializers.BasicSerializer<T>
org.djutils.serialization.serializers.ArrayOrMatrixWithUnitSerializer<U,T>
- Type Parameters:
U- the unit typeT- The object type to (de)serialize
- All Implemented Interfaces:
Serializer<T>
- Direct Known Subclasses:
DoubleMatrixSerializer,DoubleVectorSerializer,FloatMatrixSerializer,FloatVectorSerializer
public abstract class ArrayOrMatrixWithUnitSerializer<U extends Unit<U>,T>
extends BasicSerializer<T>
Serializer for Djunits arrays and matrices.
Copyright (c) 2019-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.
- Author:
- Alexander Verbraeck, Peter Knoppers
-
Constructor Summary
ConstructorsConstructorDescriptionArrayOrMatrixWithUnitSerializer(byte type, String dataClassName, int numberOfDimensions) Construct a new serializer for Djunits arrays or matrices. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidencodeUnit(U unit, byte[] message, Pointer pointer, Endianness endianness) Code a unit.abstract intReturn the size of an element in the djunits vector or array.final intReturn the number of dimensions of the stored data.protected UgetUnit(byte[] buffer, Pointer pointer, Endianness endianness) Retrieve and decode a DJUNITS unit.booleanhasUnit()Return whether the serializer uses a single unit type or not.final voidserializeWithPrefix(T object, byte[] buffer, Pointer pointer, Endianness endianness) Serialize an object of type T including the prefix byte(s).final intsizeWithPrefix(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).Methods inherited from class org.djutils.serialization.serializers.BasicSerializer
dataClassName, fieldType, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.serialization.serializers.Serializer
deSerialize, serialize, size
-
Constructor Details
-
ArrayOrMatrixWithUnitSerializer
Construct a new serializer for Djunits arrays or matrices.- Parameters:
type- the field type (returned by thefieldTypemethod)dataClassName- returned by the dataClassName methodnumberOfDimensions- should be 1 for array serializer and 2 for matrix serializer
-
-
Method Details
-
sizeWithPrefix
Description copied from interface:SerializerCompute 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- Instance of the object- Returns:
- the number of bytes needed to serialize an object of type T
- Throws:
SerializationException- when theobjectcannot be serialized
-
serializeWithPrefix
public final void serializeWithPrefix(T object, byte[] buffer, Pointer pointer, Endianness endianness) throws SerializationException Description copied from interface:SerializerSerialize an object of type T including the prefix byte(s).- Parameters:
object- the object to serializebuffer- buffer for the serialized Tpointer- position in buffer where the first byte of the serialized T will be storedendianness- selects bigEndian or littleEndian encoding- Throws:
SerializationException- when a matrix has size zero or is jagged
-
getNumberOfDimensions
public final int getNumberOfDimensions()Description copied from interface:SerializerReturn the number of dimensions of the stored data.- Returns:
- 0 for plain data, 1 for array, 2 for matrix
-
getElementSize
public abstract int getElementSize()Return the size of an element in the djunits vector or array.- Returns:
- the size of one element in number of bytes
-
hasUnit
public boolean hasUnit()Description copied from interface:SerializerReturn whether the serializer uses a single unit type or not.- Returns:
- whether the serializer uses a single unit type or not
-
encodeUnit
Code a unit.- Parameters:
unit- the unit to code in the byte arraymessage- the byte arraypointer- the start pointer in the byte arrayendianness- encoder to use for multi-byte values
-
getUnit
Retrieve and decode a DJUNITS unit.- Parameters:
buffer- the encoded datapointer- position in the encoded data where the unit is to be decoded fromendianness- decoder for multi-byte values- Returns:
- Unit
-