1 /*======================================================================*
2 * Copyright (c) 2008, Yahoo! Inc. All rights reserved. *
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 *======================================================================*/
16 * This class contains some global variables used in various parts of
19 * @author Anthony Molinaro
20 * @author Michael P. Lum
24 * The token used for <tt>undefined</tt> types in LWES
26 public final static byte UNDEFINED_TOKEN
= (byte) 0xff;
29 * The token used by <tt>uint16</tt> in the Event Serialization Protocol
31 public final static byte UINT16_TOKEN
= (byte) 0x01;
34 * The token used by <tt>int16</tt> in the Event Serialization Protocol
36 public final static byte INT16_TOKEN
= (byte) 0x02;
38 * The token used by <tt>uint32</tt> in the Event Serialization Protocol
40 public final static byte UINT32_TOKEN
= (byte) 0x03;
42 * The token used by <tt>int32</tt> in the Event Serialization Protocol
44 public final static byte INT32_TOKEN
= (byte) 0x04;
46 * The token used by <tt>string</tt> in the Event Serialization Protocol
48 public final static byte STRING_TOKEN
= (byte) 0x05;
50 * The token used by <tt>ip_addr</tt> in the Event Serialization Protocol
52 public final static byte IPADDR_TOKEN
= (byte) 0x06;
54 * The token used by <tt>int64</tt> in the Event Serialization Protocol
56 public final static byte INT64_TOKEN
= (byte) 0x07;
58 * The token used by <tt>uint64</tt> in the Event Serialization Protocol
60 public final static byte UINT64_TOKEN
= (byte) 0x08;
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;
73 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
75 public final static byte UINT16_ARRAY_TOKEN
= (byte) 0x81;
77 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
79 public final static byte INT16_ARRAY_TOKEN
= (byte) 0x82;
81 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
83 public final static byte UINT32_ARRAY_TOKEN
= (byte) 0x83;
85 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
87 public final static byte INT32_ARRAY_TOKEN
= (byte) 0x84;
90 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
92 public final static byte STRING_ARRAY_TOKEN
= (byte) 0x85;
95 * The token used by <tt>string[]</tt> in the Event Serialization Protocol
97 public final static byte IP_ADDR_ARRAY_TOKEN
= (byte) 0x86;
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
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
) {
219 return UINT16_STRING
;
223 return UINT32_STRING
;
227 return STRING_STRING
;
229 return IPADDR_STRING
;
233 return UINT64_STRING
;
235 return BOOLEAN_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
;
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
)) {
271 else if (id
.equals(INT16_STRING
)) {
274 else if (id
.equals(UINT32_STRING
)) {
277 else if (id
.equals(INT32_STRING
)) {
280 else if (id
.equals(STRING_STRING
)) {
283 else if (id
.equals(IPADDR_STRING
)) {
286 else if (id
.equals(INT64_STRING
)) {
289 else if (id
.equals(UINT64_STRING
)) {
292 else if (id
.equals(BOOLEAN_STRING
)) {
293 return BOOLEAN_TOKEN
;
295 else if (id
.equals(BYTE_STRING
)) {
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
;
329 return UNDEFINED_TOKEN
;