added ipv4 type
[lwes-java.git] / src / main / java / org / lwes / TypeID.java
blob61e0deebf9139b4a565eedb24e4888583857dd02
1 package org.lwes;
3 /**
4 * This class contains some global variables used in various parts of
5 * the event system.
7 * @author Anthony Molinaro
8 * @author Michael P. Lum
9 */
10 public class TypeID {
11 /**
12 * The token used for <tt>undefined</tt> types in LWES
14 public final static byte UNDEFINED_TOKEN = (byte) 0xff;
16 /**
17 * The token used by <tt>uint16</tt> in the Event Serialization Protocol
19 public final static byte UINT16_TOKEN = (byte) 0x01;
21 /**
22 * The token used by <tt>int16</tt> in the Event Serialization Protocol
24 public final static byte INT16_TOKEN = (byte) 0x02;
25 /**
26 * The token used by <tt>uint32</tt> in the Event Serialization Protocol
28 public final static byte UINT32_TOKEN = (byte) 0x03;
29 /**
30 * The token used by <tt>int32</tt> in the Event Serialization Protocol
32 public final static byte INT32_TOKEN = (byte) 0x04;
33 /**
34 * The token used by <tt>string</tt> in the Event Serialization Protocol
36 public final static byte STRING_TOKEN = (byte) 0x05;
37 /**
38 * The token used by <tt>ip_addr</tt> in the Event Serialization Protocol
40 public final static byte IPADDR_TOKEN = (byte) 0x06;
41 /**
42 * The token used by <tt>int64</tt> in the Event Serialization Protocol
44 public final static byte INT64_TOKEN = (byte) 0x07;
45 /**
46 * The token used by <tt>uint64</tt> in the Event Serialization Protocol
48 public final static byte UINT64_TOKEN = (byte) 0x08;
49 /**
50 * The token used by <tt>boolean</tt> in the Event Serialization Protocol
52 public final static byte BOOLEAN_TOKEN = (byte) 0x09;
54 public final static byte BYTE_TOKEN = (byte) 0x0A;
55 public final static byte FLOAT_TOKEN = (byte) 0x0B;
56 public final static byte DOUBLE_TOKEN = (byte) 0x0C;
57 public final static byte IPV4_TOKEN = (byte) 0x0D;
58 public final static byte EVENT_TOKEN = (byte) 0x0F;
60 /**
61 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
63 public final static byte UINT16_ARRAY_TOKEN = (byte) 0x81;
64 /**
65 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
67 public final static byte INT16_ARRAY_TOKEN = (byte) 0x82;
68 /**
69 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
71 public final static byte UINT32_ARRAY_TOKEN = (byte) 0x83;
72 /**
73 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
75 public final static byte INT32_ARRAY_TOKEN = (byte) 0x84;
77 /**
78 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
80 public final static byte STRING_ARRAY_TOKEN = (byte) 0x85;
82 /**
83 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
85 public final static byte IP_ADDR_ARRAY_TOKEN = (byte) 0x86;
87 /**
88 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
90 public final static byte INT64_ARRAY_TOKEN = (byte) 0x87;
92 /**
93 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
95 public final static byte UINT64_ARRAY_TOKEN = (byte) 0x88;
97 /**
98 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
100 public final static byte BOOLEAN_ARRAY_TOKEN = (byte) 0x89;
102 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
104 public final static byte BYTE_ARRAY_TOKEN = (byte) 0x8A;
106 public final static byte FLOAT_ARRAY_TOKEN = (byte) 0x8B;
107 public final static byte DOUBLE_ARRAY_TOKEN = (byte) 0x8C;
108 public final static byte IPV4_ARRAY_TOKEN = (byte) 0x8D;
109 public final static byte EVENT_ARRAY_TOKEN = (byte) 0x8E;
112 * The string used by <tt>uint16</tt> in the Event Serialization Protocol
114 public final static String UINT16_STRING = "uint16";
116 * The string used by <tt>int16</tt> in the Event Serialization Protocol
118 public final static String INT16_STRING = "int16";
120 * The string used by <tt>uint32</tt> in the Event Serialization Protocol
122 public final static String UINT32_STRING = "uint32";
124 * The string used by <tt>int32</tt> in the Event Serialization Protocol
126 public final static String INT32_STRING = "int32";
128 * The string used by <tt>string</tt> in the Event Serialization Protocol
130 public final static String STRING_STRING = "string";
132 * The string used by <tt>ip_addr</tt> in the Event Serialization Protocol
134 public final static String IPADDR_STRING = "ip_addr";
136 * The string used by <tt>int64</tt> in the Event Serialization Protocol
138 public final static String INT64_STRING = "int64";
140 * The string used by <tt>uint64</tt> in the Event Serialization Protocol
142 public final static String UINT64_STRING = "uint64";
144 * The string used by <tt>boolean</tt> in the Event Serialization Protocol
146 public final static String BOOLEAN_STRING = "boolean";
148 public final static String BYTE_STRING = "byte";
149 public final static String DOUBLE_STRING = "double";
150 public final static String FLOAT_STRING = "float";
151 public final static String IPV4_STRING = "ipv4";
153 public final static String STRING_ARRAY_STRING = "[Lstring";
154 public final static String UINT16_ARRAY_STRING = "[Luint16";
155 public final static String INT16_ARRAY_STRING = "[Lint16";
156 public final static String UINT32_ARRAY_STRING = "[Luint32";
157 public final static String INT32_ARRAY_STRING = "[Lint32";
158 public final static String UINT64_ARRAY_STRING = "[Luint64";
159 public final static String INT64_ARRAY_STRING = "[Lint64";
160 public final static String BOOLEAN_ARRAY_STRING = "[Lboolean";
161 public final static String BYTE_ARRAY_STRING = "[Lbyte";
162 public final static String DOUBLE_ARRAY_STRING = "[Ldouble";
163 public final static String FLOAT_ARRAY_STRING = "[Lfloat";
164 public final static String IPV4_ARRAY_STRING = "[Lipv4";
167 * This is a regular expression for parsing an integer number from a string
169 public final static String SIGNED_INTEGER_REGEX = "-?\\d+";
171 * This is a regular expression for parsing an unsigned integer number
172 * from a string
174 public final static String UNSIGNED_INTEGER_REGEX = "\\d+(?=\\s|$)";
176 * This is a regular expression for matching a hexidecimal short from a string
178 public final static String HEX_SHORT_REGEX = "0x[0-9a-fA-F]{1,4}(?=\\s|$)";
180 * This is a regular expression for matching a hexidecimal int from a string
182 public final static String HEX_INT_REGEX = "0x[0-9a-fA-F]{5,8}(?=\\s|$)";
184 * This is a regular expression for matching a hexidecimal long from a string
186 public final static String HEX_LONG_REGEX = "0x[0-9a-fA-F]{9,16}(?=\\s|$)";
188 * This is a regular expression for matching an ip address from a string
190 public final static String IP_ADDR_REGEX
192 "\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b";
194 * This is a regular expression for matching a boolean from a string
196 public final static String BOOLEAN_REGEX = "true|false";
199 * Simple conversion utility
201 * @param id The id token to translate
202 * @return String representation of this id
204 public static String byteIDToString(byte id) {
205 switch (id) {
206 case UINT16_TOKEN:
207 return UINT16_STRING;
208 case INT16_TOKEN:
209 return INT16_STRING;
210 case UINT32_TOKEN:
211 return UINT32_STRING;
212 case INT32_TOKEN:
213 return INT32_STRING;
214 case STRING_TOKEN:
215 return STRING_STRING;
216 case IPADDR_TOKEN:
217 return IPADDR_STRING;
218 case INT64_TOKEN:
219 return INT64_STRING;
220 case UINT64_TOKEN:
221 return UINT64_STRING;
222 case BOOLEAN_TOKEN:
223 return BOOLEAN_STRING;
224 case BYTE_TOKEN:
225 return BYTE_STRING;
226 case STRING_ARRAY_TOKEN:
227 return STRING_ARRAY_STRING;
228 case UINT16_ARRAY_TOKEN:
229 return UINT16_ARRAY_STRING;
230 case INT16_ARRAY_TOKEN:
231 return INT16_ARRAY_STRING;
232 case UINT32_ARRAY_TOKEN:
233 return UINT32_ARRAY_STRING;
234 case INT32_ARRAY_TOKEN:
235 return INT32_ARRAY_STRING;
236 case UINT64_ARRAY_TOKEN:
237 return UINT64_ARRAY_STRING;
238 case INT64_ARRAY_TOKEN:
239 return INT64_ARRAY_STRING;
240 case BOOLEAN_ARRAY_TOKEN:
241 return BOOLEAN_ARRAY_STRING;
242 case BYTE_ARRAY_TOKEN:
243 return BYTE_ARRAY_STRING;
244 default:
245 return null;
250 * Another conversion utility
252 * @param id String representation of the type id
253 * @return byte token representation of the type id
255 public static byte stringToByteID(String id) {
256 if (id.equals(UINT16_STRING)) {
257 return UINT16_TOKEN;
259 else if (id.equals(INT16_STRING)) {
260 return INT16_TOKEN;
262 else if (id.equals(UINT32_STRING)) {
263 return UINT32_TOKEN;
265 else if (id.equals(INT32_STRING)) {
266 return INT32_TOKEN;
268 else if (id.equals(STRING_STRING)) {
269 return STRING_TOKEN;
271 else if (id.equals(IPADDR_STRING)) {
272 return IPADDR_TOKEN;
274 else if (id.equals(INT64_STRING)) {
275 return INT64_TOKEN;
277 else if (id.equals(UINT64_STRING)) {
278 return UINT64_TOKEN;
280 else if (id.equals(BOOLEAN_STRING)) {
281 return BOOLEAN_TOKEN;
283 else if (id.equals(BYTE_STRING)) {
284 return BYTE_TOKEN;
286 else if (id.equals(STRING_ARRAY_STRING)) {
287 return STRING_ARRAY_TOKEN;
289 else if (id.equals(UINT16_ARRAY_STRING)) {
290 return UINT16_ARRAY_TOKEN;
292 else if (id.equals(INT16_ARRAY_STRING)) {
293 return INT16_ARRAY_TOKEN;
295 else if (id.equals(UINT32_ARRAY_STRING)) {
296 return UINT32_ARRAY_TOKEN;
298 else if (id.equals(INT32_ARRAY_STRING)) {
299 return INT32_ARRAY_TOKEN;
301 else if (id.equals(STRING_ARRAY_STRING)) {
302 return STRING_ARRAY_TOKEN;
304 else if (id.equals(INT64_ARRAY_STRING)) {
305 return INT64_ARRAY_TOKEN;
307 else if (id.equals(UINT64_ARRAY_STRING)) {
308 return UINT64_ARRAY_TOKEN;
310 else if (id.equals(BOOLEAN_ARRAY_STRING)) {
311 return BOOLEAN_ARRAY_TOKEN;
313 else if (id.equals(BYTE_ARRAY_STRING)) {
314 return BYTE_ARRAY_TOKEN;
316 else {
317 return UNDEFINED_TOKEN;