-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
166 lines (156 loc) · 5.39 KB
/
types.go
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package msgpack
const (
minFixedInt int8 = -32 // minimum int8 value of a fixed 8-bit int
maxFixedInt int8 = 127 // maximum int8 value of a fixed 8-bit int
minFixedUint uint8 = 0 // minimum uint8 value of a fixed 8-bit uint
maxFixedUint uint8 = 127 // maximum uint8 value of a fixed 8-bit uint
)
// atoms are single-bytes encoding both type and value.
//
// # available atoms:
//
// atomNil // 0xc0: nil
// atomNull // 0xc0: nil
// atomFalse // 0xc2: false
// atomTrue // 0xc3: true
// atomEmptyArray // 0x90: array with 0 entries
// atomEmptyMap // 0x80: map with 0 entries
// atomEmptyString // 0xa0: string with zero length
// atomZero // 0x00: zero
const (
atomNil byte = atomNull
atomNull byte = 0xc0
atomFalse byte = 0xc2
atomTrue byte = 0xc3
atomEmptyArray byte = 0x90
atomEmptyMap byte = 0x80
atomEmptyString byte = 0xa0
atomZero byte = 0x00
)
// masks are single-byte values that encode type and size information in a single
// byte. Each mask is OR'd with a value stored in the bits not used for the
// mask itself.
//
// # available masks:
//
// maskFixArray // 0x90-0x9f: array with 0-15 entries
// maskFixInt // 0x00-0x7f: positive fixint (0-127)
// maskFixMap // 0x80-0x8f: map with 0-15 entries
// maskFixString // 0xa0-0xbf: string with 0-31 bytes
// maskNegFixInt // 0xe0-0xff: negative fixint (-1 to -32)
const (
maskFixArray byte = 0x90 // 0x90-0x9f: array with 0-15 entries
maskFixInt byte = 0x00 // 0x00-0x7f: positive fixint (0-127)
maskFixMap byte = 0x80 // 0x80-0x8f: map with 0-15 entries
maskFixString byte = 0xa0 // 0xa0-0xbf: string with 0-31 bytes
maskNegFixInt byte = 0xe0 // 0xe0-0xff: negative fixint (-1 to -32)
)
// array family types consist of a single byte followed by 2, or 4 bytes
// encoding the number of elements in the array, followed by the elements
// themselves (encoded as discrete msgpack values).
//
// # available array family types:
//
// typeArray16 // 0xdc: array with 0-65,535 elements
// typeArray32 // 0xdd: array with 0-4,294,967,295 elements
const (
typeArray16 byte = 0xdc
typeArray32 byte = 0xdd
)
// binary family types consist of a single byte followed by 1, 2, or 4 bytes
// encoding the number of bytes in the binary data, followed by the binary
// data itself.
//
// # available binary family types:
//
// typeBin8 // 0xc4: binary with 0-255 bytes of data
// typeBin16 // 0xc5: binary with 0-65,535 bytes of data
// typeBin32 // 0xc6: binary with 0-4,294,967,295 bytes of data
const (
typeBin8 byte = 0xc4
typeBin16 byte = 0xc5
typeBin32 byte = 0xc6
)
// float family types consist of a single byte followed by 4 or 8 bytes
//
// # available float family types:
//
// typeFloat32 // 0xca: 32-bit IEEE 754 floating point
// typeFloat64 // 0xcb: 64-bit IEEE 754 floating point
const (
typeFloat32 byte = 0xca
typeFloat64 byte = 0xcb
)
// map family types consist of a single byte followed by 2, or 4 bytes
// encoding the number of elements in the map, followed by the key+value
// pairs in the map (encoded as discrete msgpack values).
//
// # available map family types:
//
// typeMap16 // 0xde: map with 0-65,535 elements
// typeMap32 // 0xdf: map with 0-4,294,967,295 elements
const (
typeMap16 byte = 0xde
typeMap32 byte = 0xdf
)
// int family types consist of a single byte followed by 1, 2, 4, or 8 bytes
// encoding the integer value.
//
// # available int family types:
//
// typeInt8 // 0xd0: 8-bit signed integer
// typeInt16 // 0xd1: 16-bit signed integer
// typeInt32 // 0xd2: 32-bit signed integer
// typeInt64 // 0xd3: 64-bit signed integer
// typeUint8 // 0xcc: 8-bit unsigned integer
// typeUint16 // 0xcd: 16-bit unsigned integer
// typeUint32 // 0xce: 32-bit unsigned integer
// typeUint64 // 0xcf: 64-bit unsigned integer
const (
typeInt8 byte = 0xd0
typeInt16 byte = 0xd1
typeInt32 byte = 0xd2
typeInt64 byte = 0xd3
typeUint8 byte = 0xcc
typeUint16 byte = 0xcc
typeUint32 byte = 0xcd
typeUint64 byte = 0xce
)
// string family types consist of a single byte followed by 1, 2, or 4 bytes
// encoding the number of bytes in the string, followed by the string data
// itself.
//
// # available string family types:
//
// typeString8 // 0xd9: string with 0-255 bytes of data
// typeString16 // 0xda: string with 0-65,535 bytes of data
// typeString32 // 0xdb: string with 0-4,294,967,295 bytes of data
const (
typeString8 byte = 0xd9
typeString16 byte = 0xda
typeString32 byte = 0xdb
)
// ext family types consist of a single byte followed by 1, 2, or 4 bytes
// encoding the number of bytes in the extension data, followed by the
// extension type and the extension data itself.
//
// # available ext family types:
//
// typeFixExt1 // 0xd4: 1-byte extension type
// typeFixExt2 // 0xd5: 2-byte extension type
// typeFixExt4 // 0xd6: 4-byte extension type
// typeFixExt8 // 0xd7: 8-byte extension type
// typeFixExt16 // 0xd8: 16-byte extension type
// typeExt8 // 0xc7: extension type with 0-255 bytes of data
// typeExt16 // 0xc8: extension type with 0-65,535 bytes of data
// typeExt32 // 0xc9: extension type with 0-4,294,967,295 bytes of data
const (
typeFixExt1 byte = 0xd4
typeFixExt2 byte = 0xd5
typeFixExt4 byte = 0xd6
typeFixExt8 byte = 0xd7
typeFixExt16 byte = 0xd8
typeExt8 byte = 0xc7
typeExt16 byte = 0xc8
typeExt32 byte = 0xc9
)