Class ObjectSerializer<T>

java.lang.Object
org.djutils.serialization.serializers.BasicSerializer<T>
org.djutils.serialization.serializers.ObjectSerializer<T>
Type Parameters:
T - class
All Implemented Interfaces:
Serializer<T>
Direct Known Subclasses:
FixedSizeObjectSerializer, ObjectWithUnitSerializer

public abstract class ObjectSerializer<T> extends BasicSerializer<T>
Serializer for simple 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

    • ObjectSerializer

      public ObjectSerializer(byte type, String dataClassName)
      Construct a new ObjectSerializer.
      Parameters:
      type - byte; the field type (returned by the fieldType method)
      dataClassName - String; returned by the dataClassName method
  • Method Details

    • 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