forked from alecthomas/go_serialization_benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structdef-bebop-200sc.go
137 lines (124 loc) · 3.1 KB
/
structdef-bebop-200sc.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
// Code generated by bebopc-go; DO NOT EDIT.
package goserbench
import (
"github.com/200sc/bebop"
"github.com/200sc/bebop/iohelp"
"io"
"time"
)
var _ bebop.Record = &BebopBuf200sc{}
type BebopBuf200sc struct {
Name string
BirthDay time.Time
Phone string
Siblings int32
Spouse bool
Money float64
}
func (bbp *BebopBuf200sc) MarshalBebopTo(buf []byte) int {
at := 0
iohelp.WriteUint32Bytes(buf[at:], uint32(len(bbp.Name)))
copy(buf[at+4:at+4+len(bbp.Name)], []byte(bbp.Name))
at += 4 + len(bbp.Name)
if bbp.BirthDay != (time.Time{}) {
iohelp.WriteInt64Bytes(buf[at:], ((bbp.BirthDay).UnixNano() / 100))
} else {
iohelp.WriteInt64Bytes(buf[at:], 0)
}
at += 8
iohelp.WriteUint32Bytes(buf[at:], uint32(len(bbp.Phone)))
copy(buf[at+4:at+4+len(bbp.Phone)], []byte(bbp.Phone))
at += 4 + len(bbp.Phone)
iohelp.WriteInt32Bytes(buf[at:], bbp.Siblings)
at += 4
iohelp.WriteBoolBytes(buf[at:], bbp.Spouse)
at += 1
iohelp.WriteFloat64Bytes(buf[at:], bbp.Money)
at += 8
return at
}
func (bbp *BebopBuf200sc) UnmarshalBebop(buf []byte) (err error) {
at := 0
bbp.Name, err = iohelp.ReadStringBytes(buf[at:])
if err != nil {
return err
}
at += 4 + len(bbp.Name)
if len(buf[at:]) < 8 {
return io.ErrUnexpectedEOF
}
bbp.BirthDay = iohelp.ReadDateBytes(buf[at:])
at += 8
bbp.Phone, err = iohelp.ReadStringBytes(buf[at:])
if err != nil {
return err
}
at += 4 + len(bbp.Phone)
if len(buf[at:]) < 4 {
return io.ErrUnexpectedEOF
}
bbp.Siblings = iohelp.ReadInt32Bytes(buf[at:])
at += 4
if len(buf[at:]) < 1 {
return io.ErrUnexpectedEOF
}
bbp.Spouse = iohelp.ReadBoolBytes(buf[at:])
at += 1
if len(buf[at:]) < 8 {
return io.ErrUnexpectedEOF
}
bbp.Money = iohelp.ReadFloat64Bytes(buf[at:])
at += 8
return nil
}
func (bbp *BebopBuf200sc) EncodeBebop(iow io.Writer) (err error) {
w := iohelp.NewErrorWriter(iow)
iohelp.WriteUint32(w, uint32(len(bbp.Name)))
w.Write([]byte(bbp.Name))
if bbp.BirthDay != (time.Time{}) {
iohelp.WriteInt64(w, ((bbp.BirthDay).UnixNano() / 100))
} else {
iohelp.WriteInt64(w, 0)
}
iohelp.WriteUint32(w, uint32(len(bbp.Phone)))
w.Write([]byte(bbp.Phone))
iohelp.WriteInt32(w, bbp.Siblings)
iohelp.WriteBool(w, bbp.Spouse)
iohelp.WriteFloat64(w, bbp.Money)
return w.Err
}
func (bbp *BebopBuf200sc) DecodeBebop(ior io.Reader) (err error) {
r := iohelp.NewErrorReader(ior)
bbp.Name = iohelp.ReadString(r)
bbp.BirthDay = iohelp.ReadDate(r)
bbp.Phone = iohelp.ReadString(r)
bbp.Siblings = iohelp.ReadInt32(r)
bbp.Spouse = iohelp.ReadBool(r)
bbp.Money = iohelp.ReadFloat64(r)
return r.Err
}
func (bbp *BebopBuf200sc) Size() int {
bodyLen := 0
bodyLen += 4 + len(bbp.Name)
bodyLen += 8
bodyLen += 4 + len(bbp.Phone)
bodyLen += 4
bodyLen += 1
bodyLen += 8
return bodyLen
}
func (bbp *BebopBuf200sc) MarshalBebop() []byte {
buf := make([]byte, bbp.Size())
bbp.MarshalBebopTo(buf)
return buf
}
func MakeBebopBuf200sc(r *iohelp.ErrorReader) (BebopBuf200sc, error) {
v := BebopBuf200sc{}
err := v.DecodeBebop(r)
return v, err
}
func MakeBebopBuf200scFromBytes(buf []byte) (BebopBuf200sc, error) {
v := BebopBuf200sc{}
err := v.UnmarshalBebop(buf)
return v, err
}