View Javadoc
1   package org.opentrafficsim.sim0mq.publisher;
2   
3   import org.djutils.event.Event;
4   import org.djutils.event.EventType;
5   import org.djutils.exceptions.Throw;
6   import org.djutils.metadata.MetaData;
7   import org.djutils.serialization.EndianUtil;
8   import org.djutils.serialization.SerializationException;
9   import org.djutils.serialization.serializers.Pointer;
10  import org.djutils.serialization.serializers.Serializer;
11  
12  /**
13   * Convert one Event into an equivalent Sim0MQ Message, or back.
14   * <p>
15   * Copyright (c) 2020-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
17   * </p>
18   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
20   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
21   * @param <E> event type
22   */
23  public class EventSerializer<E extends Event> implements Serializer<Event>
24  {
25      /** The type of event that this EventSerializer handles. */
26      private final EventType eventType;
27  
28      /**
29       * Construct a new EventSerializer for the specified <code>EventType</code>.
30       * @param eventType EventType; the event type
31       */
32      EventSerializer(final EventType eventType)
33      {
34          this.eventType = eventType;
35      }
36  
37      /** {@inheritDoc} */
38      @Override
39      public int size(final Event event) throws SerializationException
40      {
41          EventType et = event.getType();
42          Throw.when(et.equals(this.eventType), ClassCastException.class,
43                  "EventSerializer for " + this.eventType.getName() + " cannot handle event " + event);
44          int result = et.getName().length();
45          MetaData metaData = this.eventType.getMetaData();
46          for (int index = 0; index < metaData.size(); index++)
47          {
48              // TODO: There has to be sme content here?
49          }
50          return result;
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55      public int sizeWithPrefix(final Event event) throws SerializationException
56      {
57          return 1 + size(event);
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public byte fieldType()
63      {
64          return 33;
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public void serialize(final Event object, final byte[] buffer, final Pointer pointer, final EndianUtil endianUtil)
70              throws SerializationException
71      {
72          // TODO Auto-generated method stub
73  
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public void serializeWithPrefix(final Event object, final byte[] buffer, final Pointer pointer, final EndianUtil endianUtil)
79              throws SerializationException
80      {
81          // TODO Auto-generated method stub
82  
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public Event deSerialize(final byte[] buffer, final Pointer pointer, final EndianUtil endianUtil)
88              throws SerializationException
89      {
90          // TODO Auto-generated method stub
91          return null;
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public String dataClassName()
97      {
98          // TODO Auto-generated method stub
99          return null;
100     }
101 
102     /** {@inheritDoc} */
103     @Override
104     public final int getNumberOfDimensions()
105     {
106         return 0;
107     }
108 
109 }