removed a debug
[lwes-java.git] / src / main / java / org / lwes / TypeID.java
blob053e76f85aea4d96e1196217ec353f8747a15f45
1 /*======================================================================*
2 * Copyright (c) 2008, Yahoo! Inc. All rights reserved. *
3 * *
4 * Licensed under the New BSD License (the "License"); you may not use *
5 * this file except in compliance with the License. Unless required *
6 * by applicable law or agreed to in writing, software distributed *
7 * under the License is distributed on an "AS IS" BASIS, WITHOUT *
8 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
9 * See the License for the specific language governing permissions and *
10 * limitations under the License. See accompanying LICENSE file. *
11 *======================================================================*/
13 package org.lwes;
15 /**
16 * This class contains some global variables used in various parts of
17 * the event system.
19 * @author Anthony Molinaro
20 * @author Michael P. Lum
22 public class TypeID {
23 /**
24 * The token used for <tt>undefined</tt> types in LWES
26 public final static byte UNDEFINED_TOKEN = (byte) 0xff;
28 /**
29 * The token used by <tt>uint16</tt> in the Event Serialization Protocol
31 public final static byte UINT16_TOKEN = (byte) 0x01;
33 /**
34 * The token used by <tt>int16</tt> in the Event Serialization Protocol
36 public final static byte INT16_TOKEN = (byte) 0x02;
37 /**
38 * The token used by <tt>uint32</tt> in the Event Serialization Protocol
40 public final static byte UINT32_TOKEN = (byte) 0x03;
41 /**
42 * The token used by <tt>int32</tt> in the Event Serialization Protocol
44 public final static byte INT32_TOKEN = (byte) 0x04;
45 /**
46 * The token used by <tt>string</tt> in the Event Serialization Protocol
48 public final static byte STRING_TOKEN = (byte) 0x05;
49 /**
50 * The token used by <tt>ip_addr</tt> in the Event Serialization Protocol
52 public final static byte IPADDR_TOKEN = (byte) 0x06;
53 /**
54 * The token used by <tt>int64</tt> in the Event Serialization Protocol
56 public final static byte INT64_TOKEN = (byte) 0x07;
57 /**
58 * The token used by <tt>uint64</tt> in the Event Serialization Protocol
60 public final static byte UINT64_TOKEN = (byte) 0x08;
61 /**
62 * The token used by <tt>boolean</tt> in the Event Serialization Protocol
64 public final static byte BOOLEAN_TOKEN = (byte) 0x09;
66 public final static byte BYTE_TOKEN = (byte) 0x0A;
67 public final static byte FLOAT_TOKEN = (byte) 0x0B;
68 public final static byte DOUBLE_TOKEN = (byte) 0x0C;
69 public final static byte IPV4_TOKEN = (byte) 0x0D;
70 public final static byte EVENT_TOKEN = (byte) 0x0F;
72 /**
73 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
75 public final static byte UINT16_ARRAY_TOKEN = (byte) 0x81;
76 /**
77 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
79 public final static byte INT16_ARRAY_TOKEN = (byte) 0x82;
80 /**
81 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
83 public final static byte UINT32_ARRAY_TOKEN = (byte) 0x83;
84 /**
85 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
87 public final static byte INT32_ARRAY_TOKEN = (byte) 0x84;
89 /**
90 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
92 public final static byte STRING_ARRAY_TOKEN = (byte) 0x85;
94 /**
95 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
97 public final static byte IP_ADDR_ARRAY_TOKEN = (byte) 0x86;
99 /**
100 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
102 public final static byte INT64_ARRAY_TOKEN = (byte) 0x87;
105 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
107 public final static byte UINT64_ARRAY_TOKEN = (byte) 0x88;
110 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
112 public final static byte BOOLEAN_ARRAY_TOKEN = (byte) 0x89;
114 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
116 public final static byte BYTE_ARRAY_TOKEN = (byte) 0x8A;
118 public final static byte FLOAT_ARRAY_TOKEN = (byte) 0x8B;
119 public final static byte DOUBLE_ARRAY_TOKEN = (byte) 0x8C;
120 public final static byte IPV4_ARRAY_TOKEN = (byte) 0x8D;
121 public final static byte EVENT_ARRAY_TOKEN = (byte) 0x8E;
124 * The string used by <tt>uint16</tt> in the Event Serialization Protocol
126 public final static String UINT16_STRING = "uint16";
128 * The string used by <tt>int16</tt> in the Event Serialization Protocol
130 public final static String INT16_STRING = "int16";
132 * The string used by <tt>uint32</tt> in the Event Serialization Protocol
134 public final static String UINT32_STRING = "uint32";
136 * The string used by <tt>int32</tt> in the Event Serialization Protocol
138 public final static String INT32_STRING = "int32";
140 * The string used by <tt>string</tt> in the Event Serialization Protocol
142 public final static String STRING_STRING = "string";
144 * The string used by <tt>ip_addr</tt> in the Event Serialization Protocol
146 public final static String IPADDR_STRING = "ip_addr";
148 * The string used by <tt>int64</tt> in the Event Serialization Protocol
150 public final static String INT64_STRING = "int64";
152 * The string used by <tt>uint64</tt> in the Event Serialization Protocol
154 public final static String UINT64_STRING = "uint64";
156 * The string used by <tt>boolean</tt> in the Event Serialization Protocol
158 public final static String BOOLEAN_STRING = "boolean";
160 public final static String BYTE_STRING = "byte";
161 public final static String DOUBLE_STRING = "double";
162 public final static String FLOAT_STRING = "float";
163 public final static String IPV4_STRING = "ipv4";
165 public final static String STRING_ARRAY_STRING = "[Lstring";
166 public final static String UINT16_ARRAY_STRING = "[Luint16";
167 public final static String INT16_ARRAY_STRING = "[Lint16";
168 public final static String UINT32_ARRAY_STRING = "[Luint32";
169 public final static String INT32_ARRAY_STRING = "[Lint32";
170 public final static String UINT64_ARRAY_STRING = "[Luint64";
171 public final static String INT64_ARRAY_STRING = "[Lint64";
172 public final static String BOOLEAN_ARRAY_STRING = "[Lboolean";
173 public final static String BYTE_ARRAY_STRING = "[Lbyte";
174 public final static String DOUBLE_ARRAY_STRING = "[Ldouble";
175 public final static String FLOAT_ARRAY_STRING = "[Lfloat";
176 public final static String IPV4_ARRAY_STRING = "[Lipv4";
179 * This is a regular expression for parsing an integer number from a string
181 public final static String SIGNED_INTEGER_REGEX = "-?\\d+";
183 * This is a regular expression for parsing an unsigned integer number
184 * from a string
186 public final static String UNSIGNED_INTEGER_REGEX = "\\d+(?=\\s|$)";
188 * This is a regular expression for matching a hexidecimal short from a string
190 public final static String HEX_SHORT_REGEX = "0x[0-9a-fA-F]{1,4}(?=\\s|$)";
192 * This is a regular expression for matching a hexidecimal int from a string
194 public final static String HEX_INT_REGEX = "0x[0-9a-fA-F]{5,8}(?=\\s|$)";
196 * This is a regular expression for matching a hexidecimal long from a string
198 public final static String HEX_LONG_REGEX = "0x[0-9a-fA-F]{9,16}(?=\\s|$)";
200 * This is a regular expression for matching an ip address from a string
202 public final static String IP_ADDR_REGEX
204 "\\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";
206 * This is a regular expression for matching a boolean from a string
208 public final static String BOOLEAN_REGEX = "true|false";
211 * Simple conversion utility
213 * @param id The id token to translate
214 * @return String representation of this id
216 public static String byteIDToString(byte id) {
217 switch (id) {
218 case UINT16_TOKEN:
219 return UINT16_STRING;
220 case INT16_TOKEN:
221 return INT16_STRING;
222 case UINT32_TOKEN:
223 return UINT32_STRING;
224 case INT32_TOKEN:
225 return INT32_STRING;
226 case STRING_TOKEN:
227 return STRING_STRING;
228 case IPADDR_TOKEN:
229 return IPADDR_STRING;
230 case INT64_TOKEN:
231 return INT64_STRING;
232 case UINT64_TOKEN:
233 return UINT64_STRING;
234 case BOOLEAN_TOKEN:
235 return BOOLEAN_STRING;
236 case BYTE_TOKEN:
237 return BYTE_STRING;
238 case STRING_ARRAY_TOKEN:
239 return STRING_ARRAY_STRING;
240 case UINT16_ARRAY_TOKEN:
241 return UINT16_ARRAY_STRING;
242 case INT16_ARRAY_TOKEN:
243 return INT16_ARRAY_STRING;
244 case UINT32_ARRAY_TOKEN:
245 return UINT32_ARRAY_STRING;
246 case INT32_ARRAY_TOKEN:
247 return INT32_ARRAY_STRING;
248 case UINT64_ARRAY_TOKEN:
249 return UINT64_ARRAY_STRING;
250 case INT64_ARRAY_TOKEN:
251 return INT64_ARRAY_STRING;
252 case BOOLEAN_ARRAY_TOKEN:
253 return BOOLEAN_ARRAY_STRING;
254 case BYTE_ARRAY_TOKEN:
255 return BYTE_ARRAY_STRING;
256 default:
257 return null;
262 * Another conversion utility
264 * @param id String representation of the type id
265 * @return byte token representation of the type id
267 public static byte stringToByteID(String id) {
268 if (id.equals(UINT16_STRING)) {
269 return UINT16_TOKEN;
271 else if (id.equals(INT16_STRING)) {
272 return INT16_TOKEN;
274 else if (id.equals(UINT32_STRING)) {
275 return UINT32_TOKEN;
277 else if (id.equals(INT32_STRING)) {
278 return INT32_TOKEN;
280 else if (id.equals(STRING_STRING)) {
281 return STRING_TOKEN;
283 else if (id.equals(IPADDR_STRING)) {
284 return IPADDR_TOKEN;
286 else if (id.equals(INT64_STRING)) {
287 return INT64_TOKEN;
289 else if (id.equals(UINT64_STRING)) {
290 return UINT64_TOKEN;
292 else if (id.equals(BOOLEAN_STRING)) {
293 return BOOLEAN_TOKEN;
295 else if (id.equals(BYTE_STRING)) {
296 return BYTE_TOKEN;
298 else if (id.equals(STRING_ARRAY_STRING)) {
299 return STRING_ARRAY_TOKEN;
301 else if (id.equals(UINT16_ARRAY_STRING)) {
302 return UINT16_ARRAY_TOKEN;
304 else if (id.equals(INT16_ARRAY_STRING)) {
305 return INT16_ARRAY_TOKEN;
307 else if (id.equals(UINT32_ARRAY_STRING)) {
308 return UINT32_ARRAY_TOKEN;
310 else if (id.equals(INT32_ARRAY_STRING)) {
311 return INT32_ARRAY_TOKEN;
313 else if (id.equals(STRING_ARRAY_STRING)) {
314 return STRING_ARRAY_TOKEN;
316 else if (id.equals(INT64_ARRAY_STRING)) {
317 return INT64_ARRAY_TOKEN;
319 else if (id.equals(UINT64_ARRAY_STRING)) {
320 return UINT64_ARRAY_TOKEN;
322 else if (id.equals(BOOLEAN_ARRAY_STRING)) {
323 return BOOLEAN_ARRAY_TOKEN;
325 else if (id.equals(BYTE_ARRAY_STRING)) {
326 return BYTE_ARRAY_TOKEN;
328 else {
329 return UNDEFINED_TOKEN;