forked from alecthomas/go_serialization_benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structdef.capnp2.go
161 lines (120 loc) · 3.13 KB
/
structdef.capnp2.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
package goserbench
// AUTO GENERATED - DO NOT EDIT
import (
math "math"
capnp "zombiezen.com/go/capnproto2"
)
type Capnp2A struct{ capnp.Struct }
func NewCapnp2A(s *capnp.Segment) (Capnp2A, error) {
st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 24, PointerCount: 2})
if err != nil {
return Capnp2A{}, err
}
return Capnp2A{st}, nil
}
func NewRootCapnp2A(s *capnp.Segment) (Capnp2A, error) {
st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 24, PointerCount: 2})
if err != nil {
return Capnp2A{}, err
}
return Capnp2A{st}, nil
}
func ReadRootCapnp2A(msg *capnp.Message) (Capnp2A, error) {
root, err := msg.RootPtr()
if err != nil {
return Capnp2A{}, err
}
return Capnp2A{root.Struct()}, nil
}
func (s Capnp2A) Name() (string, error) {
p, err := s.Struct.Ptr(0)
if err != nil {
return "", err
}
return p.Text(), nil
}
func (s Capnp2A) HasName() bool {
p, err := s.Struct.Ptr(0)
return p.IsValid() || err != nil
}
func (s Capnp2A) NameBytes() ([]byte, error) {
p, err := s.Struct.Ptr(0)
if err != nil {
return nil, err
}
return p.Data(), nil
}
func (s Capnp2A) SetName(v string) error {
t, err := capnp.NewText(s.Struct.Segment(), v)
if err != nil {
return err
}
return s.Struct.SetPtr(0, t.List.ToPtr())
}
func (s Capnp2A) BirthDay() int64 {
return int64(s.Struct.Uint64(0))
}
func (s Capnp2A) SetBirthDay(v int64) {
s.Struct.SetUint64(0, uint64(v))
}
func (s Capnp2A) Phone() (string, error) {
p, err := s.Struct.Ptr(1)
if err != nil {
return "", err
}
return p.Text(), nil
}
func (s Capnp2A) HasPhone() bool {
p, err := s.Struct.Ptr(1)
return p.IsValid() || err != nil
}
func (s Capnp2A) PhoneBytes() ([]byte, error) {
p, err := s.Struct.Ptr(1)
if err != nil {
return nil, err
}
return p.Data(), nil
}
func (s Capnp2A) SetPhone(v string) error {
t, err := capnp.NewText(s.Struct.Segment(), v)
if err != nil {
return err
}
return s.Struct.SetPtr(1, t.List.ToPtr())
}
func (s Capnp2A) Siblings() int32 {
return int32(s.Struct.Uint32(8))
}
func (s Capnp2A) SetSiblings(v int32) {
s.Struct.SetUint32(8, uint32(v))
}
func (s Capnp2A) Spouse() bool {
return s.Struct.Bit(96)
}
func (s Capnp2A) SetSpouse(v bool) {
s.Struct.SetBit(96, v)
}
func (s Capnp2A) Money() float64 {
return math.Float64frombits(s.Struct.Uint64(16))
}
func (s Capnp2A) SetMoney(v float64) {
s.Struct.SetUint64(16, math.Float64bits(v))
}
// Capnp2A_List is a list of Capnp2A.
type Capnp2A_List struct{ capnp.List }
// NewCapnp2A creates a new list of Capnp2A.
func NewCapnp2A_List(s *capnp.Segment, sz int32) (Capnp2A_List, error) {
l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 24, PointerCount: 2}, sz)
if err != nil {
return Capnp2A_List{}, err
}
return Capnp2A_List{l}, nil
}
func (s Capnp2A_List) At(i int) Capnp2A { return Capnp2A{s.List.Struct(i)} }
func (s Capnp2A_List) Set(i int, v Capnp2A) error { return s.List.SetStruct(i, v.Struct) }
// Capnp2A_Promise is a wrapper for a Capnp2A promised by a client call.
type Capnp2A_Promise struct{ *capnp.Pipeline }
func (p Capnp2A_Promise) Struct() (Capnp2A, error) {
s, err := p.Pipeline.Struct()
return Capnp2A{s}, err
}