-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
msgpack.hexpat
147 lines (140 loc) · 3.09 KB
/
msgpack.hexpat
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#pragma author WerWolv
#pragma description MessagePack
#pragma MIME application/x-msgpack
enum Type : u8 {
PositiveFixInt = 0x00 ... 0x7F,
FixMap = 0x80 ... 0x8F,
FixArray = 0x90 ... 0x9F,
FixStr = 0xA0 ... 0xBF,
Nil = 0xC0,
Unused = 0xC1,
False = 0xC2,
True = 0xC3,
Bin8 = 0xC4,
Bin16 = 0xC5,
Bin32 = 0xC6,
Ext8 = 0xC7,
Ext16 = 0xC8,
Ext32 = 0xC9,
Float32 = 0xCA,
Float64 = 0xCB,
Uint8 = 0xCC,
Uint16 = 0xCD,
Uint32 = 0xCE,
Uint64 = 0xCF,
Int8 = 0xD0,
Int16 = 0xD1,
Int32 = 0xD2,
Int64 = 0xD3,
FixExt1 = 0xD4,
FixExt2 = 0xD5,
FixExt4 = 0xD6,
FixExt8 = 0xD7,
FixExt16 = 0xD8,
Str8 = 0xD9,
Str16 = 0xDA,
Str32 = 0xDB,
Array16 = 0xDC,
Array32 = 0xDD,
Map16 = 0xDE,
Map32 = 0xDF,
NegativeFixInt = 0xE0 ... 0xFF
};
using MessagePack;
struct MapEntry {
MessagePack key, value;
};
struct MessagePack {
Type type;
if (u8(type) <= 0x7F) {
$ -= 1;
u8 value;
} else if (u8(type) >= Type::NegativeFixInt) {
$ -= 1;
s8 value;
} else if (type == Type::Uint8)
be u8 value;
else if (type == Type::Uint16)
be u16 value;
else if (type == Type::Uint32)
be u32 value;
else if (type == Type::Uint64)
be u64 value;
else if (type == Type::Int8)
be s8 value;
else if (type == Type::Int16)
be s16 value;
else if (type == Type::Int32)
be s32 value;
else if (type == Type::Int64)
be s64 value;
else if (type == Type::Float32)
be float value;
else if (type == Type::Float64)
be double value;
else if ((u8(type) & 0b1110'0000) == Type::FixStr)
char value[u8(type) & 0b0001'1111];
else if (type == Type::Str8) {
be u8 length;
char value[length];
} else if (type == Type::Str16) {
be u16 length;
char value[length];
} else if (type == Type::Str32) {
be u32 length;
char value[length];
} else if (type == Type::Bin8) {
be u8 length;
u8 value[length];
} else if (type == Type::Bin16) {
be u16 length;
u8 value[length];
} else if (type == Type::Bin32) {
be u32 length;
u8 value[length];
} else if ((u8(type) & 0b1111'0000) == Type::FixArray)
MessagePack value[u8(type) & 0b0000'1111];
else if (type == Type::Array16) {
be u16 length;
MessagePack value[length];
} else if (type == Type::Array32) {
be u32 length;
MessagePack value[length];
} else if ((u8(type) & 0b1111'0000) == Type::FixMap)
MapEntry value[u8(type) & 0b0000'1111];
else if (type == Type::Map16) {
be u16 length;
MapEntry value[length];
} else if (type == Type::Map32) {
be u32 length;
MapEntry value[length];
} else if (type == Type::FixExt1) {
s8 type;
u8 data;
} else if (type == Type::FixExt2) {
s8 type;
u16 data;
} else if (type == Type::FixExt4) {
s8 type;
u32 data;
} else if (type == Type::FixExt8) {
s8 type;
u64 data;
} else if (type == Type::FixExt16) {
s8 type;
u128 data;
} else if (type == Type::Ext8) {
u8 length;
s8 type;
u8 data[length];
} else if (type == Type::Ext16) {
be u16 length;
s8 type;
u8 data[length];
} else if (type == Type::Ext32) {
be u32 length;
s8 type;
u8 data[length];
}
};
MessagePack pack @ 0x00;