U
- the unit typeT
- The object type to (de)serializepublic abstract class ArrayOrMatrixWithUnitSerializer<U extends org.djunits.unit.Unit<U>,T> extends BasicSerializer<T>
Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
Constructor and Description |
---|
ArrayOrMatrixWithUnitSerializer(byte type,
String dataClassName,
int numberOfDimensions)
Construct a new serializer for Djunits arrays or matrices.
|
Modifier and Type | Method and Description |
---|---|
protected void |
encodeUnit(U unit,
byte[] message,
Pointer pointer,
EndianUtil endianUtil)
Code a unit, including MoneyUnits.
|
int |
getNumberOfDimensions()
Return the number of dimensions of the stored data.
|
protected U |
getUnit(byte[] buffer,
Pointer pointer,
EndianUtil endianUtil)
Retrieve and decode a DJUNITS unit.
|
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).
|
dataClassName, fieldType, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
deSerialize, serialize, size
public ArrayOrMatrixWithUnitSerializer(byte type, String dataClassName, int numberOfDimensions)
type
- byte; the field type (returned by the fieldType
method)dataClassName
- String; returned by the dataClassName methodnumberOfDimensions
- int; should be 1 for array serializer and 2 for matrix serializerpublic final int sizeWithPrefix(T object) throws SerializationException
Serializer
object
- T; Instance of the objectSerializationException
- when the object
cannot be serializedpublic final void serializeWithPrefix(T object, byte[] buffer, Pointer pointer, EndianUtil endianUtil) throws SerializationException
Serializer
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 encodingSerializationException
- when a matrix has size zero or is jaggedpublic final int getNumberOfDimensions()
Serializer
protected void encodeUnit(U unit, byte[] message, Pointer pointer, EndianUtil endianUtil)
unit
- the unit to code in the byte arraymessage
- the byte arraypointer
- the start pointer in the byte arrayendianUtil
- EndianUtil; encoder to use for multi-byte valuesprotected U getUnit(byte[] buffer, Pointer pointer, EndianUtil endianUtil)
buffer
- byte[]; the encoded datapointer
- Pointer; position in the encoded data where the unit is to be decoded fromendianUtil
- EndianUtil; decoder for multi-byte valuesCopyright © 2018–2019 Delft University of Technology. All rights reserved.