Debian Codegraph @

benchmarks/small_payload_ffjson.go

raw
1 // Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
2 // source: small_payload.go
3
4 package benchmark
5
6 import (
7 "bytes"
8 "fmt"
9
10 fflib "github.com/pquerna/ffjson/fflib/v1"
11 )
12
13 // MarshalJSON marshal bytes to json - template
14 func (j *SmallPayloadFFJson) MarshalJSON() ([]byte, error) {
15 var buf fflib.Buffer
16 if j == nil {
17 buf.WriteString("null")
18 return buf.Bytes(), nil
19 }
20 err := j.MarshalJSONBuf(&buf)
21 if err != nil {
22 return nil, err
23 }
24 return buf.Bytes(), nil
25 }
26
27 // MarshalJSONBuf marshal buff to json - template
28 func (j *SmallPayloadFFJson) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
29 if j == nil {
30 buf.WriteString("null")
31 return nil
32 }
33 var err error
34 var obj []byte
35 _ = obj
36 _ = err
37 buf.WriteString(`{"St":`)
38 fflib.FormatBits2(buf, uint64(j.St), 10, j.St < 0)
39 buf.WriteString(`,"Sid":`)
40 fflib.FormatBits2(buf, uint64(j.Sid), 10, j.Sid < 0)
41 buf.WriteString(`,"Tt":`)
42 fflib.WriteJsonString(buf, string(j.Tt))
43 buf.WriteString(`,"Gr":`)
44 fflib.FormatBits2(buf, uint64(j.Gr), 10, j.Gr < 0)
45 buf.WriteString(`,"Uuid":`)
46 fflib.WriteJsonString(buf, string(j.Uuid))
47 buf.WriteString(`,"Ip":`)
48 fflib.WriteJsonString(buf, string(j.Ip))
49 buf.WriteString(`,"Ua":`)
50 fflib.WriteJsonString(buf, string(j.Ua))
51 buf.WriteString(`,"Tz":`)
52 fflib.FormatBits2(buf, uint64(j.Tz), 10, j.Tz < 0)
53 buf.WriteString(`,"V":`)
54 fflib.FormatBits2(buf, uint64(j.V), 10, j.V < 0)
55 buf.WriteByte('}')
56 return nil
57 }
58
59 const (
60 ffjtSmallPayloadFFJsonbase = iota
61 ffjtSmallPayloadFFJsonnosuchkey
62
63 ffjtSmallPayloadFFJsonSt
64
65 ffjtSmallPayloadFFJsonSid
66
67 ffjtSmallPayloadFFJsonTt
68
69 ffjtSmallPayloadFFJsonGr
70
71 ffjtSmallPayloadFFJsonUuid
72
73 ffjtSmallPayloadFFJsonIp
74
75 ffjtSmallPayloadFFJsonUa
76
77 ffjtSmallPayloadFFJsonTz
78
79 ffjtSmallPayloadFFJsonV
80 )
81
82 var ffjKeySmallPayloadFFJsonSt = []byte("St")
83
84 var ffjKeySmallPayloadFFJsonSid = []byte("Sid")
85
86 var ffjKeySmallPayloadFFJsonTt = []byte("Tt")
87
88 var ffjKeySmallPayloadFFJsonGr = []byte("Gr")
89
90 var ffjKeySmallPayloadFFJsonUuid = []byte("Uuid")
91
92 var ffjKeySmallPayloadFFJsonIp = []byte("Ip")
93
94 var ffjKeySmallPayloadFFJsonUa = []byte("Ua")
95
96 var ffjKeySmallPayloadFFJsonTz = []byte("Tz")
97
98 var ffjKeySmallPayloadFFJsonV = []byte("V")
99
100 // UnmarshalJSON umarshall json - template of ffjson
101 func (j *SmallPayloadFFJson) UnmarshalJSON(input []byte) error {
102 fs := fflib.NewFFLexer(input)
103 return j.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
104 }
105
106 // UnmarshalJSONFFLexer fast json unmarshall - template ffjson
107 func (j *SmallPayloadFFJson) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error {
108 var err error
109 currentKey := ffjtSmallPayloadFFJsonbase
110 _ = currentKey
111 tok := fflib.FFTok_init
112 wantedTok := fflib.FFTok_init
113
114 mainparse:
115 for {
116 tok = fs.Scan()
117 // println(fmt.Sprintf("debug: tok: %v state: %v", tok, state))
118 if tok == fflib.FFTok_error {
119 goto tokerror
120 }
121
122 switch state {
123
124 case fflib.FFParse_map_start:
125 if tok != fflib.FFTok_left_bracket {
126 wantedTok = fflib.FFTok_left_bracket
127 goto wrongtokenerror
128 }
129 state = fflib.FFParse_want_key
130 continue
131
132 case fflib.FFParse_after_value:
133 if tok == fflib.FFTok_comma {
134 state = fflib.FFParse_want_key
135 } else if tok == fflib.FFTok_right_bracket {
136 goto done
137 } else {
138 wantedTok = fflib.FFTok_comma
139 goto wrongtokenerror
140 }
141
142 case fflib.FFParse_want_key:
143 // json {} ended. goto exit. woo.
144 if tok == fflib.FFTok_right_bracket {
145 goto done
146 }
147 if tok != fflib.FFTok_string {
148 wantedTok = fflib.FFTok_string
149 goto wrongtokenerror
150 }
151
152 kn := fs.Output.Bytes()
153 if len(kn) <= 0 {
154 // "" case. hrm.
155 currentKey = ffjtSmallPayloadFFJsonnosuchkey
156 state = fflib.FFParse_want_colon
157 goto mainparse
158 } else {
159 switch kn[0] {
160
161 case 'G':
162
163 if bytes.Equal(ffjKeySmallPayloadFFJsonGr, kn) {
164 currentKey = ffjtSmallPayloadFFJsonGr
165 state = fflib.FFParse_want_colon
166 goto mainparse
167 }
168
169 case 'I':
170
171 if bytes.Equal(ffjKeySmallPayloadFFJsonIp, kn) {
172 currentKey = ffjtSmallPayloadFFJsonIp
173 state = fflib.FFParse_want_colon
174 goto mainparse
175 }
176
177 case 'S':
178
179 if bytes.Equal(ffjKeySmallPayloadFFJsonSt, kn) {
180 currentKey = ffjtSmallPayloadFFJsonSt
181 state = fflib.FFParse_want_colon
182 goto mainparse
183
184 } else if bytes.Equal(ffjKeySmallPayloadFFJsonSid, kn) {
185 currentKey = ffjtSmallPayloadFFJsonSid
186 state = fflib.FFParse_want_colon
187 goto mainparse
188 }
189
190 case 'T':
191
192 if bytes.Equal(ffjKeySmallPayloadFFJsonTt, kn) {
193 currentKey = ffjtSmallPayloadFFJsonTt
194 state = fflib.FFParse_want_colon
195 goto mainparse
196
197 } else if bytes.Equal(ffjKeySmallPayloadFFJsonTz, kn) {
198 currentKey = ffjtSmallPayloadFFJsonTz
199 state = fflib.FFParse_want_colon
200 goto mainparse
201 }
202
203 case 'U':
204
205 if bytes.Equal(ffjKeySmallPayloadFFJsonUuid, kn) {
206 currentKey = ffjtSmallPayloadFFJsonUuid
207 state = fflib.FFParse_want_colon
208 goto mainparse
209
210 } else if bytes.Equal(ffjKeySmallPayloadFFJsonUa, kn) {
211 currentKey = ffjtSmallPayloadFFJsonUa
212 state = fflib.FFParse_want_colon
213 goto mainparse
214 }
215
216 case 'V':
217
218 if bytes.Equal(ffjKeySmallPayloadFFJsonV, kn) {
219 currentKey = ffjtSmallPayloadFFJsonV
220 state = fflib.FFParse_want_colon
221 goto mainparse
222 }
223
224 }
225
226 if fflib.SimpleLetterEqualFold(ffjKeySmallPayloadFFJsonV, kn) {
227 currentKey = ffjtSmallPayloadFFJsonV
228 state = fflib.FFParse_want_colon
229 goto mainparse
230 }
231
232 if fflib.SimpleLetterEqualFold(ffjKeySmallPayloadFFJsonTz, kn) {
233 currentKey = ffjtSmallPayloadFFJsonTz
234 state = fflib.FFParse_want_colon
235 goto mainparse
236 }
237
238 if fflib.SimpleLetterEqualFold(ffjKeySmallPayloadFFJsonUa, kn) {
239 currentKey = ffjtSmallPayloadFFJsonUa
240 state = fflib.FFParse_want_colon
241 goto mainparse
242 }
243
244 if fflib.SimpleLetterEqualFold(ffjKeySmallPayloadFFJsonIp, kn) {
245 currentKey = ffjtSmallPayloadFFJsonIp
246 state = fflib.FFParse_want_colon
247 goto mainparse
248 }
249
250 if fflib.SimpleLetterEqualFold(ffjKeySmallPayloadFFJsonUuid, kn) {
251 currentKey = ffjtSmallPayloadFFJsonUuid
252 state = fflib.FFParse_want_colon
253 goto mainparse
254 }
255
256 if fflib.SimpleLetterEqualFold(ffjKeySmallPayloadFFJsonGr, kn) {
257 currentKey = ffjtSmallPayloadFFJsonGr
258 state = fflib.FFParse_want_colon
259 goto mainparse
260 }
261
262 if fflib.SimpleLetterEqualFold(ffjKeySmallPayloadFFJsonTt, kn) {
263 currentKey = ffjtSmallPayloadFFJsonTt
264 state = fflib.FFParse_want_colon
265 goto mainparse
266 }
267
268 if fflib.EqualFoldRight(ffjKeySmallPayloadFFJsonSid, kn) {
269 currentKey = ffjtSmallPayloadFFJsonSid
270 state = fflib.FFParse_want_colon
271 goto mainparse
272 }
273
274 if fflib.EqualFoldRight(ffjKeySmallPayloadFFJsonSt, kn) {
275 currentKey = ffjtSmallPayloadFFJsonSt
276 state = fflib.FFParse_want_colon
277 goto mainparse
278 }
279
280 currentKey = ffjtSmallPayloadFFJsonnosuchkey
281 state = fflib.FFParse_want_colon
282 goto mainparse
283 }
284
285 case fflib.FFParse_want_colon:
286 if tok != fflib.FFTok_colon {
287 wantedTok = fflib.FFTok_colon
288 goto wrongtokenerror
289 }
290 state = fflib.FFParse_want_value
291 continue
292 case fflib.FFParse_want_value:
293
294 if tok == fflib.FFTok_left_brace || tok == fflib.FFTok_left_bracket || tok == fflib.FFTok_integer || tok == fflib.FFTok_double || tok == fflib.FFTok_string || tok == fflib.FFTok_bool || tok == fflib.FFTok_null {
295 switch currentKey {
296
297 case ffjtSmallPayloadFFJsonSt:
298 goto handle_St
299
300 case ffjtSmallPayloadFFJsonSid:
301 goto handle_Sid
302
303 case ffjtSmallPayloadFFJsonTt:
304 goto handle_Tt
305
306 case ffjtSmallPayloadFFJsonGr:
307 goto handle_Gr
308
309 case ffjtSmallPayloadFFJsonUuid:
310 goto handle_Uuid
311
312 case ffjtSmallPayloadFFJsonIp:
313 goto handle_Ip
314
315 case ffjtSmallPayloadFFJsonUa:
316 goto handle_Ua
317
318 case ffjtSmallPayloadFFJsonTz:
319 goto handle_Tz
320
321 case ffjtSmallPayloadFFJsonV:
322 goto handle_V
323
324 case ffjtSmallPayloadFFJsonnosuchkey:
325 err = fs.SkipField(tok)
326 if err != nil {
327 return fs.WrapErr(err)
328 }
329 state = fflib.FFParse_after_value
330 goto mainparse
331 }
332 } else {
333 goto wantedvalue
334 }
335 }
336 }
337
338 handle_St:
339
340 /* handler: j.St type=int kind=int quoted=false*/
341
342 {
343 if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
344 return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
345 }
346 }
347
348 {
349
350 if tok == fflib.FFTok_null {
351
352 } else {
353
354 tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
355
356 if err != nil {
357 return fs.WrapErr(err)
358 }
359
360 j.St = int(tval)
361
362 }
363 }
364
365 state = fflib.FFParse_after_value
366 goto mainparse
367
368 handle_Sid:
369
370 /* handler: j.Sid type=int kind=int quoted=false*/
371
372 {
373 if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
374 return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
375 }
376 }
377
378 {
379
380 if tok == fflib.FFTok_null {
381
382 } else {
383
384 tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
385
386 if err != nil {
387 return fs.WrapErr(err)
388 }
389
390 j.Sid = int(tval)
391
392 }
393 }
394
395 state = fflib.FFParse_after_value
396 goto mainparse
397
398 handle_Tt:
399
400 /* handler: j.Tt type=string kind=string quoted=false*/
401
402 {
403
404 {
405 if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
406 return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
407 }
408 }
409
410 if tok == fflib.FFTok_null {
411
412 } else {
413
414 outBuf := fs.Output.Bytes()
415
416 j.Tt = string(string(outBuf))
417
418 }
419 }
420
421 state = fflib.FFParse_after_value
422 goto mainparse
423
424 handle_Gr:
425
426 /* handler: j.Gr type=int kind=int quoted=false*/
427
428 {
429 if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
430 return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
431 }
432 }
433
434 {
435
436 if tok == fflib.FFTok_null {
437
438 } else {
439
440 tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
441
442 if err != nil {
443 return fs.WrapErr(err)
444 }
445
446 j.Gr = int(tval)
447
448 }
449 }
450
451 state = fflib.FFParse_after_value
452 goto mainparse
453
454 handle_Uuid:
455
456 /* handler: j.Uuid type=string kind=string quoted=false*/
457
458 {
459
460 {
461 if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
462 return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
463 }
464 }
465
466 if tok == fflib.FFTok_null {
467
468 } else {
469
470 outBuf := fs.Output.Bytes()
471
472 j.Uuid = string(string(outBuf))
473
474 }
475 }
476
477 state = fflib.FFParse_after_value
478 goto mainparse
479
480 handle_Ip:
481
482 /* handler: j.Ip type=string kind=string quoted=false*/
483
484 {
485
486 {
487 if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
488 return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
489 }
490 }
491
492 if tok == fflib.FFTok_null {
493
494 } else {
495
496 outBuf := fs.Output.Bytes()
497
498 j.Ip = string(string(outBuf))
499
500 }
501 }
502
503 state = fflib.FFParse_after_value
504 goto mainparse
505
506 handle_Ua:
507
508 /* handler: j.Ua type=string kind=string quoted=false*/
509
510 {
511
512 {
513 if tok != fflib.FFTok_string && tok != fflib.FFTok_null {
514 return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for string", tok))
515 }
516 }
517
518 if tok == fflib.FFTok_null {
519
520 } else {
521
522 outBuf := fs.Output.Bytes()
523
524 j.Ua = string(string(outBuf))
525
526 }
527 }
528
529 state = fflib.FFParse_after_value
530 goto mainparse
531
532 handle_Tz:
533
534 /* handler: j.Tz type=int kind=int quoted=false*/
535
536 {
537 if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
538 return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
539 }
540 }
541
542 {
543
544 if tok == fflib.FFTok_null {
545
546 } else {
547
548 tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
549
550 if err != nil {
551 return fs.WrapErr(err)
552 }
553
554 j.Tz = int(tval)
555
556 }
557 }
558
559 state = fflib.FFParse_after_value
560 goto mainparse
561
562 handle_V:
563
564 /* handler: j.V type=int kind=int quoted=false*/
565
566 {
567 if tok != fflib.FFTok_integer && tok != fflib.FFTok_null {
568 return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for int", tok))
569 }
570 }
571
572 {
573
574 if tok == fflib.FFTok_null {
575
576 } else {
577
578 tval, err := fflib.ParseInt(fs.Output.Bytes(), 10, 64)
579
580 if err != nil {
581 return fs.WrapErr(err)
582 }
583
584 j.V = int(tval)
585
586 }
587 }
588
589 state = fflib.FFParse_after_value
590 goto mainparse
591
592 wantedvalue:
593 return fs.WrapErr(fmt.Errorf("wanted value token, but got token: %v", tok))
594 wrongtokenerror:
595 return fs.WrapErr(fmt.Errorf("ffjson: wanted token: %v, but got token: %v output=%s", wantedTok, tok, fs.Output.String()))
596 tokerror:
597 if fs.BigError != nil {
598 return fs.WrapErr(fs.BigError)
599 }
600 err = fs.Error.ToError()
601 if err != nil {
602 return fs.WrapErr(err)
603 }
604 panic("ffjson-generated: unreachable, please report bug.")
605 done:
606
607 return nil
608 }