Class ArrayOrMatrixWithUnitSerializer<U extends org.djunits.unit.Unit<U>,​T>

    • Constructor Detail

      • ArrayOrMatrixWithUnitSerializer

        public ArrayOrMatrixWithUnitSerializer​(byte type,
                                               String dataClassName,
                                               int numberOfDimensions)
        Construct a new serializer for Djunits arrays or matrices.
        Parameters:
        type - byte; the field type (returned by the fieldType method)
        dataClassName - String; returned by the dataClassName method
        numberOfDimensions - int; should be 1 for array serializer and 2 for matrix serializer
    • 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 the object 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 serialize
        buffer - byte[]; buffer for the serialized T
        pointer - Pointer; position in buffer where the first byte of the serialized T will be stored
        endianUtil - EndianUtil; 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: Serializer
        Return the number of dimensions of the stored data.
        Returns:
        int; 0 for plain data, 1 for array, 2 for matrix
      • encodeUnit

        protected void encodeUnit​(U unit,
                                  byte[] message,
                                  Pointer pointer,
                                  EndianUtil endianUtil)
        Code a unit, including MoneyUnits.
        Parameters:
        unit - U; the unit to code in the byte array
        message - byte[]; the byte array
        pointer - Pointer; the start pointer in the byte array
        endianUtil - EndianUtil; encoder to use for multi-byte values
      • getUnit

        protected U getUnit​(byte[] buffer,
                            Pointer pointer,
                            EndianUtil endianUtil)
        Retrieve and decode a DJUNITS unit.
        Parameters:
        buffer - byte[]; the encoded data
        pointer - Pointer; position in the encoded data where the unit is to be decoded from
        endianUtil - EndianUtil; decoder for multi-byte values
        Returns:
        Unit