forked from capnproto/go-capnp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msgp_bench_gen_test.go
216 lines (208 loc) · 4.44 KB
/
msgp_bench_gen_test.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//go:build msgpbench
// +build msgpbench
package capnp_test
// NOTE: THIS FILE WAS PRODUCED BY THE
// MSGP CODE GENERATION TOOL (github.com/tinylib/msgp)
// DO NOT EDIT
import (
"github.com/tinylib/msgp/msgp"
)
// DecodeMsg implements msgp.Decodable
func (z *Event) DecodeMsg(dc *msgp.Reader) (err error) {
var field []byte
_ = field
var zxvk uint32
zxvk, err = dc.ReadMapHeader()
if err != nil {
return
}
for zxvk > 0 {
zxvk--
field, err = dc.ReadMapKeyPtr()
if err != nil {
return
}
switch msgp.UnsafeString(field) {
case "Name":
z.Name, err = dc.ReadString()
if err != nil {
return
}
case "BirthDay":
z.BirthDay, err = dc.ReadTime()
if err != nil {
return
}
case "Phone":
z.Phone, err = dc.ReadString()
if err != nil {
return
}
case "Siblings":
z.Siblings, err = dc.ReadInt()
if err != nil {
return
}
case "Spouse":
z.Spouse, err = dc.ReadBool()
if err != nil {
return
}
case "Money":
z.Money, err = dc.ReadFloat64()
if err != nil {
return
}
default:
err = dc.Skip()
if err != nil {
return
}
}
}
return
}
// EncodeMsg implements msgp.Encodable
func (z *Event) EncodeMsg(en *msgp.Writer) (err error) {
// map header, size 6
// write "Name"
err = en.Append(0x86, 0xa4, 0x4e, 0x61, 0x6d, 0x65)
if err != nil {
return err
}
err = en.WriteString(z.Name)
if err != nil {
return
}
// write "BirthDay"
err = en.Append(0xa8, 0x42, 0x69, 0x72, 0x74, 0x68, 0x44, 0x61, 0x79)
if err != nil {
return err
}
err = en.WriteTime(z.BirthDay)
if err != nil {
return
}
// write "Phone"
err = en.Append(0xa5, 0x50, 0x68, 0x6f, 0x6e, 0x65)
if err != nil {
return err
}
err = en.WriteString(z.Phone)
if err != nil {
return
}
// write "Siblings"
err = en.Append(0xa8, 0x53, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x73)
if err != nil {
return err
}
err = en.WriteInt(z.Siblings)
if err != nil {
return
}
// write "Spouse"
err = en.Append(0xa6, 0x53, 0x70, 0x6f, 0x75, 0x73, 0x65)
if err != nil {
return err
}
err = en.WriteBool(z.Spouse)
if err != nil {
return
}
// write "Money"
err = en.Append(0xa5, 0x4d, 0x6f, 0x6e, 0x65, 0x79)
if err != nil {
return err
}
err = en.WriteFloat64(z.Money)
if err != nil {
return
}
return
}
// MarshalMsg implements msgp.Marshaler
func (z *Event) MarshalMsg(b []byte) (o []byte, err error) {
o = msgp.Require(b, z.Msgsize())
// map header, size 6
// string "Name"
o = append(o, 0x86, 0xa4, 0x4e, 0x61, 0x6d, 0x65)
o = msgp.AppendString(o, z.Name)
// string "BirthDay"
o = append(o, 0xa8, 0x42, 0x69, 0x72, 0x74, 0x68, 0x44, 0x61, 0x79)
o = msgp.AppendTime(o, z.BirthDay)
// string "Phone"
o = append(o, 0xa5, 0x50, 0x68, 0x6f, 0x6e, 0x65)
o = msgp.AppendString(o, z.Phone)
// string "Siblings"
o = append(o, 0xa8, 0x53, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x73)
o = msgp.AppendInt(o, z.Siblings)
// string "Spouse"
o = append(o, 0xa6, 0x53, 0x70, 0x6f, 0x75, 0x73, 0x65)
o = msgp.AppendBool(o, z.Spouse)
// string "Money"
o = append(o, 0xa5, 0x4d, 0x6f, 0x6e, 0x65, 0x79)
o = msgp.AppendFloat64(o, z.Money)
return
}
// UnmarshalMsg implements msgp.Unmarshaler
func (z *Event) UnmarshalMsg(bts []byte) (o []byte, err error) {
var field []byte
_ = field
var zbzg uint32
zbzg, bts, err = msgp.ReadMapHeaderBytes(bts)
if err != nil {
return
}
for zbzg > 0 {
zbzg--
field, bts, err = msgp.ReadMapKeyZC(bts)
if err != nil {
return
}
switch msgp.UnsafeString(field) {
case "Name":
z.Name, bts, err = msgp.ReadStringBytes(bts)
if err != nil {
return
}
case "BirthDay":
z.BirthDay, bts, err = msgp.ReadTimeBytes(bts)
if err != nil {
return
}
case "Phone":
z.Phone, bts, err = msgp.ReadStringBytes(bts)
if err != nil {
return
}
case "Siblings":
z.Siblings, bts, err = msgp.ReadIntBytes(bts)
if err != nil {
return
}
case "Spouse":
z.Spouse, bts, err = msgp.ReadBoolBytes(bts)
if err != nil {
return
}
case "Money":
z.Money, bts, err = msgp.ReadFloat64Bytes(bts)
if err != nil {
return
}
default:
bts, err = msgp.Skip(bts)
if err != nil {
return
}
}
}
o = bts
return
}
// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (z *Event) Msgsize() (s int) {
s = 1 + 5 + msgp.StringPrefixSize + len(z.Name) + 9 + msgp.TimeSize + 6 + msgp.StringPrefixSize + len(z.Phone) + 9 + msgp.IntSize + 7 + msgp.BoolSize + 6 + msgp.Float64Size
return
}