Class DoubleVectorSerializer<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>>

Type Parameters:
U - the unit type
S - the scalar type
V - the vector type
All Implemented Interfaces:
Serializer<V>

public class DoubleVectorSerializer<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>> extends ArrayOrMatrixWithUnitSerializer<U,V>
(De)serializes a DJUNITS DoubleVector.

Copyright (c) 2019-2025 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 Details

    • DoubleVectorSerializer

      public DoubleVectorSerializer()
  • Method Details

    • size

      public int size(V adv)
      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:
      adv - Instance of the object
      Returns:
      the number of bytes needed to serialize an object of type T
    • getElementSize

      public int getElementSize()
      Description copied from class: ArrayOrMatrixWithUnitSerializer
      Return the size of an element in the djunits vector or array.
      Specified by:
      getElementSize in class ArrayOrMatrixWithUnitSerializer<U extends org.djunits.unit.Unit<U>,V extends org.djunits.value.vdouble.vector.base.DoubleVector<U,S,V>>
      Returns:
      the size of one element in number of bytes
    • serialize

      public void serialize(V adv, 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:
      adv - the object to serialize
      buffer - buffer for the serialized T
      pointer - position in buffer where the first byte of the serialized T will be stored
      endianUtil - selects bigEndian or littleEndian encoding
      Throws:
      SerializationException - when a matrix has size zero or is jagged
    • deSerialize

      public V deSerialize(byte[] buffer, Pointer pointer, EndianUtil endianUtil) throws SerializationException
      Description copied from interface: Serializer
      Deserialize an object of type T. The pointer should be on the first byte of the object; i.e. just after the prefix byte.
      Parameters:
      buffer - the bytes with serialized data that must be reconstructed into a T
      pointer - position in the buffer where the first byte of the serialized T is located
      endianUtil - selects bigEndian or littleEndian encoding
      Returns:
      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, S>, V extends org.djunits.value.vdouble.vector.base.DoubleVector<U, S, V>> V instantiateAnonymous(org.djunits.value.vdouble.vector.data.DoubleVectorData data, org.djunits.unit.Unit<?> unit)
      Instantiate the DoubleVector 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 type
      S - the scalar type
      V - the vector type
      Parameters:
      data - the values
      unit - the unit in which the value is expressed
      Returns:
      an instantiated DoubleVector with the provided displayUunit