Debian Codegraph @

jsonutils/adapters/testintegration/benchmarks/payloads.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 "strconv"
7
8 // The definition of these payloads is borrowed from github.com/goccy/go-json.
9
10 type SmallPayload struct {
11 St int `json:"st"`
12 Sid int `json:"sid"`
13 Tt string `json:"tt"`
14 Gr int `json:"gr"`
15 UUID string `json:"uuid"`
16 IP string `json:"ip"`
17 Ua string `json:"ua"`
18 Tz int `json:"tz"`
19 V int `json:"v"`
20 }
21
22 //nolint:mnd
23 func NewSmallPayload() *SmallPayload {
24 return &SmallPayload{
25 St: 1,
26 Sid: 2,
27 Tt: "TestString",
28 Gr: 4,
29 UUID: "8f9a65eb-4807-4d57-b6e0-bda5d62f1429",
30 IP: "127.0.0.1",
31 Ua: "Mozilla",
32 Tz: 8,
33 V: 6,
34 }
35 }
36
37 type MediumPayload struct {
38 Person *CBPerson `json:"person"`
39 Company string `json:"company"`
40 }
41
42 const mediumNumberOfAvatars = 8
43
44 //nolint:mnd
45 func NewMediumPayload() *MediumPayload {
46 p := &MediumPayload{
47 Company: "test",
48 Person: &CBPerson{
49 Name: &CBName{
50 FullName: "test",
51 },
52 Github: &CBGithub{
53 Followers: 100,
54 },
55 Gravatar: &CBGravatar{},
56 },
57 }
58
59 avatars := make(Avatars, mediumNumberOfAvatars)
60 for i := range mediumNumberOfAvatars {
61 avatars[i] = &CBAvatar{
62 URL: "http://test.com",
63 }
64 }
65 p.Person.Gravatar.Avatars = avatars
66
67 return p
68 }
69
70 type CBPerson struct {
71 Name *CBName `json:"name"`
72 Github *CBGithub `json:"github"`
73 Gravatar *CBGravatar `json:"gravatar"`
74 }
75
76 type CBName struct {
77 FullName string `json:"fullName"`
78 }
79
80 type CBGithub struct {
81 Followers int `json:"followers"`
82 }
83
84 type CBGravatar struct {
85 Avatars Avatars `json:"avatars"`
86 }
87
88 type Avatars []*CBAvatar
89
90 type CBAvatar struct {
91 URL string `json:"url"`
92 }
93
94 type LargePayload struct {
95 Users DSUsers `json:"users"`
96 Topics *DSTopicsList `json:"topics"`
97 }
98
99 const largeNumberOfUsers = 100
100
101 func NewLargePayload() *LargePayload {
102 dsUsers := make(DSUsers, largeNumberOfUsers)
103 dsTopics := make(DSTopics, largeNumberOfUsers)
104 for i := range largeNumberOfUsers {
105 str := "test" + strconv.Itoa(i)
106 dsUsers[i] = &DSUser{
107 Username: str,
108 }
109 dsTopics[i] = &DSTopic{
110 ID: i,
111 Slug: str,
112 }
113 }
114
115 return &LargePayload{
116 Users: dsUsers,
117 Topics: &DSTopicsList{
118 Topics: dsTopics,
119 MoreTopicsURL: "http://test.com",
120 },
121 }
122 }
123
124 type DSUser struct {
125 Username string `json:"username"`
126 }
127
128 type DSUsers []*DSUser
129
130 type DSTopicsList struct {
131 Topics DSTopics `json:"topics"`
132 MoreTopicsURL string `json:"moreTopicsURL"`
133 }
134
135 type DSTopic struct {
136 ID int `json:"id"`
137 Slug string `json:"slug"`
138 }
139
140 type DSTopics []*DSTopic