Class ObjectArraySerializer<E>

Type Parameters:
E - class of the element object
All Implemented Interfaces:
Serializer<E[]>

public abstract class ObjectArraySerializer<E> extends ArrayOrMatrixSerializer<E[],E>
Serializer for Object array classes.

Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.

Author:
Alexander Verbraeck, Peter Knoppers
  • Constructor Details

    • ObjectArraySerializer

      public ObjectArraySerializer(byte type, int dataSize, E sample, String dataClassName)
      Construct a new ObjectArraySerializer.
      Parameters:
      type - byte; the field type (returned by the fieldType method)
      dataSize - int; the number of bytes needed to encode one additional array element
      sample - E; sample object (can be zero length array).
      dataClassName - String; returned by the dataClassName method
  • Method Details

    • size

      public final int size(E[] array)
      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:
      array - T; Instance of the object
      Returns:
      int; the number of bytes needed to serialize an object of type T
    • sizeWithPrefix

      public final int sizeWithPrefix(E[] array)
      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:
      array - T; Instance of the object
      Returns:
      int; the number of bytes needed to serialize an object of type T
    • serializeWithPrefix

      public final void serializeWithPrefix(E[] array, 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:
      array - 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
    • serialize

      public final void serialize(E[] array, byte[] buffer, Pointer pointer, EndianUtil endianUtil)
      Description copied from interface: Serializer
      Serialize an object of type T; not including the prefix byte(s).
      Parameters:
      array - 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
    • deSerialize

      public final E[] deSerialize(byte[] buffer, Pointer pointer, EndianUtil endianUtil)
      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 - byte[]; the bytes with serialized data that must be reconstructed into a T
      pointer - Pointer; position in the buffer where the first byte of the serialized T is located
      endianUtil - EndianUtil; selects bigEndian or littleEndian encoding
      Returns:
      T; a T object constructed from the data in the buffer