| 1 |
package benchmark |
| 2 |
|
| 3 |
import "github.com/francoispqt/gojay" |
| 4 |
|
| 5 |
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}`) |
| 6 |
|
| 7 |
// ffjson:skip |
| 8 |
type SmallPayload struct { |
| 9 |
St int |
| 10 |
Sid int |
| 11 |
Tt string |
| 12 |
Gr int |
| 13 |
Uuid string |
| 14 |
Ip string |
| 15 |
Ua string |
| 16 |
Tz int |
| 17 |
V int |
| 18 |
} |
| 19 |
|
| 20 |
type SmallPayloadFFJson struct { |
| 21 |
St int |
| 22 |
Sid int |
| 23 |
Tt string |
| 24 |
Gr int |
| 25 |
Uuid string |
| 26 |
Ip string |
| 27 |
Ua string |
| 28 |
Tz int |
| 29 |
V int |
| 30 |
} |
| 31 |
|
| 32 |
//easyjson:json |
| 33 |
type SmallPayloadEasyJson struct { |
| 34 |
St int |
| 35 |
Sid int |
| 36 |
Tt string |
| 37 |
Gr int |
| 38 |
Uuid string |
| 39 |
Ip string |
| 40 |
Ua string |
| 41 |
Tz int |
| 42 |
V int |
| 43 |
} |
| 44 |
|
| 45 |
func (t *SmallPayload) MarshalJSONObject(enc *gojay.Encoder) { |
| 46 |
enc.AddIntKey("st", t.St) |
| 47 |
enc.AddIntKey("sid", t.Sid) |
| 48 |
enc.AddStringKey("tt", t.Tt) |
| 49 |
enc.AddIntKey("gr", t.Gr) |
| 50 |
enc.AddStringKey("uuid", t.Uuid) |
| 51 |
enc.AddStringKey("ip", t.Ip) |
| 52 |
enc.AddStringKey("ua", t.Ua) |
| 53 |
enc.AddIntKey("tz", t.Tz) |
| 54 |
enc.AddIntKey("v", t.V) |
| 55 |
} |
| 56 |
|
| 57 |
func (t *SmallPayload) IsNil() bool { |
| 58 |
return t == nil |
| 59 |
} |
| 60 |
|
| 61 |
func (t *SmallPayload) UnmarshalJSONObject(dec *gojay.Decoder, key string) error { |
| 62 |
switch key { |
| 63 |
case "st": |
| 64 |
return dec.AddInt(&t.St) |
| 65 |
case "sid": |
| 66 |
return dec.AddInt(&t.Sid) |
| 67 |
case "gr": |
| 68 |
return dec.AddInt(&t.Gr) |
| 69 |
case "tz": |
| 70 |
return dec.AddInt(&t.Tz) |
| 71 |
case "v": |
| 72 |
return dec.AddInt(&t.V) |
| 73 |
case "tt": |
| 74 |
return dec.AddString(&t.Tt) |
| 75 |
case "uuid": |
| 76 |
return dec.AddString(&t.Uuid) |
| 77 |
case "ip": |
| 78 |
return dec.AddString(&t.Ip) |
| 79 |
case "ua": |
| 80 |
return dec.AddString(&t.Ua) |
| 81 |
} |
| 82 |
return nil |
| 83 |
} |
| 84 |
|
| 85 |
func (t *SmallPayload) NKeys() int { |
| 86 |
return 9 |
| 87 |
} |
| 88 |
|
| 89 |
func NewSmallPayload() *SmallPayload { |
| 90 |
return &SmallPayload{ |
| 91 |
St: 1, |
| 92 |
Sid: 2, |
| 93 |
Tt: "TestString", |
| 94 |
Gr: 4, |
| 95 |
Uuid: "8f9a65eb-4807-4d57-b6e0-bda5d62f1429", |
| 96 |
Ip: "127.0.0.1", |
| 97 |
Ua: "Mozilla", |
| 98 |
Tz: 8, |
| 99 |
V: 6, |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
func NewSmallPayloadEasyJson() *SmallPayloadEasyJson { |
| 104 |
return &SmallPayloadEasyJson{ |
| 105 |
St: 1, |
| 106 |
Sid: 2, |
| 107 |
Tt: "TestString", |
| 108 |
Gr: 4, |
| 109 |
Uuid: "8f9a65eb-4807-4d57-b6e0-bda5d62f1429", |
| 110 |
Ip: "127.0.0.1", |
| 111 |
Ua: "Mozilla", |
| 112 |
Tz: 8, |
| 113 |
V: 6, |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
func NewSmallPayloadFFJson() *SmallPayloadFFJson { |
| 118 |
return &SmallPayloadFFJson{ |
| 119 |
St: 1, |
| 120 |
Sid: 2, |
| 121 |
Tt: "TestString", |
| 122 |
Gr: 4, |
| 123 |
Uuid: "8f9a65eb-4807-4d57-b6e0-bda5d62f1429", |
| 124 |
Ip: "127.0.0.1", |
| 125 |
Ua: "Mozilla", |
| 126 |
Tz: 8, |
| 127 |
V: 6, |
| 128 |
} |
| 129 |
} |