1 // Protocol Buffers for Go with Gadgets
3 // Copyright (c) 2016, The GoGo Authors. All rights reserved.
4 // http://github.com/gogo/protobuf
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 var durationType = reflect.TypeOf((*time.Duration)(nil)).Elem()
38 type duration struct {
39 Seconds int64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"`
40 Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"`
43 func (m *duration) Reset() { *m = duration{} }
44 func (*duration) ProtoMessage() {}
45 func (*duration) String() string { return "duration<string>" }
48 RegisterType((*duration)(nil), "gogo.protobuf.proto.duration")
51 func (o *Buffer) decDuration() (time.Duration, error) {
52 b, err := o.DecodeRawBytes(true)
57 if err := Unmarshal(b, dproto); err != nil {
60 return durationFromProto(dproto)
63 func (o *Buffer) dec_duration(p *Properties, base structPointer) error {
64 d, err := o.decDuration()
68 word64_Set(structPointer_Word64(base, p.field), o, uint64(d))
72 func (o *Buffer) dec_ref_duration(p *Properties, base structPointer) error {
73 d, err := o.decDuration()
77 word64Val_Set(structPointer_Word64Val(base, p.field), o, uint64(d))
81 func (o *Buffer) dec_slice_duration(p *Properties, base structPointer) error {
82 d, err := o.decDuration()
86 newBas := appendStructPointer(base, p.field, reflect.SliceOf(reflect.PtrTo(durationType)))
88 setPtrCustomType(newBas, zero, &d)
92 func (o *Buffer) dec_slice_ref_duration(p *Properties, base structPointer) error {
93 d, err := o.decDuration()
97 structPointer_Word64Slice(base, p.field).Append(uint64(d))
101 func size_duration(p *Properties, base structPointer) (n int) {
102 structp := structPointer_GetStructPointer(base, p.field)
103 if structPointer_IsNil(structp) {
106 dur := structPointer_Interface(structp, durationType).(*time.Duration)
107 d := durationProto(*dur)
109 return size + sizeVarint(uint64(size)) + len(p.tagcode)
112 func (o *Buffer) enc_duration(p *Properties, base structPointer) error {
113 structp := structPointer_GetStructPointer(base, p.field)
114 if structPointer_IsNil(structp) {
117 dur := structPointer_Interface(structp, durationType).(*time.Duration)
118 d := durationProto(*dur)
119 data, err := Marshal(d)
123 o.buf = append(o.buf, p.tagcode...)
124 o.EncodeRawBytes(data)
128 func size_ref_duration(p *Properties, base structPointer) (n int) {
129 dur := structPointer_InterfaceAt(base, p.field, durationType).(*time.Duration)
130 d := durationProto(*dur)
132 return size + sizeVarint(uint64(size)) + len(p.tagcode)
135 func (o *Buffer) enc_ref_duration(p *Properties, base structPointer) error {
136 dur := structPointer_InterfaceAt(base, p.field, durationType).(*time.Duration)
137 d := durationProto(*dur)
138 data, err := Marshal(d)
142 o.buf = append(o.buf, p.tagcode...)
143 o.EncodeRawBytes(data)
147 func size_slice_duration(p *Properties, base structPointer) (n int) {
148 pdurs := structPointer_InterfaceAt(base, p.field, reflect.SliceOf(reflect.PtrTo(durationType))).(*[]*time.Duration)
150 for i := 0; i < len(durs); i++ {
154 dproto := durationProto(*durs[i])
156 n += len(p.tagcode) + size + sizeVarint(uint64(size))
161 func (o *Buffer) enc_slice_duration(p *Properties, base structPointer) error {
162 pdurs := structPointer_InterfaceAt(base, p.field, reflect.SliceOf(reflect.PtrTo(durationType))).(*[]*time.Duration)
164 for i := 0; i < len(durs); i++ {
166 return errRepeatedHasNil
168 dproto := durationProto(*durs[i])
169 data, err := Marshal(dproto)
173 o.buf = append(o.buf, p.tagcode...)
174 o.EncodeRawBytes(data)
179 func size_slice_ref_duration(p *Properties, base structPointer) (n int) {
180 pdurs := structPointer_InterfaceAt(base, p.field, reflect.SliceOf(durationType)).(*[]time.Duration)
182 for i := 0; i < len(durs); i++ {
183 dproto := durationProto(durs[i])
185 n += len(p.tagcode) + size + sizeVarint(uint64(size))
190 func (o *Buffer) enc_slice_ref_duration(p *Properties, base structPointer) error {
191 pdurs := structPointer_InterfaceAt(base, p.field, reflect.SliceOf(durationType)).(*[]time.Duration)
193 for i := 0; i < len(durs); i++ {
194 dproto := durationProto(durs[i])
195 data, err := Marshal(dproto)
199 o.buf = append(o.buf, p.tagcode...)
200 o.EncodeRawBytes(data)