forked from goccy/go-json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmall_payload.go
129 lines (117 loc) · 2.27 KB
/
small_payload.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
package benchmark
import "github.com/francoispqt/gojay"
var SmallFixture = []byte(`{"st": 1,"sid": 486,"tt": "active","gr": 0,"uuid": "de305d54-75b4-431b-adb2-eb6b9e546014","ip": "127.0.0.1","ua": "user_agent","tz": -6,"v": 1}`)
// ffjson:skip
type SmallPayload struct {
St int
Sid int
Tt string
Gr int
Uuid string
Ip string
Ua string
Tz int
V int
}
type SmallPayloadFFJson struct {
St int
Sid int
Tt string
Gr int
Uuid string
Ip string
Ua string
Tz int
V int
}
//easyjson:json
type SmallPayloadEasyJson struct {
St int
Sid int
Tt string
Gr int
Uuid string
Ip string
Ua string
Tz int
V int
}
func (t *SmallPayload) MarshalJSONObject(enc *gojay.Encoder) {
enc.AddIntKey("st", t.St)
enc.AddIntKey("sid", t.Sid)
enc.AddStringKey("tt", t.Tt)
enc.AddIntKey("gr", t.Gr)
enc.AddStringKey("uuid", t.Uuid)
enc.AddStringKey("ip", t.Ip)
enc.AddStringKey("ua", t.Ua)
enc.AddIntKey("tz", t.Tz)
enc.AddIntKey("v", t.V)
}
func (t *SmallPayload) IsNil() bool {
return t == nil
}
func (t *SmallPayload) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
switch key {
case "st":
return dec.AddInt(&t.St)
case "sid":
return dec.AddInt(&t.Sid)
case "gr":
return dec.AddInt(&t.Gr)
case "tz":
return dec.AddInt(&t.Tz)
case "v":
return dec.AddInt(&t.V)
case "tt":
return dec.AddString(&t.Tt)
case "uuid":
return dec.AddString(&t.Uuid)
case "ip":
return dec.AddString(&t.Ip)
case "ua":
return dec.AddString(&t.Ua)
}
return nil
}
func (t *SmallPayload) NKeys() int {
return 9
}
func NewSmallPayload() *SmallPayload {
return &SmallPayload{
St: 1,
Sid: 2,
Tt: "TestString",
Gr: 4,
Uuid: "8f9a65eb-4807-4d57-b6e0-bda5d62f1429",
Ip: "127.0.0.1",
Ua: "Mozilla",
Tz: 8,
V: 6,
}
}
func NewSmallPayloadEasyJson() *SmallPayloadEasyJson {
return &SmallPayloadEasyJson{
St: 1,
Sid: 2,
Tt: "TestString",
Gr: 4,
Uuid: "8f9a65eb-4807-4d57-b6e0-bda5d62f1429",
Ip: "127.0.0.1",
Ua: "Mozilla",
Tz: 8,
V: 6,
}
}
func NewSmallPayloadFFJson() *SmallPayloadFFJson {
return &SmallPayloadFFJson{
St: 1,
Sid: 2,
Tt: "TestString",
Gr: 4,
Uuid: "8f9a65eb-4807-4d57-b6e0-bda5d62f1429",
Ip: "127.0.0.1",
Ua: "Mozilla",
Tz: 8,
V: 6,
}
}