Class BasicPrimitiveArrayOrMatrixSerializer<T>
- java.lang.Object
-
- org.djutils.serialization.serializers.BasicSerializer<T>
-
- org.djutils.serialization.serializers.BasicPrimitiveArrayOrMatrixSerializer<T>
-
- Type Parameters:
T
- array type, e.g. int[]
- All Implemented Interfaces:
Serializer<T>
public abstract class BasicPrimitiveArrayOrMatrixSerializer<T> extends BasicSerializer<T>
Serializer for primitive data array classes. *Copyright (c) 2019-2023 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 BasicPrimitiveArrayOrMatrixSerializer(byte type, int elementSize, String dataClassName, int numberOfDimensions)
Construct a new BasicPrimitiveArrayOrMatrixSerializer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getElementSize()
Retrieve the number of bytes needed to encode one additional array element.int
getNumberOfDimensions()
Return the number of dimensions of the stored data.void
serializeWithPrefix(T object, byte[] buffer, Pointer pointer, EndianUtil endianUtil)
Serialize an object of type T including the prefix byte(s).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).-
Methods inherited from class org.djutils.serialization.serializers.BasicSerializer
dataClassName, fieldType, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.serialization.serializers.Serializer
deSerialize, serialize, size
-
-
-
-
Constructor Detail
-
BasicPrimitiveArrayOrMatrixSerializer
public BasicPrimitiveArrayOrMatrixSerializer(byte type, int elementSize, String dataClassName, int numberOfDimensions)
Construct a new BasicPrimitiveArrayOrMatrixSerializer.- Parameters:
type
- byte; the field type (returned by thefieldType
method)elementSize
- int; the number of bytes needed to encode one additional array elementdataClassName
- String; returned by the dataClassName methodnumberOfDimensions
- int; number of dimensions (1 for array, 2 for matrix)
-
-
Method Detail
-
sizeWithPrefix
public final int sizeWithPrefix(T object) 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:
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
-
serializeWithPrefix
public final void serializeWithPrefix(T object, 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:
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
-
getElementSize
public final int getElementSize()
Retrieve the number of bytes needed to encode one additional array element.- Returns:
- int; the number of bytes needed to encode one additional array element
-
getNumberOfDimensions
public final int getNumberOfDimensions()
Description copied from interface:Serializer
Return the number of dimensions of the stored data.- Returns:
- int; 0 for plain data, 1 for array, 2 for matrix
-
-