Debian Codegraph @

benchmarks/medium_payload.go

raw
1 package benchmark
2
3 import "github.com/francoispqt/gojay"
4
5 // Response from Clearbit API. Size: 2.4kb
6 var MediumFixture = []byte(`{
7 "person": {
8 "id": "d50887ca-a6ce-4e59-b89f-14f0b5d03b03",
9 "name": {
10 "fullName": "Leonid Bugaev",
11 "givenName": "Leonid",
12 "familyName": "Bugaev"
13 },
14 "email": "[email protected]",
15 "gender": "male",
16 "location": "Saint Petersburg, Saint Petersburg, RU",
17 "geo": {
18 "city": "Saint Petersburg",
19 "state": "Saint Petersburg",
20 "country": "Russia",
21 "lat": 59.9342802,
22 "lng": 30.3350986
23 },
24 "bio": "Senior engineer at Granify.com",
25 "site": "http://flickfaver.com",
26 "avatar": "https://d1ts43dypk8bqh.cloudfront.net/v1/avatars/d50887ca-a6ce-4e59-b89f-14f0b5d03b03",
27 "employment": {
28 "name": "www.latera.ru",
29 "title": "Software Engineer",
30 "domain": "gmail.com"
31 },
32 "facebook": {
33 "handle": "leonid.bugaev"
34 },
35 "github": {
36 "handle": "buger",
37 "id": 14009,
38 "avatar": "https://avatars.githubusercontent.com/u/14009?v=3",
39 "company": "Granify",
40 "blog": "http://leonsbox.com",
41 "followers": 95,
42 "following": 10
43 },
44 "twitter": {
45 "handle": "flickfaver",
46 "id": 77004410,
47 "bio": null,
48 "followers": 2,
49 "following": 1,
50 "statuses": 5,
51 "favorites": 0,
52 "location": "",
53 "site": "http://flickfaver.com",
54 "avatar": null
55 },
56 "linkedin": {
57 "handle": "in/leonidbugaev"
58 },
59 "googleplus": {
60 "handle": null
61 },
62 "angellist": {
63 "handle": "leonid-bugaev",
64 "id": 61541,
65 "bio": "Senior engineer at Granify.com",
66 "blog": "http://buger.github.com",
67 "site": "http://buger.github.com",
68 "followers": 41,
69 "avatar": "https://d1qb2nb5cznatu.cloudfront.net/users/61541-medium_jpg?1405474390"
70 },
71 "klout": {
72 "handle": null,
73 "score": null
74 },
75 "foursquare": {
76 "handle": null
77 },
78 "aboutme": {
79 "handle": "leonid.bugaev",
80 "bio": null,
81 "avatar": null
82 },
83 "gravatar": {
84 "handle": "buger",
85 "urls": [
86 ],
87 "avatar": "http://1.gravatar.com/avatar/f7c8edd577d13b8930d5522f28123510",
88 "avatars": [
89 {
90 "url": "http://1.gravatar.com/avatar/f7c8edd577d13b8930d5522f28123510",
91 "type": "thumbnail"
92 }
93 ]
94 },
95 "fuzzy": false
96 },
97 "company": null
98 }`)
99
100 type CBAvatar struct {
101 Url string
102 }
103
104 func (m *CBAvatar) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
105 switch key {
106 case "avatars":
107 return dec.AddString(&m.Url)
108 }
109 return nil
110 }
111 func (m *CBAvatar) NKeys() int {
112 return 1
113 }
114
115 func (m *CBAvatar) MarshalJSONObject(enc *gojay.Encoder) {
116 enc.AddStringKey("url", m.Url)
117 }
118
119 func (m *CBAvatar) IsNil() bool {
120 return m == nil
121 }
122
123 type Avatars []*CBAvatar
124
125 func (t *Avatars) UnmarshalJSONArray(dec *gojay.Decoder) error {
126 avatar := CBAvatar{}
127 *t = append(*t, &avatar)
128 return dec.AddObject(&avatar)
129 }
130
131 func (m *Avatars) MarshalJSONArray(enc *gojay.Encoder) {
132 for _, e := range *m {
133 enc.AddObject(e)
134 }
135 }
136 func (m *Avatars) IsNil() bool {
137 return m == nil
138 }
139
140 type CBGravatar struct {
141 Avatars Avatars
142 }
143
144 func (m *CBGravatar) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
145 switch key {
146 case "avatars":
147 return dec.AddArray(&m.Avatars)
148 }
149 return nil
150 }
151 func (m *CBGravatar) NKeys() int {
152 return 1
153 }
154
155 func (m *CBGravatar) MarshalJSONObject(enc *gojay.Encoder) {
156 enc.AddArrayKey("avatars", &m.Avatars)
157 }
158
159 func (m *CBGravatar) IsNil() bool {
160 return m == nil
161 }
162
163 type CBGithub struct {
164 Followers int
165 }
166
167 func (m *CBGithub) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
168 switch key {
169 case "followers":
170 return dec.AddInt(&m.Followers)
171 }
172 return nil
173 }
174
175 func (m *CBGithub) NKeys() int {
176 return 1
177 }
178
179 func (m *CBGithub) MarshalJSONObject(enc *gojay.Encoder) {
180 enc.AddIntKey("followers", m.Followers)
181 }
182
183 func (m *CBGithub) IsNil() bool {
184 return m == nil
185 }
186
187 type CBName struct {
188 FullName string `json:"fullName"`
189 }
190
191 func (m *CBName) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
192 switch key {
193 case "fullName":
194 return dec.AddString(&m.FullName)
195 }
196 return nil
197 }
198
199 func (m *CBName) NKeys() int {
200 return 1
201 }
202
203 func (m *CBName) MarshalJSONObject(enc *gojay.Encoder) {
204 enc.AddStringKey("fullName", m.FullName)
205 }
206
207 func (m *CBName) IsNil() bool {
208 return m == nil
209 }
210
211 type CBPerson struct {
212 Name *CBName `json:"name"`
213 Github *CBGithub `json:"github"`
214 Gravatar *CBGravatar
215 }
216
217 func (m *CBPerson) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
218 switch key {
219 case "name":
220 m.Name = &CBName{}
221 return dec.AddObject(m.Name)
222 case "github":
223 m.Github = &CBGithub{}
224 return dec.AddObject(m.Github)
225 case "gravatar":
226 m.Gravatar = &CBGravatar{}
227 return dec.AddObject(m.Gravatar)
228 }
229 return nil
230 }
231
232 func (m *CBPerson) NKeys() int {
233 return 3
234 }
235
236 func (m *CBPerson) MarshalJSONObject(enc *gojay.Encoder) {
237 enc.AddObjectKey("name", m.Name)
238 enc.AddObjectKey("github", m.Github)
239 enc.AddObjectKey("gravatar", m.Gravatar)
240 }
241
242 func (m *CBPerson) IsNil() bool {
243 return m == nil
244 }
245
246 type MediumPayload struct {
247 Person *CBPerson `json:"person"`
248 Company string `json:"company"`
249 }
250
251 //easyjson:json
252 type MediumPayloadEasyJson struct {
253 Person *CBPerson `json:"person"`
254 Company string `json:"company"`
255 }
256
257 func (m *MediumPayload) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
258 switch key {
259 case "person":
260 m.Person = &CBPerson{}
261 return dec.AddObject(m.Person)
262 case "company":
263 dec.AddString(&m.Company)
264 }
265 return nil
266 }
267
268 func (m *MediumPayload) NKeys() int {
269 return 2
270 }
271
272 func (m *MediumPayload) MarshalJSONObject(enc *gojay.Encoder) {
273 enc.AddObjectKey("person", m.Person)
274 // enc.AddStringKey("company", m.Company)
275 }
276
277 func (m *MediumPayload) IsNil() bool {
278 return m == nil
279 }
280
281 func NewMediumPayload() *MediumPayload {
282 return &MediumPayload{
283 Company: "test",
284 Person: &CBPerson{
285 Name: &CBName{
286 FullName: "test",
287 },
288 Github: &CBGithub{
289 Followers: 100,
290 },
291 Gravatar: &CBGravatar{
292 Avatars: Avatars{
293 &CBAvatar{
294 Url: "http://test.com",
295 },
296 &CBAvatar{
297 Url: "http://test.com",
298 },
299 &CBAvatar{
300 Url: "http://test.com",
301 },
302 &CBAvatar{
303 Url: "http://test.com",
304 },
305 &CBAvatar{
306 Url: "http://test.com",
307 },
308 &CBAvatar{
309 Url: "http://test.com",
310 },
311 &CBAvatar{
312 Url: "http://test.com",
313 },
314 &CBAvatar{
315 Url: "http://test.com",
316 },
317 },
318 },
319 },
320 }
321 }
322
323 func NewMediumPayloadEasyJson() *MediumPayloadEasyJson {
324 return &MediumPayloadEasyJson{
325 Company: "test",
326 Person: &CBPerson{
327 Name: &CBName{
328 FullName: "test",
329 },
330 Github: &CBGithub{
331 Followers: 100,
332 },
333 Gravatar: &CBGravatar{
334 Avatars: Avatars{
335 &CBAvatar{
336 Url: "http://test.com",
337 },
338 &CBAvatar{
339 Url: "http://test.com",
340 },
341 &CBAvatar{
342 Url: "http://test.com",
343 },
344 &CBAvatar{
345 Url: "http://test.com",
346 },
347 &CBAvatar{
348 Url: "http://test.com",
349 },
350 &CBAvatar{
351 Url: "http://test.com",
352 },
353 &CBAvatar{
354 Url: "http://test.com",
355 },
356 &CBAvatar{
357 Url: "http://test.com",
358 },
359 },
360 },
361 },
362 }
363 }