Debian Codegraph @

jsonutils/adapters/testintegration/benchmarks/payloads_easyjson.go

raw
1 // SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
2 // SPDX-License-Identifier: Apache-2.0
3
4 package benchmarks
5
6 import (
7 jlexer "github.com/mailru/easyjson/jlexer"
8 jwriter "github.com/mailru/easyjson/jwriter"
9 )
10
11 const defaultEasyJSONAlloc = 8
12
13 // MarshalEasyJSON supports easyjson.Marshaler interface
14 func (v SmallPayload) MarshalEasyJSON(out *jwriter.Writer) {
15 out.RawByte('{')
16 first := true
17 {
18 const prefix string = ",\"st\":"
19 if first {
20 first = false
21 out.RawString(prefix[1:])
22 } else {
23 out.RawString(prefix)
24 }
25 out.Int(v.St)
26 }
27 {
28 const prefix string = ",\"sid\":"
29 if first {
30 first = false
31 out.RawString(prefix[1:])
32 } else {
33 out.RawString(prefix)
34 }
35 out.Int(v.Sid)
36 }
37 {
38 const prefix string = ",\"tt\":"
39 if first {
40 first = false
41 out.RawString(prefix[1:])
42 } else {
43 out.RawString(prefix)
44 }
45 out.String(v.Tt)
46 }
47 {
48 const prefix string = ",\"gr\":"
49 if first {
50 first = false
51 out.RawString(prefix[1:])
52 } else {
53 out.RawString(prefix)
54 }
55 out.Int(v.Gr)
56 }
57 {
58 const prefix string = ",\"uuid\":"
59 if first {
60 first = false
61 out.RawString(prefix[1:])
62 } else {
63 out.RawString(prefix)
64 }
65 out.String(v.UUID)
66 }
67 {
68 const prefix string = ",\"ip\":"
69 if first {
70 first = false
71 out.RawString(prefix[1:])
72 } else {
73 out.RawString(prefix)
74 }
75 out.String(v.IP)
76 }
77 {
78 const prefix string = ",\"ua\":"
79 if first {
80 first = false
81 out.RawString(prefix[1:])
82 } else {
83 out.RawString(prefix)
84 }
85 out.String(v.Ua)
86 }
87 {
88 const prefix string = ",\"tz\":"
89 if first {
90 first = false
91 out.RawString(prefix[1:])
92 } else {
93 out.RawString(prefix)
94 }
95 out.Int(v.Tz)
96 }
97 {
98 const prefix string = ",\"v\":"
99 if first {
100 out.RawString(prefix[1:])
101 } else {
102 out.RawString(prefix)
103 }
104 out.Int(v.V)
105 }
106 out.RawByte('}')
107 }
108
109 // UnmarshalEasyJSON supports easyjson.Unmarshaler interface
110 func (v *SmallPayload) UnmarshalEasyJSON(in *jlexer.Lexer) {
111 isTopLevel := in.IsStart()
112 if in.IsNull() {
113 if isTopLevel {
114 in.Consumed()
115 }
116 in.Skip()
117 return
118 }
119 in.Delim('{')
120 for !in.IsDelim('}') {
121 key := in.UnsafeString()
122 in.WantColon()
123 if in.IsNull() {
124 in.Skip()
125 in.WantComma()
126 continue
127 }
128 switch key {
129 case "st":
130 v.St = in.Int()
131 case "sid":
132 v.Sid = in.Int()
133 case "tt":
134 v.Tt = in.String()
135 case "gr":
136 v.Gr = in.Int()
137 case "uuid":
138 v.UUID = in.String()
139 case "ip":
140 v.IP = in.String()
141 case "ua":
142 v.Ua = in.String()
143 case "tz":
144 v.Tz = in.Int()
145 case "v":
146 v.V = in.Int()
147 default:
148 in.SkipRecursive()
149 }
150 in.WantComma()
151 }
152 in.Delim('}')
153 if isTopLevel {
154 in.Consumed()
155 }
156 }
157
158 func (v MediumPayload) MarshalEasyJSON(out *jwriter.Writer) {
159 out.RawByte('{')
160 first := true
161 {
162 const prefix string = ",\"person\":"
163 if first {
164 first = false
165 out.RawString(prefix[1:])
166 } else {
167 out.RawString(prefix)
168 }
169 if v.Person == nil {
170 out.RawString("null")
171 } else {
172 v.Person.MarshalEasyJSON(out)
173 }
174 }
175 {
176 const prefix string = ",\"company\":"
177 if first {
178 out.RawString(prefix[1:])
179 } else {
180 out.RawString(prefix)
181 }
182 out.String(v.Company)
183 }
184 out.RawByte('}')
185 }
186
187 func (v *MediumPayload) UnmarshalEasyJSON(in *jlexer.Lexer) {
188 isTopLevel := in.IsStart()
189 if in.IsNull() {
190 if isTopLevel {
191 in.Consumed()
192 }
193 in.Skip()
194 return
195 }
196 in.Delim('{')
197 for !in.IsDelim('}') {
198 key := in.UnsafeString()
199 in.WantColon()
200 if in.IsNull() {
201 in.Skip()
202 in.WantComma()
203 continue
204 }
205 switch key {
206 case "person":
207 if in.IsNull() {
208 in.Skip()
209 v.Person = nil
210 } else {
211 if v.Person == nil {
212 v.Person = new(CBPerson)
213 }
214 v.Person.UnmarshalEasyJSON(in)
215 }
216 case "company":
217 v.Company = in.String()
218 default:
219 in.SkipRecursive()
220 }
221 in.WantComma()
222 }
223 in.Delim('}')
224 if isTopLevel {
225 in.Consumed()
226 }
227 }
228
229 func (v CBPerson) MarshalEasyJSON(out *jwriter.Writer) {
230 out.RawByte('{')
231 first := true
232 {
233 const prefix string = ",\"name\":"
234 if first {
235 first = false
236 out.RawString(prefix[1:])
237 } else {
238 out.RawString(prefix)
239 }
240 if v.Name == nil {
241 out.RawString("null")
242 } else {
243 v.Name.MarshalEasyJSON(out)
244 }
245 }
246 {
247 const prefix string = ",\"github\":"
248 if first {
249 first = false
250 out.RawString(prefix[1:])
251 } else {
252 out.RawString(prefix)
253 }
254 if v.Github == nil {
255 out.RawString("null")
256 } else {
257 v.Github.MarshalEasyJSON(out)
258 }
259 }
260 {
261 const prefix string = ",\"gravatar\":"
262 if first {
263 out.RawString(prefix[1:])
264 } else {
265 out.RawString(prefix)
266 }
267 if v.Gravatar == nil {
268 out.RawString("null")
269 } else {
270 v.Gravatar.MarshalEasyJSON(out)
271 }
272 }
273 out.RawByte('}')
274 }
275
276 func (v *CBPerson) UnmarshalEasyJSON(in *jlexer.Lexer) {
277 isTopLevel := in.IsStart()
278 if in.IsNull() {
279 if isTopLevel {
280 in.Consumed()
281 }
282 in.Skip()
283 return
284 }
285 in.Delim('{')
286 for !in.IsDelim('}') {
287 key := in.UnsafeString()
288 in.WantColon()
289 if in.IsNull() {
290 in.Skip()
291 in.WantComma()
292 continue
293 }
294 switch key {
295 case "name":
296 if in.IsNull() {
297 in.Skip()
298 v.Name = nil
299 } else {
300 if v.Name == nil {
301 v.Name = new(CBName)
302 }
303 v.Name.UnmarshalEasyJSON(in)
304 }
305 case "github":
306 if in.IsNull() {
307 in.Skip()
308 v.Github = nil
309 } else {
310 if v.Github == nil {
311 v.Github = new(CBGithub)
312 }
313 v.Github.UnmarshalEasyJSON(in)
314 }
315 case "gravatar":
316 if in.IsNull() {
317 in.Skip()
318 v.Gravatar = nil
319 } else {
320 if v.Gravatar == nil {
321 v.Gravatar = new(CBGravatar)
322 }
323 v.Gravatar.UnmarshalEasyJSON(in)
324 }
325 default:
326 in.SkipRecursive()
327 }
328 in.WantComma()
329 }
330 in.Delim('}')
331 if isTopLevel {
332 in.Consumed()
333 }
334 }
335
336 func (v CBName) MarshalEasyJSON(out *jwriter.Writer) {
337 out.RawByte('{')
338 first := true
339 {
340 const prefix string = ",\"fullName\":"
341 if first {
342 out.RawString(prefix[1:])
343 } else {
344 out.RawString(prefix)
345 }
346 out.String(v.FullName)
347 }
348 out.RawByte('}')
349 }
350
351 func (v *CBName) UnmarshalEasyJSON(in *jlexer.Lexer) {
352 isTopLevel := in.IsStart()
353 if in.IsNull() {
354 if isTopLevel {
355 in.Consumed()
356 }
357 in.Skip()
358 return
359 }
360 in.Delim('{')
361 for !in.IsDelim('}') {
362 key := in.UnsafeString()
363 in.WantColon()
364 if in.IsNull() {
365 in.Skip()
366 in.WantComma()
367 continue
368 }
369 switch key {
370 case "fullName":
371 v.FullName = in.String()
372 default:
373 in.SkipRecursive()
374 }
375 in.WantComma()
376 }
377 in.Delim('}')
378 if isTopLevel {
379 in.Consumed()
380 }
381 }
382
383 func (v CBGithub) MarshalEasyJSON(out *jwriter.Writer) {
384 out.RawByte('{')
385 {
386 const prefix string = ",\"followers\":"
387 out.RawString(prefix[1:])
388 out.Int(v.Followers)
389 }
390 out.RawByte('}')
391 }
392
393 func (v *CBGithub) UnmarshalEasyJSON(in *jlexer.Lexer) {
394 isTopLevel := in.IsStart()
395 if in.IsNull() {
396 if isTopLevel {
397 in.Consumed()
398 }
399 in.Skip()
400 return
401 }
402 in.Delim('{')
403 for !in.IsDelim('}') {
404 key := in.UnsafeString()
405 in.WantColon()
406 if in.IsNull() {
407 in.Skip()
408 in.WantComma()
409 continue
410 }
411 switch key {
412 case "followers":
413 v.Followers = in.Int()
414 default:
415 in.SkipRecursive()
416 }
417 in.WantComma()
418 }
419 in.Delim('}')
420 if isTopLevel {
421 in.Consumed()
422 }
423 }
424
425 func (v CBGravatar) MarshalEasyJSON(out *jwriter.Writer) {
426 out.RawByte('{')
427 {
428 const prefix string = ",\"avatars\":"
429 out.RawString(prefix[1:])
430
431 if v.Avatars == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
432 out.RawString("null")
433 } else {
434 out.RawByte('[')
435 for v2, v3 := range v.Avatars {
436 if v2 > 0 {
437 out.RawByte(',')
438 }
439 if v3 == nil {
440 out.RawString("null")
441 } else {
442 v3.MarshalEasyJSON(out)
443 }
444 }
445 out.RawByte(']')
446 }
447 }
448 out.RawByte('}')
449 }
450
451 func (v *CBGravatar) UnmarshalEasyJSON(in *jlexer.Lexer) {
452 isTopLevel := in.IsStart()
453 if in.IsNull() {
454 if isTopLevel {
455 in.Consumed()
456 }
457 in.Skip()
458 return
459 }
460 in.Delim('{')
461 for !in.IsDelim('}') {
462 key := in.UnsafeString()
463 in.WantColon()
464 if in.IsNull() {
465 in.Skip()
466 in.WantComma()
467 continue
468 }
469 switch key {
470 case "avatars":
471 if in.IsNull() {
472 in.Skip()
473 v.Avatars = nil
474 } else {
475 in.Delim('[')
476 if v.Avatars == nil {
477 if !in.IsDelim(']') {
478 v.Avatars = make(Avatars, 0, defaultEasyJSONAlloc)
479 } else {
480 v.Avatars = Avatars{}
481 }
482 } else {
483 v.Avatars = (v.Avatars)[:0]
484 }
485 for !in.IsDelim(']') {
486 var v1 *CBAvatar
487 if in.IsNull() {
488 in.Skip()
489 v1 = nil
490 } else {
491 if v1 == nil {
492 v1 = new(CBAvatar)
493 }
494 v1.UnmarshalEasyJSON(in)
495 }
496 v.Avatars = append(v.Avatars, v1)
497 in.WantComma()
498 }
499 in.Delim(']')
500 }
501 default:
502 in.SkipRecursive()
503 }
504 in.WantComma()
505 }
506 in.Delim('}')
507 if isTopLevel {
508 in.Consumed()
509 }
510 }
511
512 func (v CBAvatar) MarshalEasyJSON(out *jwriter.Writer) {
513 out.RawByte('{')
514 {
515 const prefix string = ",\"url\":"
516 out.RawString(prefix[1:])
517 out.String(v.URL)
518 }
519 out.RawByte('}')
520 }
521
522 func (v *CBAvatar) UnmarshalEasyJSON(in *jlexer.Lexer) {
523 isTopLevel := in.IsStart()
524 if in.IsNull() {
525 if isTopLevel {
526 in.Consumed()
527 }
528 in.Skip()
529 return
530 }
531 in.Delim('{')
532 for !in.IsDelim('}') {
533 key := in.UnsafeString()
534 in.WantColon()
535 if in.IsNull() {
536 in.Skip()
537 in.WantComma()
538 continue
539 }
540 switch key {
541 case "url":
542 v.URL = in.String()
543 default:
544 in.SkipRecursive()
545 }
546 in.WantComma()
547 }
548 in.Delim('}')
549 if isTopLevel {
550 in.Consumed()
551 }
552 }
553
554 func (v LargePayload) MarshalEasyJSON(out *jwriter.Writer) {
555 out.RawByte('{')
556 first := true
557 {
558 const prefix string = ",\"users\":"
559 if first {
560 first = false
561 out.RawString(prefix[1:])
562 } else {
563 out.RawString(prefix)
564 }
565 if v.Users == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
566 out.RawString("null")
567 } else {
568 out.RawByte('[')
569 for v2, v3 := range v.Users {
570 if v2 > 0 {
571 out.RawByte(',')
572 }
573 if v3 == nil {
574 out.RawString("null")
575 } else {
576 v3.MarshalEasyJSON(out)
577 }
578 }
579 out.RawByte(']')
580 }
581 }
582 {
583 const prefix string = ",\"topics\":"
584 if first {
585 out.RawString(prefix[1:])
586 } else {
587 out.RawString(prefix)
588 }
589 if v.Topics == nil {
590 out.RawString("null")
591 } else {
592 v.Topics.MarshalEasyJSON(out)
593 }
594 }
595 out.RawByte('}')
596 }
597
598 func (v *LargePayload) UnmarshalEasyJSON(in *jlexer.Lexer) {
599 isTopLevel := in.IsStart()
600 if in.IsNull() {
601 if isTopLevel {
602 in.Consumed()
603 }
604 in.Skip()
605 return
606 }
607 in.Delim('{')
608 for !in.IsDelim('}') {
609 key := in.UnsafeString()
610 in.WantColon()
611 if in.IsNull() {
612 in.Skip()
613 in.WantComma()
614 continue
615 }
616 switch key {
617 case "users":
618 if in.IsNull() {
619 in.Skip()
620 v.Users = nil
621 } else {
622 in.Delim('[')
623 if v.Users == nil {
624 if !in.IsDelim(']') {
625 v.Users = make(DSUsers, 0, defaultEasyJSONAlloc)
626 } else {
627 v.Users = DSUsers{}
628 }
629 } else {
630 v.Users = (v.Users)[:0]
631 }
632 for !in.IsDelim(']') {
633 var v1 *DSUser
634 if in.IsNull() {
635 in.Skip()
636 v1 = nil
637 } else {
638 if v1 == nil {
639 v1 = new(DSUser)
640 }
641 v1.UnmarshalEasyJSON(in)
642 }
643 v.Users = append(v.Users, v1)
644 in.WantComma()
645 }
646 in.Delim(']')
647 }
648 case "topics":
649 if in.IsNull() {
650 in.Skip()
651 v.Topics = nil
652 } else {
653 if v.Topics == nil {
654 v.Topics = new(DSTopicsList)
655 }
656 v.Topics.UnmarshalEasyJSON(in)
657 }
658 default:
659 in.SkipRecursive()
660 }
661 in.WantComma()
662 }
663 in.Delim('}')
664 if isTopLevel {
665 in.Consumed()
666 }
667 }
668
669 func (v DSUser) MarshalEasyJSON(out *jwriter.Writer) {
670 out.RawByte('{')
671 {
672 const prefix string = ",\"username\":"
673 out.RawString(prefix[1:])
674 out.String(v.Username)
675 }
676 out.RawByte('}')
677 }
678
679 func (v *DSUser) UnmarshalEasyJSON(in *jlexer.Lexer) {
680 isTopLevel := in.IsStart()
681 if in.IsNull() {
682 if isTopLevel {
683 in.Consumed()
684 }
685 in.Skip()
686 return
687 }
688 in.Delim('{')
689 for !in.IsDelim('}') {
690 key := in.UnsafeString()
691 in.WantColon()
692 if in.IsNull() {
693 in.Skip()
694 in.WantComma()
695 continue
696 }
697 switch key {
698 case "username":
699 v.Username = in.String()
700 default:
701 in.SkipRecursive()
702 }
703 in.WantComma()
704 }
705 in.Delim('}')
706 if isTopLevel {
707 in.Consumed()
708 }
709 }
710
711 func (v DSTopicsList) MarshalEasyJSON(out *jwriter.Writer) {
712 out.RawByte('{')
713 first := true
714 {
715 const prefix string = ",\"topics\":"
716 if first {
717 first = false
718 out.RawString(prefix[1:])
719 } else {
720 out.RawString(prefix)
721 }
722 if v.Topics == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
723 out.RawString("null")
724 } else {
725 out.RawByte('[')
726 for v5, v6 := range v.Topics {
727 if v5 > 0 {
728 out.RawByte(',')
729 }
730 if v6 == nil {
731 out.RawString("null")
732 } else {
733 v6.MarshalEasyJSON(out)
734 }
735 }
736 out.RawByte(']')
737 }
738 }
739 {
740 const prefix string = ",\"moreTopicsURL\":"
741 if first {
742 out.RawString(prefix[1:])
743 } else {
744 out.RawString(prefix)
745 }
746 out.String(v.MoreTopicsURL)
747 }
748 out.RawByte('}')
749 }
750
751 func (v *DSTopicsList) UnmarshalEasyJSON(in *jlexer.Lexer) {
752 isTopLevel := in.IsStart()
753 if in.IsNull() {
754 if isTopLevel {
755 in.Consumed()
756 }
757 in.Skip()
758 return
759 }
760 in.Delim('{')
761 for !in.IsDelim('}') {
762 key := in.UnsafeString()
763 in.WantColon()
764 if in.IsNull() {
765 in.Skip()
766 in.WantComma()
767 continue
768 }
769 switch key {
770 case "topics":
771 if in.IsNull() {
772 in.Skip()
773 v.Topics = nil
774 } else {
775 in.Delim('[')
776 if v.Topics == nil {
777 if !in.IsDelim(']') {
778 v.Topics = make(DSTopics, 0, defaultEasyJSONAlloc)
779 } else {
780 v.Topics = DSTopics{}
781 }
782 } else {
783 v.Topics = (v.Topics)[:0]
784 }
785 for !in.IsDelim(']') {
786 var v4 *DSTopic
787 if in.IsNull() {
788 in.Skip()
789 v4 = nil
790 } else {
791 if v4 == nil {
792 v4 = new(DSTopic)
793 }
794 v4.UnmarshalEasyJSON(in)
795 }
796 v.Topics = append(v.Topics, v4)
797 in.WantComma()
798 }
799 in.Delim(']')
800 }
801 case "moreTopicsURL":
802 v.MoreTopicsURL = in.String()
803 default:
804 in.SkipRecursive()
805 }
806 in.WantComma()
807 }
808 in.Delim('}')
809 if isTopLevel {
810 in.Consumed()
811 }
812 }
813
814 func (v DSTopic) MarshalEasyJSON(out *jwriter.Writer) {
815 out.RawByte('{')
816 first := true
817 {
818 const prefix string = ",\"id\":"
819 if first {
820 first = false
821 out.RawString(prefix[1:])
822 } else {
823 out.RawString(prefix)
824 }
825 out.Int(v.ID)
826 }
827 {
828 const prefix string = ",\"slug\":"
829 if first {
830 out.RawString(prefix[1:])
831 } else {
832 out.RawString(prefix)
833 }
834 out.String(v.Slug)
835 }
836 out.RawByte('}')
837 }
838
839 func (v *DSTopic) UnmarshalEasyJSON(in *jlexer.Lexer) {
840 isTopLevel := in.IsStart()
841 if in.IsNull() {
842 if isTopLevel {
843 in.Consumed()
844 }
845 in.Skip()
846 return
847 }
848 in.Delim('{')
849 for !in.IsDelim('}') {
850 key := in.UnsafeString()
851 in.WantColon()
852 if in.IsNull() {
853 in.Skip()
854 in.WantComma()
855 continue
856 }
857 switch key {
858 case "id":
859 v.ID = in.Int()
860 case "slug":
861 v.Slug = in.String()
862 default:
863 in.SkipRecursive()
864 }
865 in.WantComma()
866 }
867 in.Delim('}')
868 if isTopLevel {
869 in.Consumed()
870 }
871 }