Class ArrayOrMatrixSerializer<T,E>

java.lang.Object
org.djutils.serialization.serializers.BasicSerializer<T>
org.djutils.serialization.serializers.ArrayOrMatrixSerializer<T,E>
Type Parameters:
T - type; with [] or [][]
E - type without [] or [][]
All Implemented Interfaces:
Serializer<T>
Direct Known Subclasses:
ObjectArraySerializer, ObjectMatrixSerializer

public abstract class ArrayOrMatrixSerializer<T,E> extends BasicSerializer<T>
Serializer for arrays or matrices.
  • Constructor Details

    • ArrayOrMatrixSerializer

      ArrayOrMatrixSerializer(byte type, int elementSize, String dataClassName, int numberOfDimensions)
      Construct a new ArrayOrMatrixSerializere.
      Parameters:
      type - byte; the field type (returned by the fieldType method)
      elementSize - int; the number of bytes needed to encode one additional array, or matrix element
      dataClassName - String; returned by the dataClassName method
      numberOfDimensions - int; should be 1 for array serializer and 2 for matrix serializer
  • Method Details

    • getElementSize

      public final int getElementSize()
      Return the number of bytes needed to encode one additional element.
      Returns:
      int; the number of bytes needed to encode one additional element
    • getNumberOfDimensions

      public final int getNumberOfDimensions()
      Return the number of dimensions of the stored data.
      Returns:
      int; 1 for array, 2 for matrix
    • serializeElement

      public abstract void serializeElement(E object, byte[] buffer, int offset, EndianUtil endianUtil)
      Serializer for one array or matrix element (without type prefix) must be implemented in implementing sub classes.
      Parameters:
      object - E; the object to serialize
      buffer - byte[]; the byte buffer for the serialized object
      offset - int; index in byte buffer where first serialized byte must be stored
      endianUtil - EndianUtil; selects bigEndian or littleEndian encoding
    • deSerializeElement

      public abstract E deSerializeElement(byte[] buffer, int offset, EndianUtil endianUtil)
      Deserializer for one array or matrix element (without type prefix) must be implemented in implementing sub classes.
      Parameters:
      buffer - byte[]; the byte buffer from which the object is to be deserialized
      offset - int; index in byte buffer where first byte of the object is stored
      endianUtil - EndianUtil; selects bigEndian or littleEndian encoding
      Returns:
      E; the deserialized object