View Javadoc
1   package org.djutils.serialization.serializers;
2   
3   /**
4    * Serializer for simple, fixed size, classes.
5    * <p>
6    * Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
7    * BSD-style license. See <a href="https://djutils.org/docs/current/djutils/licenses.html">DJUTILS License</a>.
8    * </p>
9    * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
10   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
11   * @param <T> class
12   */
13  public abstract class FixedSizeObjectSerializer<T extends Object> extends ObjectSerializer<T>
14  {
15      /** Size of the encoded data. */
16      private final int dataSize;
17  
18      /**
19       * Construct the FixedSizeSerializer.
20       * @param fieldType byte; the field type (returned by the <code>fieldType</code> method)
21       * @param serializedDataSize int; number of bytes required for serialized T
22       * @param dataClassName String; returned by the dataClassName method
23       */
24      public FixedSizeObjectSerializer(final byte fieldType, final int serializedDataSize, final String dataClassName)
25      {
26          super(fieldType, dataClassName);
27          this.dataSize = serializedDataSize;
28      }
29  
30      @Override
31      public final int size(final Object object)
32      {
33          return this.dataSize;
34      }
35  
36  }