1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#include "FieldParser.hpp"
Field FieldParser::Parse(FieldType type, byte *data, size_t len) {
switch (type) {
case VarIntType:
return ParseVarInt(data, len);
case Boolean:
return ParseBool(data);
case String:
return ParseString(data);
case Long:
return ParseLong(data);
case Int:
return ParseInt(data);
case UnsignedByte:
return ParseUByte(data);
case Byte8_t:
return ParseByte(data);
case Float:
return ParseFloat(data);
case Position:
return ParsePosition(data);
case Double:
return ParseDouble(data);
case ByteArray:
return ParseByteArray(data, len);
default:
throw 105;
}
}
Field FieldParser::ParseString(byte *data) {
Field fLen = ParseVarInt(data, 0);
Field f;
f.SetRaw(data, fLen.GetLength() + fLen.GetVarInt(), String);
return f;
}
Field FieldParser::ParseBool(byte *data) {
Field f;
f.SetRaw(data, 1, Boolean);
return f;
}
Field FieldParser::ParseVarInt(byte *data, size_t len) {
if (len != 0) {
Field f;
f.SetRaw(data, len, VarIntType);
return f;
}
int val = VarIntRead(data, len);
Field f;
f.SetVarInt(val);
return f;
}
Field FieldParser::ParseLong(byte *data) {
Field f;
f.SetRaw(data, 8, Long);
return f;
}
Field FieldParser::ParseInt(byte *data) {
Field f;
f.SetRaw(data, 4, Int);
return f;
}
Field FieldParser::ParseUByte(byte *data) {
Field f;
f.SetRaw(data, 1, UnsignedByte);
return f;
}
Field FieldParser::ParseByte(byte *data) {
Field f;
f.SetRaw(data, 1, Byte8_t);
return f;
}
Field FieldParser::ParseFloat(byte *data) {
Field f;
f.SetRaw(data, 4, Float);
return f;
}
Field FieldParser::ParsePosition(byte *data) {
Field f;
f.SetRaw(data, 8, Position);
return f;
}
Field FieldParser::ParseDouble(byte *data) {
Field f;
f.SetRaw(data, 8, Double);
return f;
}
Field FieldParser::ParseByteArray(byte *data, size_t len) {
if (len == 0)
throw 119;
Field f;
f.SetRaw(data, len, Byte8_t);
return f;
}
|