Class DoubleMatrixSerializer<U extends org.djunits.unit.Unit<U>,S extends org.djunits.value.vdouble.scalar.base.DoubleScalar<U,S>,V extends org.djunits.value.vdouble.vector.base.DoubleVector<U,S,V>,M extends org.djunits.value.vdouble.matrix.base.DoubleMatrix<U,S,V,M>>
java.lang.Object
org.djutils.serialization.serializers.BasicSerializer<T>
org.djutils.serialization.serializers.ArrayOrMatrixWithUnitSerializer<U,M>
org.djutils.serialization.serializers.DoubleMatrixSerializer<U,S,V,M>
- Type Parameters:
U
- the unit typeS
- the scalar typeV
- the vector typeM
- the matrix type
- All Implemented Interfaces:
Serializer<M>
public class DoubleMatrixSerializer<U extends org.djunits.unit.Unit<U>,S extends org.djunits.value.vdouble.scalar.base.DoubleScalar<U,S>,V extends org.djunits.value.vdouble.vector.base.DoubleVector<U,S,V>,M extends org.djunits.value.vdouble.matrix.base.DoubleMatrix<U,S,V,M>>
extends ArrayOrMatrixWithUnitSerializer<U,M>
(De)serializes a DJUNITS DoubleMatrix.
Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.
- Author:
- Alexander Verbraeck
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondeSerialize
(byte[] buffer, Pointer pointer, EndianUtil endianUtil) Deserialize an object of type T.static <U extends org.djunits.unit.Unit<U>,
S extends org.djunits.value.vdouble.scalar.base.DoubleScalar<U, S>, V extends org.djunits.value.vdouble.vector.base.DoubleVector<U, S, V>, M extends org.djunits.value.vdouble.matrix.base.DoubleMatrix<U, S, V, M>>
MinstantiateAnonymous
(org.djunits.value.vdouble.matrix.data.DoubleMatrixData data, org.djunits.unit.Unit<?> unit) Instantiate the DoubleMatrix based on its unit.void
serialize
(M adm, byte[] buffer, Pointer pointer, EndianUtil endianUtil) Serialize an object of type T; not 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).Methods inherited from class org.djutils.serialization.serializers.ArrayOrMatrixWithUnitSerializer
encodeUnit, getNumberOfDimensions, getUnit, serializeWithPrefix, sizeWithPrefix
Methods inherited from class org.djutils.serialization.serializers.BasicSerializer
dataClassName, fieldType, toString
-
Constructor Details
-
DoubleMatrixSerializer
public DoubleMatrixSerializer()
-
-
Method Details
-
size
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:
adm
- 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
-
serialize
public void serialize(M adm, 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:
adm
- 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 M deSerialize(byte[] buffer, Pointer pointer, EndianUtil endianUtil) throws SerializationException 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
- Throws:
SerializationException
- when the input data cannot be deserialized
-
instantiateAnonymous
public static <U extends org.djunits.unit.Unit<U>,S extends org.djunits.value.vdouble.scalar.base.DoubleScalar<U, M instantiateAnonymousS>, V extends org.djunits.value.vdouble.vector.base.DoubleVector<U, S, V>, M extends org.djunits.value.vdouble.matrix.base.DoubleMatrix<U, S, V, M>> (org.djunits.value.vdouble.matrix.data.DoubleMatrixData data, org.djunits.unit.Unit<?> unit) Instantiate the DoubleMatrix based on its unit. Loose check for types on the compiler. This allows the unit to be specified as a Unit<?> type.
Note that it is possible to make mistakes with anonymous units.- Type Parameters:
U
- the unit typeS
- the scalar typeV
- the vector typeM
- the matrix type- Parameters:
data
- DoubleMatrixData; the valuesunit
- Unit<?>; the unit in which the value is expressed- Returns:
- M; an instantiated DoubleMatrix with the provided displayUunit
-