forked from alecthomas/go_serialization_benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructdef-bebop.go
128 lines (115 loc) · 2.83 KB
/
structdef-bebop.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
// Code generated by bebopc-go; DO NOT EDIT.
package goserbench
import (
"github.com/200sc/bebop"
"github.com/200sc/bebop/iohelp"
"io"
)
var _ bebop.Record = &BebopBufA{}
type BebopBufA struct {
Name string
BirthDay uint64
Phone string
Siblings int32
Spouse bool
Money float64
}
func (bbp BebopBufA) 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)
iohelp.WriteUint64Bytes(buf[at:], bbp.BirthDay)
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 *BebopBufA) 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.ReadUint64Bytes(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 BebopBufA) EncodeBebop(iow io.Writer) (err error) {
w := iohelp.NewErrorWriter(iow)
iohelp.WriteUint32(w, uint32(len(bbp.Name)))
w.Write([]byte(bbp.Name))
iohelp.WriteUint64(w, bbp.BirthDay)
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 *BebopBufA) DecodeBebop(ior io.Reader) (err error) {
r := iohelp.NewErrorReader(ior)
bbp.Name = iohelp.ReadString(r)
bbp.BirthDay = iohelp.ReadUint64(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 BebopBufA) 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 BebopBufA) MarshalBebop() []byte {
buf := make([]byte, bbp.Size())
bbp.MarshalBebopTo(buf)
return buf
}
func MakeBebopBufA(r iohelp.ErrorReader) (BebopBufA, error) {
v := BebopBufA{}
err := v.DecodeBebop(r)
return v, err
}
func MakeBebopBufAFromBytes(buf []byte) (BebopBufA, error) {
v := BebopBufA{}
err := v.UnmarshalBebop(buf)
return v, err
}