1 package org.djutils.serialization.serializers;
2
3 import org.djutils.serialization.EndianUtil;
4 import org.djutils.serialization.SerializationException;
5
6
7
8
9
10
11
12
13
14
15
16 public abstract class BasicPrimitiveArrayOrMatrixSerializer<T extends Object> extends BasicSerializer<T>
17 {
18
19 private final int elementSize;
20
21
22 private final int numberOfDimensions;
23
24
25
26
27
28
29
30
31 public BasicPrimitiveArrayOrMatrixSerializer(final byte type, final int elementSize, final String dataClassName,
32 final int numberOfDimensions)
33 {
34 super(type, dataClassName);
35 this.elementSize = elementSize;
36 this.numberOfDimensions = numberOfDimensions;
37 }
38
39 @Override
40 public final int sizeWithPrefix(final T object) throws SerializationException
41 {
42 return 1 + size(object);
43 }
44
45 @Override
46 public final void serializeWithPrefix(final T object, final byte[] buffer, final Pointer pointer,
47 final EndianUtil endianUtil) throws SerializationException
48 {
49 buffer[pointer.getAndIncrement(1)] = fieldType();
50 serialize(object, buffer, pointer, endianUtil);
51 }
52
53
54
55
56
57 public final int getElementSize()
58 {
59 return this.elementSize;
60 }
61
62 @Override
63 public final int getNumberOfDimensions()
64 {
65 return this.numberOfDimensions;
66 }
67
68 }