View Javadoc
1   package org.djutils.serialization.serializers;
2   
3   /**
4    * Basics of the serializer
5    * <p>
6    * Copyright (c) 2019-2022 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    * @version $Revision$, $LastChangedDate$, by $Author$, <br>
10   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
11   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
12   * @param <T> class
13   */
14  public abstract class BasicSerializer<T extends Object> implements Serializer<T>
15  {
16      /** The field type that usually prefixes the serialized data. */
17      private final byte type;
18  
19      /** String returned by the dataClassName method. */
20      private final String dataClassName;
21  
22      /**
23       * Construct the BasicSerializer.
24       * @param type byte; the field type (returned by the <code>fieldType</code> method)
25       * @param dataClassName String; returned by the dataClassName method
26       */
27      public BasicSerializer(final byte type, final String dataClassName)
28      {
29          this.type = type;
30          this.dataClassName = dataClassName;
31      }
32  
33      /** {@inheritDoc} */
34      @Override
35      public final byte fieldType()
36      {
37          return this.type;
38      }
39  
40      /** {@inheritDoc} */
41      @Override
42      public final String dataClassName()
43      {
44          return this.dataClassName;
45      }
46  
47      /** {@inheritDoc} */
48      @Override
49      public String toString()
50      {
51          return "BasicSerializer [type=" + this.type + ", dataClassName=" + this.dataClassName + "]";
52      }
53  
54  }