1 package org.opentrafficsim.imb;
2
3 import nl.tno.imb.TByteBuffer;
4
5
6
7
8
9
10
11
12
13
14
15
16 public class ObjectArrayToIMB
17 {
18
19
20
21
22 private ObjectArrayToIMB()
23 {
24
25 }
26
27
28
29
30
31
32
33 public static TByteBuffer objectArrayToIMBPayload(final Object[] data) throws IMBException
34 {
35 TByteBuffer payload = new TByteBuffer();
36 for (Object o : data)
37 {
38 switch (o.getClass().getName())
39 {
40 case "java.lang.String":
41 payload.prepare((String) o);
42 break;
43
44 case "java.lang.Integer":
45 payload.prepare((Integer) o);
46 break;
47
48 case "java.lang.Long":
49 payload.prepare((Long) o);
50 break;
51
52 case "java.lang.Double":
53 payload.prepare((Double) o);
54 break;
55
56 case "java.lang.Float":
57 payload.prepare((Float) o);
58 break;
59
60 case "java.lang.Byte":
61 payload.prepare((Byte) o);
62 break;
63
64 case "java.lang.Character":
65 payload.prepare((Character) o);
66 break;
67
68 case "java.lang.Boolean":
69 payload.prepare((Boolean) o);
70 break;
71
72 default:
73 if (o instanceof SelfWrapper)
74 {
75 ((SelfWrapper) o).prepare(payload);
76 }
77 else
78 {
79 throw new IMBException("don't know how to prepare " + o.getClass().getName());
80 }
81 break;
82 }
83 }
84 payload.prepareApply();
85 for (Object o : data)
86 {
87 switch (o.getClass().getName())
88 {
89 case "java.lang.String":
90 payload.qWrite((String) o);
91 break;
92
93 case "java.lang.Integer":
94 payload.qWrite((Integer) o);
95 break;
96
97 case "java.lang.Long":
98 payload.qWrite((Long) o);
99 break;
100
101 case "java.lang.Double":
102 payload.qWrite((Double) o);
103 break;
104
105 case "java.lang.Float":
106 payload.qWrite((Float) o);
107 break;
108
109 case "java.lang.Byte":
110 payload.qWrite((Byte) o);
111 break;
112
113 case "java.lang.Character":
114 payload.qWrite((Character) o);
115 break;
116
117 case "java.lang.Boolean":
118 payload.qWrite((Boolean) o);
119 break;
120
121 default:
122 if (o instanceof SelfWrapper)
123 {
124 ((SelfWrapper) o).qWrite(payload);
125 }
126 else
127 {
128
129 throw new IMBException("don't know how to qWrite " + o.getClass().getName());
130 }
131 break;
132 }
133 }
134 return payload;
135 }
136
137 }