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
17
18 public abstract class BasicPrimitiveArrayOrMatrixSerializer<T extends Object> extends BasicSerializer<T>
19 {
20
21 private final int elementSize;
22
23
24 private final int numberOfDimensions;
25
26
27
28
29
30
31
32
33 public BasicPrimitiveArrayOrMatrixSerializer(final byte type, final int elementSize, final String dataClassName,
34 final int numberOfDimensions)
35 {
36 super(type, dataClassName);
37 this.elementSize = elementSize;
38 this.numberOfDimensions = numberOfDimensions;
39 }
40
41 @Override
42 public final int sizeWithPrefix(final T object) throws SerializationException
43 {
44 return 1 + size(object);
45 }
46
47 @Override
48 public final void serializeWithPrefix(final T object, final byte[] buffer, final Pointer pointer,
49 final EndianUtil endianUtil) throws SerializationException
50 {
51 buffer[pointer.getAndIncrement(1)] = fieldType();
52 serialize(object, buffer, pointer, endianUtil);
53 }
54
55
56
57
58
59 public final int getElementSize()
60 {
61 return this.elementSize;
62 }
63
64 @Override
65 public final int getNumberOfDimensions()
66 {
67 return this.numberOfDimensions;
68 }
69
70 }