-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolver.msgpackgen.go
302 lines (287 loc) · 8.67 KB
/
resolver.msgpackgen.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// Code generated by msgpackgen. DO NOT EDIT.
package main
import (
"fmt"
msgpack "github.com/shamaton/msgpackgen/msgpack"
dec "github.com/shamaton/msgpackgen/msgpack/dec"
enc "github.com/shamaton/msgpackgen/msgpack/enc"
)
// RegisterGeneratedResolver registers generated resolver.
func RegisterGeneratedResolver() {
msgpack.SetResolver(___encodeAsMap, ___encodeAsArray, ___decodeAsMap, ___decodeAsArray)
}
// encode
func ___encode(i interface{}) ([]byte, error) {
if msgpack.StructAsArray() {
return ___encodeAsArray(i)
} else {
return ___encodeAsMap(i)
}
}
// encodeAsArray
func ___encodeAsArray(i interface{}) ([]byte, error) {
switch v := i.(type) {
case Person:
encoder := enc.NewEncoder()
size, err := ___calcArraySizePerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v, encoder)
if err != nil {
return nil, err
}
encoder.MakeBytes(size)
b, offset, err := ___encodeArrayPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v, encoder, 0)
if err != nil {
return nil, err
}
if size != offset {
return nil, fmt.Errorf("%s size / offset different %d : %d", "Person", size, offset)
}
return b, err
case *Person:
encoder := enc.NewEncoder()
size, err := ___calcArraySizePerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(*v, encoder)
if err != nil {
return nil, err
}
encoder.MakeBytes(size)
b, offset, err := ___encodeArrayPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(*v, encoder, 0)
if err != nil {
return nil, err
}
if size != offset {
return nil, fmt.Errorf("%s size / offset different %d : %d", "Person", size, offset)
}
return b, err
}
return nil, nil
}
// encodeAsMap
func ___encodeAsMap(i interface{}) ([]byte, error) {
switch v := i.(type) {
case Person:
encoder := enc.NewEncoder()
size, err := ___calcMapSizePerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v, encoder)
if err != nil {
return nil, err
}
encoder.MakeBytes(size)
b, offset, err := ___encodeMapPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v, encoder, 0)
if err != nil {
return nil, err
}
if size != offset {
return nil, fmt.Errorf("%s size / offset different %d : %d", "Person", size, offset)
}
return b, err
case *Person:
encoder := enc.NewEncoder()
size, err := ___calcMapSizePerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(*v, encoder)
if err != nil {
return nil, err
}
encoder.MakeBytes(size)
b, offset, err := ___encodeMapPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(*v, encoder, 0)
if err != nil {
return nil, err
}
if size != offset {
return nil, fmt.Errorf("%s size / offset different %d : %d", "Person", size, offset)
}
return b, err
}
return nil, nil
}
// decode
func ___decode(data []byte, i interface{}) (bool, error) {
if msgpack.StructAsArray() {
return ___decodeAsArray(data, i)
} else {
return ___decodeAsMap(data, i)
}
}
// decodeAsArray
func ___decodeAsArray(data []byte, i interface{}) (bool, error) {
switch v := i.(type) {
case *Person:
decoder := dec.NewDecoder(data)
offset, err := ___decodeArrayPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v, decoder, 0)
if err == nil && offset != decoder.Len() {
return true, fmt.Errorf("read length is different [%d] [%d] ", offset, decoder.Len())
}
return true, err
case **Person:
decoder := dec.NewDecoder(data)
offset, err := ___decodeArrayPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(*v, decoder, 0)
if err == nil && offset != decoder.Len() {
return true, fmt.Errorf("read length is different [%d] [%d] ", offset, decoder.Len())
}
return true, err
}
return false, nil
}
// decodeAsMap
func ___decodeAsMap(data []byte, i interface{}) (bool, error) {
switch v := i.(type) {
case *Person:
decoder := dec.NewDecoder(data)
offset, err := ___decodeMapPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v, decoder, 0)
if err == nil && offset != decoder.Len() {
return true, fmt.Errorf("read length is different [%d] [%d] ", offset, decoder.Len())
}
return true, err
case **Person:
decoder := dec.NewDecoder(data)
offset, err := ___decodeMapPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(*v, decoder, 0)
if err == nil && offset != decoder.Len() {
return true, fmt.Errorf("read length is different [%d] [%d] ", offset, decoder.Len())
}
return true, err
}
return false, nil
}
// calculate size from test.Person
func ___calcArraySizePerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v Person, encoder *enc.Encoder) (int, error) {
size := 0
size += encoder.CalcStructHeaderFix(4)
size += encoder.CalcString(v.Name)
size += encoder.CalcString(v.Address)
size += encoder.CalcInt(v.Age)
return size, nil
}
// calculate size from test.Person
func ___calcMapSizePerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v Person, encoder *enc.Encoder) (int, error) {
size := 0
size += encoder.CalcStructHeaderFix(4)
size += encoder.CalcStringFix(4)
size += encoder.CalcString(v.Name)
size += encoder.CalcStringFix(7)
size += encoder.CalcString(v.Address)
size += encoder.CalcStringFix(3)
size += encoder.CalcInt(v.Age)
size += encoder.CalcStringFix(6)
return size, nil
}
// encode from test.Person
func ___encodeArrayPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v Person, encoder *enc.Encoder, offset int) ([]byte, int, error) {
var err error
offset = encoder.WriteStructHeaderFixAsArray(4, offset)
offset = encoder.WriteString(v.Name, offset)
offset = encoder.WriteString(v.Address, offset)
offset = encoder.WriteInt(v.Age, offset)
return encoder.EncodedBytes(), offset, err
}
// encode from test.Person
func ___encodeMapPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v Person, encoder *enc.Encoder, offset int) ([]byte, int, error) {
var err error
offset = encoder.WriteStructHeaderFixAsMap(4, offset)
offset = encoder.WriteStringFix("Name", 4, offset)
offset = encoder.WriteString(v.Name, offset)
offset = encoder.WriteStringFix("Address", 7, offset)
offset = encoder.WriteString(v.Address, offset)
offset = encoder.WriteStringFix("Age", 3, offset)
offset = encoder.WriteInt(v.Age, offset)
return encoder.EncodedBytes(), offset, err
}
// decode to test.Person
func ___decodeArrayPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v *Person, decoder *dec.Decoder, offset int) (int, error) {
offset, err := decoder.CheckStructHeader(4, offset)
if err != nil {
return 0, err
}
{
var vv string
vv, offset, err = decoder.AsString(offset)
if err != nil {
return 0, err
}
v.Name = vv
}
{
var vv string
vv, offset, err = decoder.AsString(offset)
if err != nil {
return 0, err
}
v.Address = vv
}
{
var vv int
vv, offset, err = decoder.AsInt(offset)
if err != nil {
return 0, err
}
v.Age = vv
}
return offset, err
}
// decode to test.Person
func ___decodeMapPerson_9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08(v *Person, decoder *dec.Decoder, offset int) (int, error) {
keys := [][]byte{
{uint8(0x4e), uint8(0x61), uint8(0x6d), uint8(0x65)}, // Name
{uint8(0x41), uint8(0x64), uint8(0x64), uint8(0x72), uint8(0x65), uint8(0x73), uint8(0x73)}, // Address
{uint8(0x41), uint8(0x67), uint8(0x65)}, // Age
{uint8(0x48), uint8(0x69), uint8(0x64), uint8(0x64), uint8(0x65), uint8(0x6e)}, // Hidden
}
offset, err := decoder.CheckStructHeader(4, offset)
if err != nil {
return 0, err
}
count := 0
for count < 4 {
var dataKey []byte
dataKey, offset, err = decoder.AsStringBytes(offset)
if err != nil {
return 0, err
}
fieldIndex := -1
for i, key := range keys {
if len(dataKey) != len(key) {
continue
}
fieldIndex = i
for dataKeyIndex := range dataKey {
if dataKey[dataKeyIndex] != key[dataKeyIndex] {
fieldIndex = -1
break
}
}
if fieldIndex >= 0 {
break
}
}
switch fieldIndex {
case 0:
{
var vv string
vv, offset, err = decoder.AsString(offset)
if err != nil {
return 0, err
}
v.Name = vv
}
count++
case 1:
{
var vv string
vv, offset, err = decoder.AsString(offset)
if err != nil {
return 0, err
}
v.Address = vv
}
count++
case 2:
{
var vv int
vv, offset, err = decoder.AsInt(offset)
if err != nil {
return 0, err
}
v.Age = vv
}
count++
default:
return 0, fmt.Errorf("unknown key[%s] found", string(dataKey))
}
}
return offset, err
}