29 u_int8_t
getByte(u_int8_t
const*& ptr, u_int8_t
const* limit) {
30 if (limit != NULL && ptr+1 > limit)
throw END_OF_DATA;
34 u_int16_t
get2BytesBE(u_int8_t
const*& ptr, u_int8_t
const* limit) {
35 if (limit != NULL && ptr+2 > limit)
throw END_OF_DATA;
36 u_int8_t byte1 = *ptr++;
37 u_int8_t byte2 = *ptr++;
38 return (byte1<<8)|byte2;
41 u_int16_t
get2BytesLE(u_int8_t
const*& ptr, u_int8_t
const* limit) {
42 if (limit != NULL && ptr+2 > limit)
throw END_OF_DATA;
43 u_int8_t byte1 = *ptr++;
44 u_int8_t byte2 = *ptr++;
45 return (byte2<<8)|byte1;
48 unsigned getWord32BE(u_int8_t
const*& ptr, u_int8_t
const* limit) {
49 if (limit != NULL && ptr+4 > limit)
throw END_OF_DATA;
50 unsigned result = (ptr[0]<<24)|(ptr[1]<<16)|(ptr[2]<<8)|ptr[3];
55 unsigned getWord32LE(u_int8_t
const*& ptr, u_int8_t
const* limit) {
56 if (limit != NULL && ptr+4 > limit)
throw END_OF_DATA;
57 unsigned result = (ptr[3]<<24)|(ptr[2]<<16)|(ptr[1]<<8)|ptr[0];
62 u_int64_t
getWord64LE(u_int8_t
const*& ptr, u_int8_t
const* limit) {
65 return (resultHigh<<32)|resultLow;
68 void printString(
char const* label, u_int8_t
const*& ptr,
unsigned stringLength, u_int8_t
const* limit) {
69 if (limit != NULL && ptr+stringLength > limit)
throw END_OF_DATA;
71 char str[stringLength+1];
73 for (i = 0; i < stringLength; ++i) str[i] = *ptr++;
77 fprintf(stderr,
"%s\n", str);
79 fprintf(stderr,
"%s: %s\n", label, str);
83 void printHex(
char const* label, u_int8_t
const*& ptr, u_int8_t
const* limit) {
84 if (limit == NULL)
return;
85 if (label != NULL) fprintf(stderr,
"%s: ", label);
86 for (u_int8_t
const* p = ptr; p < limit; ++p) fprintf(stderr,
":%02x", *p);
87 fprintf(stderr,
"\n");
u_int8_t getByte(u_int8_t const *&ptr, u_int8_t const *limit)
u_int64_t getWord64LE(u_int8_t const *&ptr, u_int8_t const *limit)
void printString(char const *label, u_int8_t const *&ptr, unsigned stringLength, u_int8_t const *limit)
unsigned getWord32LE(u_int8_t const *&ptr, u_int8_t const *limit)
u_int16_t get2BytesLE(u_int8_t const *&ptr, u_int8_t const *limit)
u_int16_t get2BytesBE(u_int8_t const *&ptr, u_int8_t const *limit)
unsigned getWord32BE(u_int8_t const *&ptr, u_int8_t const *limit)
void printHex(char const *label, u_int8_t const *&ptr, u_int8_t const *limit)