blob: 1a509b63ebc1767a0b2e0d5080bcdff9dedd9b64 [file] [log] [blame]
Damien Neilc37adef2019-04-01 13:49:56 -07001// Copyright 2018 The Go Authors. All rights reserved.
Damien Neil0232edc2020-02-20 10:30:38 -08002// Use of this source code is governed by a BSD-style
Damien Neilc37adef2019-04-01 13:49:56 -07003// license that can be found in the LICENSE file.
4
5// Code generated by generate-types. DO NOT EDIT.
6
7package impl
8
9import (
10 "math"
Joe Tsaic51e2e02019-07-13 00:44:41 -070011 "unicode/utf8"
Damien Neilc37adef2019-04-01 13:49:56 -070012
Joe Tsaicd108d02020-02-14 18:08:02 -080013 "google.golang.org/protobuf/encoding/protowire"
Damien Neilc37adef2019-04-01 13:49:56 -070014 "google.golang.org/protobuf/reflect/protoreflect"
15)
16
17// sizeBool returns the size of wire encoding a bool pointer as a Bool.
Joe Tsai41134b72020-10-19 20:51:03 -070018func sizeBool(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -070019 v := *p.Bool()
Joe Tsaicd108d02020-02-14 18:08:02 -080020 return f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v))
Damien Neilc37adef2019-04-01 13:49:56 -070021}
22
23// appendBool wire encodes a bool pointer as a Bool.
Joe Tsai41134b72020-10-19 20:51:03 -070024func appendBool(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -070025 v := *p.Bool()
Joe Tsaicd108d02020-02-14 18:08:02 -080026 b = protowire.AppendVarint(b, f.wiretag)
27 b = protowire.AppendVarint(b, protowire.EncodeBool(v))
Damien Neilc37adef2019-04-01 13:49:56 -070028 return b, nil
29}
30
Damien Neile91877d2019-06-27 10:54:42 -070031// consumeBool wire decodes a bool pointer as a Bool.
Joe Tsai41134b72020-10-19 20:51:03 -070032func consumeBool(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -080033 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -080034 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -070035 }
Damien Neiladbbc8e2020-01-24 17:01:14 -080036 var v uint64
37 var n int
38 if len(b) >= 1 && b[0] < 0x80 {
39 v = uint64(b[0])
40 n = 1
41 } else if len(b) >= 2 && b[1] < 128 {
42 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
43 n = 2
44 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -080045 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -080046 }
Damien Neile91877d2019-06-27 10:54:42 -070047 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -070048 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -070049 }
Joe Tsaicd108d02020-02-14 18:08:02 -080050 *p.Bool() = protowire.DecodeBool(v)
Damien Neilf0831e82020-01-21 14:25:12 -080051 out.n = n
52 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -070053}
54
Damien Neilc37adef2019-04-01 13:49:56 -070055var coderBool = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -070056 size: sizeBool,
57 marshal: appendBool,
58 unmarshal: consumeBool,
Damien Neile8e88752020-02-11 11:25:16 -080059 merge: mergeBool,
Damien Neilc37adef2019-04-01 13:49:56 -070060}
61
Joe Tsaic51e2e02019-07-13 00:44:41 -070062// sizeBoolNoZero returns the size of wire encoding a bool pointer as a Bool.
Damien Neilc37adef2019-04-01 13:49:56 -070063// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -070064func sizeBoolNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -070065 v := *p.Bool()
66 if v == false {
67 return 0
68 }
Joe Tsaicd108d02020-02-14 18:08:02 -080069 return f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v))
Damien Neilc37adef2019-04-01 13:49:56 -070070}
71
Joe Tsaic51e2e02019-07-13 00:44:41 -070072// appendBoolNoZero wire encodes a bool pointer as a Bool.
Damien Neilc37adef2019-04-01 13:49:56 -070073// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -070074func appendBoolNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -070075 v := *p.Bool()
76 if v == false {
77 return b, nil
78 }
Joe Tsaicd108d02020-02-14 18:08:02 -080079 b = protowire.AppendVarint(b, f.wiretag)
80 b = protowire.AppendVarint(b, protowire.EncodeBool(v))
Damien Neilc37adef2019-04-01 13:49:56 -070081 return b, nil
82}
83
84var coderBoolNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -070085 size: sizeBoolNoZero,
86 marshal: appendBoolNoZero,
87 unmarshal: consumeBool,
Damien Neile8e88752020-02-11 11:25:16 -080088 merge: mergeBoolNoZero,
Damien Neilc37adef2019-04-01 13:49:56 -070089}
90
91// sizeBoolPtr returns the size of wire encoding a *bool pointer as a Bool.
92// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -070093func sizeBoolPtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -070094 v := **p.BoolPtr()
Joe Tsaicd108d02020-02-14 18:08:02 -080095 return f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v))
Damien Neilc37adef2019-04-01 13:49:56 -070096}
97
Damien Neile91877d2019-06-27 10:54:42 -070098// appendBoolPtr wire encodes a *bool pointer as a Bool.
Damien Neilc37adef2019-04-01 13:49:56 -070099// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -0700100func appendBoolPtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700101 v := **p.BoolPtr()
Joe Tsaicd108d02020-02-14 18:08:02 -0800102 b = protowire.AppendVarint(b, f.wiretag)
103 b = protowire.AppendVarint(b, protowire.EncodeBool(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700104 return b, nil
105}
106
Damien Neile91877d2019-06-27 10:54:42 -0700107// consumeBoolPtr wire decodes a *bool pointer as a Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700108func consumeBoolPtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -0800109 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -0800110 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700111 }
Damien Neiladbbc8e2020-01-24 17:01:14 -0800112 var v uint64
113 var n int
114 if len(b) >= 1 && b[0] < 0x80 {
115 v = uint64(b[0])
116 n = 1
117 } else if len(b) >= 2 && b[1] < 128 {
118 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
119 n = 2
120 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800121 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800122 }
Damien Neile91877d2019-06-27 10:54:42 -0700123 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700124 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700125 }
126 vp := p.BoolPtr()
127 if *vp == nil {
128 *vp = new(bool)
129 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800130 **vp = protowire.DecodeBool(v)
Damien Neilf0831e82020-01-21 14:25:12 -0800131 out.n = n
132 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700133}
134
Damien Neilc37adef2019-04-01 13:49:56 -0700135var coderBoolPtr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700136 size: sizeBoolPtr,
137 marshal: appendBoolPtr,
138 unmarshal: consumeBoolPtr,
Damien Neile8e88752020-02-11 11:25:16 -0800139 merge: mergeBoolPtr,
Damien Neilc37adef2019-04-01 13:49:56 -0700140}
141
142// sizeBoolSlice returns the size of wire encoding a []bool pointer as a repeated Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700143func sizeBoolSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -0700144 s := *p.BoolSlice()
145 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -0800146 size += f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700147 }
148 return size
149}
150
151// appendBoolSlice encodes a []bool pointer as a repeated Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700152func appendBoolSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700153 s := *p.BoolSlice()
154 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -0800155 b = protowire.AppendVarint(b, f.wiretag)
156 b = protowire.AppendVarint(b, protowire.EncodeBool(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700157 }
158 return b, nil
159}
160
Damien Neile91877d2019-06-27 10:54:42 -0700161// consumeBoolSlice wire decodes a []bool pointer as a repeated Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700162func consumeBoolSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -0700163 sp := p.BoolSlice()
Joe Tsaicd108d02020-02-14 18:08:02 -0800164 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -0700165 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -0800166 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -0700167 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700168 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700169 }
170 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -0800171 var v uint64
172 var n int
173 if len(b) >= 1 && b[0] < 0x80 {
174 v = uint64(b[0])
175 n = 1
176 } else if len(b) >= 2 && b[1] < 128 {
177 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
178 n = 2
179 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800180 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800181 }
Damien Neile91877d2019-06-27 10:54:42 -0700182 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700183 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700184 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800185 s = append(s, protowire.DecodeBool(v))
Damien Neile91877d2019-06-27 10:54:42 -0700186 b = b[n:]
187 }
188 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -0800189 out.n = n
190 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700191 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800192 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -0800193 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700194 }
Damien Neiladbbc8e2020-01-24 17:01:14 -0800195 var v uint64
196 var n int
197 if len(b) >= 1 && b[0] < 0x80 {
198 v = uint64(b[0])
199 n = 1
200 } else if len(b) >= 2 && b[1] < 128 {
201 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
202 n = 2
203 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800204 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800205 }
Damien Neile91877d2019-06-27 10:54:42 -0700206 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700207 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700208 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800209 *sp = append(*sp, protowire.DecodeBool(v))
Damien Neilf0831e82020-01-21 14:25:12 -0800210 out.n = n
211 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700212}
213
Damien Neilc37adef2019-04-01 13:49:56 -0700214var coderBoolSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700215 size: sizeBoolSlice,
216 marshal: appendBoolSlice,
217 unmarshal: consumeBoolSlice,
Damien Neile8e88752020-02-11 11:25:16 -0800218 merge: mergeBoolSlice,
Damien Neilc37adef2019-04-01 13:49:56 -0700219}
220
221// sizeBoolPackedSlice returns the size of wire encoding a []bool pointer as a packed repeated Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700222func sizeBoolPackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -0700223 s := *p.BoolSlice()
224 if len(s) == 0 {
225 return 0
226 }
227 n := 0
228 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -0800229 n += protowire.SizeVarint(protowire.EncodeBool(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700230 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800231 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -0700232}
233
234// appendBoolPackedSlice encodes a []bool pointer as a packed repeated Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700235func appendBoolPackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700236 s := *p.BoolSlice()
237 if len(s) == 0 {
238 return b, nil
239 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800240 b = protowire.AppendVarint(b, f.wiretag)
Damien Neilc37adef2019-04-01 13:49:56 -0700241 n := 0
242 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -0800243 n += protowire.SizeVarint(protowire.EncodeBool(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700244 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800245 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -0700246 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -0800247 b = protowire.AppendVarint(b, protowire.EncodeBool(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700248 }
249 return b, nil
250}
251
252var coderBoolPackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700253 size: sizeBoolPackedSlice,
254 marshal: appendBoolPackedSlice,
255 unmarshal: consumeBoolSlice,
Damien Neile8e88752020-02-11 11:25:16 -0800256 merge: mergeBoolSlice,
Damien Neilc37adef2019-04-01 13:49:56 -0700257}
258
Damien Neil68b81c32019-08-22 11:41:32 -0700259// sizeBoolValue returns the size of wire encoding a bool value as a Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700260func sizeBoolValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -0800261 return tagsize + protowire.SizeVarint(protowire.EncodeBool(v.Bool()))
Damien Neilc37adef2019-04-01 13:49:56 -0700262}
263
Damien Neil68b81c32019-08-22 11:41:32 -0700264// appendBoolValue encodes a bool value as a Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700265func appendBoolValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -0800266 b = protowire.AppendVarint(b, wiretag)
267 b = protowire.AppendVarint(b, protowire.EncodeBool(v.Bool()))
Damien Neilc37adef2019-04-01 13:49:56 -0700268 return b, nil
269}
270
Damien Neil68b81c32019-08-22 11:41:32 -0700271// consumeBoolValue decodes a bool value as a Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700272func consumeBoolValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -0800273 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -0800274 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700275 }
Damien Neiladbbc8e2020-01-24 17:01:14 -0800276 var v uint64
277 var n int
278 if len(b) >= 1 && b[0] < 0x80 {
279 v = uint64(b[0])
280 n = 1
281 } else if len(b) >= 2 && b[1] < 128 {
282 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
283 n = 2
284 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800285 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800286 }
Damien Neile91877d2019-06-27 10:54:42 -0700287 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700288 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700289 }
Damien Neilf0831e82020-01-21 14:25:12 -0800290 out.n = n
Joe Tsaicd108d02020-02-14 18:08:02 -0800291 return protoreflect.ValueOfBool(protowire.DecodeBool(v)), out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700292}
293
Damien Neil68b81c32019-08-22 11:41:32 -0700294var coderBoolValue = valueCoderFuncs{
295 size: sizeBoolValue,
296 marshal: appendBoolValue,
297 unmarshal: consumeBoolValue,
Damien Neile8e88752020-02-11 11:25:16 -0800298 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -0700299}
300
Damien Neil68b81c32019-08-22 11:41:32 -0700301// sizeBoolSliceValue returns the size of wire encoding a []bool value as a repeated Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700302func sizeBoolSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -0700303 list := listv.List()
304 for i, llen := 0, list.Len(); i < llen; i++ {
305 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800306 size += tagsize + protowire.SizeVarint(protowire.EncodeBool(v.Bool()))
Damien Neilc37adef2019-04-01 13:49:56 -0700307 }
308 return size
309}
310
Damien Neil68b81c32019-08-22 11:41:32 -0700311// appendBoolSliceValue encodes a []bool value as a repeated Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700312func appendBoolSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -0700313 list := listv.List()
314 for i, llen := 0, list.Len(); i < llen; i++ {
315 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800316 b = protowire.AppendVarint(b, wiretag)
317 b = protowire.AppendVarint(b, protowire.EncodeBool(v.Bool()))
Damien Neilc37adef2019-04-01 13:49:56 -0700318 }
319 return b, nil
320}
321
Damien Neil68b81c32019-08-22 11:41:32 -0700322// consumeBoolSliceValue wire decodes a []bool value as a repeated Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700323func consumeBoolSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -0700324 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -0800325 if wtyp == protowire.BytesType {
326 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -0700327 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700328 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700329 }
330 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -0800331 var v uint64
332 var n int
333 if len(b) >= 1 && b[0] < 0x80 {
334 v = uint64(b[0])
335 n = 1
336 } else if len(b) >= 2 && b[1] < 128 {
337 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
338 n = 2
339 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800340 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800341 }
Damien Neile91877d2019-06-27 10:54:42 -0700342 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700343 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700344 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800345 list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v)))
Damien Neile91877d2019-06-27 10:54:42 -0700346 b = b[n:]
347 }
Damien Neilf0831e82020-01-21 14:25:12 -0800348 out.n = n
349 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700350 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800351 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -0800352 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700353 }
Damien Neiladbbc8e2020-01-24 17:01:14 -0800354 var v uint64
355 var n int
356 if len(b) >= 1 && b[0] < 0x80 {
357 v = uint64(b[0])
358 n = 1
359 } else if len(b) >= 2 && b[1] < 128 {
360 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
361 n = 2
362 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800363 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800364 }
Damien Neile91877d2019-06-27 10:54:42 -0700365 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700366 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700367 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800368 list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v)))
Damien Neilf0831e82020-01-21 14:25:12 -0800369 out.n = n
370 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700371}
372
Damien Neil68b81c32019-08-22 11:41:32 -0700373var coderBoolSliceValue = valueCoderFuncs{
374 size: sizeBoolSliceValue,
375 marshal: appendBoolSliceValue,
376 unmarshal: consumeBoolSliceValue,
Damien Neile8e88752020-02-11 11:25:16 -0800377 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -0700378}
379
Damien Neil68b81c32019-08-22 11:41:32 -0700380// sizeBoolPackedSliceValue returns the size of wire encoding a []bool value as a packed repeated Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700381func sizeBoolPackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -0700382 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -0800383 llen := list.Len()
384 if llen == 0 {
385 return 0
386 }
Damien Neil7492a092019-07-10 15:23:29 -0700387 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -0800388 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -0700389 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800390 n += protowire.SizeVarint(protowire.EncodeBool(v.Bool()))
Damien Neil7492a092019-07-10 15:23:29 -0700391 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800392 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -0700393}
394
Damien Neil68b81c32019-08-22 11:41:32 -0700395// appendBoolPackedSliceValue encodes a []bool value as a packed repeated Bool.
Joe Tsai41134b72020-10-19 20:51:03 -0700396func appendBoolPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -0700397 list := listv.List()
398 llen := list.Len()
399 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -0700400 return b, nil
401 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800402 b = protowire.AppendVarint(b, wiretag)
Damien Neil7492a092019-07-10 15:23:29 -0700403 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -0700404 for i := 0; i < llen; i++ {
405 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800406 n += protowire.SizeVarint(protowire.EncodeBool(v.Bool()))
Damien Neil7492a092019-07-10 15:23:29 -0700407 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800408 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -0700409 for i := 0; i < llen; i++ {
410 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800411 b = protowire.AppendVarint(b, protowire.EncodeBool(v.Bool()))
Damien Neil7492a092019-07-10 15:23:29 -0700412 }
413 return b, nil
414}
415
Damien Neil68b81c32019-08-22 11:41:32 -0700416var coderBoolPackedSliceValue = valueCoderFuncs{
417 size: sizeBoolPackedSliceValue,
418 marshal: appendBoolPackedSliceValue,
419 unmarshal: consumeBoolSliceValue,
Damien Neile8e88752020-02-11 11:25:16 -0800420 merge: mergeListValue,
Damien Neil68b81c32019-08-22 11:41:32 -0700421}
422
423// sizeEnumValue returns the size of wire encoding a value as a Enum.
Joe Tsai41134b72020-10-19 20:51:03 -0700424func sizeEnumValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -0800425 return tagsize + protowire.SizeVarint(uint64(v.Enum()))
Damien Neil68b81c32019-08-22 11:41:32 -0700426}
427
428// appendEnumValue encodes a value as a Enum.
Joe Tsai41134b72020-10-19 20:51:03 -0700429func appendEnumValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -0800430 b = protowire.AppendVarint(b, wiretag)
431 b = protowire.AppendVarint(b, uint64(v.Enum()))
Damien Neil68b81c32019-08-22 11:41:32 -0700432 return b, nil
433}
434
435// consumeEnumValue decodes a value as a Enum.
Joe Tsai41134b72020-10-19 20:51:03 -0700436func consumeEnumValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -0800437 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -0800438 return protoreflect.Value{}, out, errUnknown
Damien Neil68b81c32019-08-22 11:41:32 -0700439 }
Damien Neiladbbc8e2020-01-24 17:01:14 -0800440 var v uint64
441 var n int
442 if len(b) >= 1 && b[0] < 0x80 {
443 v = uint64(b[0])
444 n = 1
445 } else if len(b) >= 2 && b[1] < 128 {
446 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
447 n = 2
448 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800449 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800450 }
Damien Neil68b81c32019-08-22 11:41:32 -0700451 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700452 return protoreflect.Value{}, out, errDecode
Damien Neil68b81c32019-08-22 11:41:32 -0700453 }
Damien Neilf0831e82020-01-21 14:25:12 -0800454 out.n = n
455 return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), out, nil
Damien Neil68b81c32019-08-22 11:41:32 -0700456}
457
458var coderEnumValue = valueCoderFuncs{
459 size: sizeEnumValue,
460 marshal: appendEnumValue,
461 unmarshal: consumeEnumValue,
Damien Neile8e88752020-02-11 11:25:16 -0800462 merge: mergeScalarValue,
Damien Neil68b81c32019-08-22 11:41:32 -0700463}
464
465// sizeEnumSliceValue returns the size of wire encoding a [] value as a repeated Enum.
Joe Tsai41134b72020-10-19 20:51:03 -0700466func sizeEnumSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -0700467 list := listv.List()
468 for i, llen := 0, list.Len(); i < llen; i++ {
469 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800470 size += tagsize + protowire.SizeVarint(uint64(v.Enum()))
Damien Neil68b81c32019-08-22 11:41:32 -0700471 }
472 return size
473}
474
475// appendEnumSliceValue encodes a [] value as a repeated Enum.
Joe Tsai41134b72020-10-19 20:51:03 -0700476func appendEnumSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -0700477 list := listv.List()
478 for i, llen := 0, list.Len(); i < llen; i++ {
479 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800480 b = protowire.AppendVarint(b, wiretag)
481 b = protowire.AppendVarint(b, uint64(v.Enum()))
Damien Neil68b81c32019-08-22 11:41:32 -0700482 }
483 return b, nil
484}
485
486// consumeEnumSliceValue wire decodes a [] value as a repeated Enum.
Joe Tsai41134b72020-10-19 20:51:03 -0700487func consumeEnumSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -0700488 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -0800489 if wtyp == protowire.BytesType {
490 b, n := protowire.ConsumeBytes(b)
Damien Neil68b81c32019-08-22 11:41:32 -0700491 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700492 return protoreflect.Value{}, out, errDecode
Damien Neil68b81c32019-08-22 11:41:32 -0700493 }
494 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -0800495 var v uint64
496 var n int
497 if len(b) >= 1 && b[0] < 0x80 {
498 v = uint64(b[0])
499 n = 1
500 } else if len(b) >= 2 && b[1] < 128 {
501 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
502 n = 2
503 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800504 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800505 }
Damien Neil68b81c32019-08-22 11:41:32 -0700506 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700507 return protoreflect.Value{}, out, errDecode
Damien Neil68b81c32019-08-22 11:41:32 -0700508 }
509 list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
510 b = b[n:]
511 }
Damien Neilf0831e82020-01-21 14:25:12 -0800512 out.n = n
513 return listv, out, nil
Damien Neil68b81c32019-08-22 11:41:32 -0700514 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800515 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -0800516 return protoreflect.Value{}, out, errUnknown
Damien Neil68b81c32019-08-22 11:41:32 -0700517 }
Damien Neiladbbc8e2020-01-24 17:01:14 -0800518 var v uint64
519 var n int
520 if len(b) >= 1 && b[0] < 0x80 {
521 v = uint64(b[0])
522 n = 1
523 } else if len(b) >= 2 && b[1] < 128 {
524 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
525 n = 2
526 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800527 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800528 }
Damien Neil68b81c32019-08-22 11:41:32 -0700529 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700530 return protoreflect.Value{}, out, errDecode
Damien Neil68b81c32019-08-22 11:41:32 -0700531 }
532 list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
Damien Neilf0831e82020-01-21 14:25:12 -0800533 out.n = n
534 return listv, out, nil
Damien Neil68b81c32019-08-22 11:41:32 -0700535}
536
537var coderEnumSliceValue = valueCoderFuncs{
538 size: sizeEnumSliceValue,
539 marshal: appendEnumSliceValue,
540 unmarshal: consumeEnumSliceValue,
Damien Neile8e88752020-02-11 11:25:16 -0800541 merge: mergeListValue,
Damien Neil68b81c32019-08-22 11:41:32 -0700542}
543
544// sizeEnumPackedSliceValue returns the size of wire encoding a [] value as a packed repeated Enum.
Joe Tsai41134b72020-10-19 20:51:03 -0700545func sizeEnumPackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -0700546 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -0800547 llen := list.Len()
548 if llen == 0 {
549 return 0
550 }
Damien Neil68b81c32019-08-22 11:41:32 -0700551 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -0800552 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -0700553 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800554 n += protowire.SizeVarint(uint64(v.Enum()))
Damien Neil68b81c32019-08-22 11:41:32 -0700555 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800556 return tagsize + protowire.SizeBytes(n)
Damien Neil68b81c32019-08-22 11:41:32 -0700557}
558
559// appendEnumPackedSliceValue encodes a [] value as a packed repeated Enum.
Joe Tsai41134b72020-10-19 20:51:03 -0700560func appendEnumPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -0700561 list := listv.List()
562 llen := list.Len()
563 if llen == 0 {
564 return b, nil
565 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800566 b = protowire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -0700567 n := 0
568 for i := 0; i < llen; i++ {
569 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800570 n += protowire.SizeVarint(uint64(v.Enum()))
Damien Neil68b81c32019-08-22 11:41:32 -0700571 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800572 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -0700573 for i := 0; i < llen; i++ {
574 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800575 b = protowire.AppendVarint(b, uint64(v.Enum()))
Damien Neil68b81c32019-08-22 11:41:32 -0700576 }
577 return b, nil
578}
579
580var coderEnumPackedSliceValue = valueCoderFuncs{
581 size: sizeEnumPackedSliceValue,
582 marshal: appendEnumPackedSliceValue,
583 unmarshal: consumeEnumSliceValue,
Damien Neile8e88752020-02-11 11:25:16 -0800584 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -0700585}
586
Damien Neilc37adef2019-04-01 13:49:56 -0700587// sizeInt32 returns the size of wire encoding a int32 pointer as a Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700588func sizeInt32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -0700589 v := *p.Int32()
Joe Tsaicd108d02020-02-14 18:08:02 -0800590 return f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700591}
592
593// appendInt32 wire encodes a int32 pointer as a Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700594func appendInt32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700595 v := *p.Int32()
Joe Tsaicd108d02020-02-14 18:08:02 -0800596 b = protowire.AppendVarint(b, f.wiretag)
597 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700598 return b, nil
599}
600
Damien Neile91877d2019-06-27 10:54:42 -0700601// consumeInt32 wire decodes a int32 pointer as a Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700602func consumeInt32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -0800603 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -0800604 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700605 }
Damien Neiladbbc8e2020-01-24 17:01:14 -0800606 var v uint64
607 var n int
608 if len(b) >= 1 && b[0] < 0x80 {
609 v = uint64(b[0])
610 n = 1
611 } else if len(b) >= 2 && b[1] < 128 {
612 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
613 n = 2
614 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800615 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800616 }
Damien Neile91877d2019-06-27 10:54:42 -0700617 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700618 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700619 }
620 *p.Int32() = int32(v)
Damien Neilf0831e82020-01-21 14:25:12 -0800621 out.n = n
622 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700623}
624
Damien Neilc37adef2019-04-01 13:49:56 -0700625var coderInt32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700626 size: sizeInt32,
627 marshal: appendInt32,
628 unmarshal: consumeInt32,
Damien Neile8e88752020-02-11 11:25:16 -0800629 merge: mergeInt32,
Damien Neilc37adef2019-04-01 13:49:56 -0700630}
631
Joe Tsaic51e2e02019-07-13 00:44:41 -0700632// sizeInt32NoZero returns the size of wire encoding a int32 pointer as a Int32.
Damien Neilc37adef2019-04-01 13:49:56 -0700633// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -0700634func sizeInt32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -0700635 v := *p.Int32()
636 if v == 0 {
637 return 0
638 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800639 return f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700640}
641
Joe Tsaic51e2e02019-07-13 00:44:41 -0700642// appendInt32NoZero wire encodes a int32 pointer as a Int32.
Damien Neilc37adef2019-04-01 13:49:56 -0700643// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -0700644func appendInt32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700645 v := *p.Int32()
646 if v == 0 {
647 return b, nil
648 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800649 b = protowire.AppendVarint(b, f.wiretag)
650 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700651 return b, nil
652}
653
654var coderInt32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700655 size: sizeInt32NoZero,
656 marshal: appendInt32NoZero,
657 unmarshal: consumeInt32,
Damien Neile8e88752020-02-11 11:25:16 -0800658 merge: mergeInt32NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -0700659}
660
661// sizeInt32Ptr returns the size of wire encoding a *int32 pointer as a Int32.
662// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -0700663func sizeInt32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -0700664 v := **p.Int32Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -0800665 return f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700666}
667
Damien Neile91877d2019-06-27 10:54:42 -0700668// appendInt32Ptr wire encodes a *int32 pointer as a Int32.
Damien Neilc37adef2019-04-01 13:49:56 -0700669// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -0700670func appendInt32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700671 v := **p.Int32Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -0800672 b = protowire.AppendVarint(b, f.wiretag)
673 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700674 return b, nil
675}
676
Damien Neile91877d2019-06-27 10:54:42 -0700677// consumeInt32Ptr wire decodes a *int32 pointer as a Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700678func consumeInt32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -0800679 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -0800680 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700681 }
Damien Neiladbbc8e2020-01-24 17:01:14 -0800682 var v uint64
683 var n int
684 if len(b) >= 1 && b[0] < 0x80 {
685 v = uint64(b[0])
686 n = 1
687 } else if len(b) >= 2 && b[1] < 128 {
688 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
689 n = 2
690 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800691 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800692 }
Damien Neile91877d2019-06-27 10:54:42 -0700693 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700694 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700695 }
696 vp := p.Int32Ptr()
697 if *vp == nil {
698 *vp = new(int32)
699 }
700 **vp = int32(v)
Damien Neilf0831e82020-01-21 14:25:12 -0800701 out.n = n
702 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700703}
704
Damien Neilc37adef2019-04-01 13:49:56 -0700705var coderInt32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700706 size: sizeInt32Ptr,
707 marshal: appendInt32Ptr,
708 unmarshal: consumeInt32Ptr,
Damien Neile8e88752020-02-11 11:25:16 -0800709 merge: mergeInt32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -0700710}
711
712// sizeInt32Slice returns the size of wire encoding a []int32 pointer as a repeated Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700713func sizeInt32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -0700714 s := *p.Int32Slice()
715 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -0800716 size += f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700717 }
718 return size
719}
720
721// appendInt32Slice encodes a []int32 pointer as a repeated Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700722func appendInt32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700723 s := *p.Int32Slice()
724 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -0800725 b = protowire.AppendVarint(b, f.wiretag)
726 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700727 }
728 return b, nil
729}
730
Damien Neile91877d2019-06-27 10:54:42 -0700731// consumeInt32Slice wire decodes a []int32 pointer as a repeated Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700732func consumeInt32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -0700733 sp := p.Int32Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -0800734 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -0700735 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -0800736 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -0700737 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700738 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700739 }
740 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -0800741 var v uint64
742 var n int
743 if len(b) >= 1 && b[0] < 0x80 {
744 v = uint64(b[0])
745 n = 1
746 } else if len(b) >= 2 && b[1] < 128 {
747 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
748 n = 2
749 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800750 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800751 }
Damien Neile91877d2019-06-27 10:54:42 -0700752 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700753 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700754 }
755 s = append(s, int32(v))
756 b = b[n:]
757 }
758 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -0800759 out.n = n
760 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700761 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800762 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -0800763 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700764 }
Damien Neiladbbc8e2020-01-24 17:01:14 -0800765 var v uint64
766 var n int
767 if len(b) >= 1 && b[0] < 0x80 {
768 v = uint64(b[0])
769 n = 1
770 } else if len(b) >= 2 && b[1] < 128 {
771 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
772 n = 2
773 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800774 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800775 }
Damien Neile91877d2019-06-27 10:54:42 -0700776 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700777 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700778 }
779 *sp = append(*sp, int32(v))
Damien Neilf0831e82020-01-21 14:25:12 -0800780 out.n = n
781 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700782}
783
Damien Neilc37adef2019-04-01 13:49:56 -0700784var coderInt32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700785 size: sizeInt32Slice,
786 marshal: appendInt32Slice,
787 unmarshal: consumeInt32Slice,
Damien Neile8e88752020-02-11 11:25:16 -0800788 merge: mergeInt32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -0700789}
790
791// sizeInt32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700792func sizeInt32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -0700793 s := *p.Int32Slice()
794 if len(s) == 0 {
795 return 0
796 }
797 n := 0
798 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -0800799 n += protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700800 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800801 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -0700802}
803
804// appendInt32PackedSlice encodes a []int32 pointer as a packed repeated Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700805func appendInt32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700806 s := *p.Int32Slice()
807 if len(s) == 0 {
808 return b, nil
809 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800810 b = protowire.AppendVarint(b, f.wiretag)
Damien Neilc37adef2019-04-01 13:49:56 -0700811 n := 0
812 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -0800813 n += protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700814 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800815 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -0700816 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -0800817 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -0700818 }
819 return b, nil
820}
821
822var coderInt32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700823 size: sizeInt32PackedSlice,
824 marshal: appendInt32PackedSlice,
825 unmarshal: consumeInt32Slice,
Damien Neile8e88752020-02-11 11:25:16 -0800826 merge: mergeInt32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -0700827}
828
Damien Neil68b81c32019-08-22 11:41:32 -0700829// sizeInt32Value returns the size of wire encoding a int32 value as a Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700830func sizeInt32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -0800831 return tagsize + protowire.SizeVarint(uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700832}
833
Damien Neil68b81c32019-08-22 11:41:32 -0700834// appendInt32Value encodes a int32 value as a Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700835func appendInt32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -0800836 b = protowire.AppendVarint(b, wiretag)
837 b = protowire.AppendVarint(b, uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700838 return b, nil
839}
840
Damien Neil68b81c32019-08-22 11:41:32 -0700841// consumeInt32Value decodes a int32 value as a Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700842func consumeInt32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -0800843 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -0800844 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700845 }
Damien Neiladbbc8e2020-01-24 17:01:14 -0800846 var v uint64
847 var n int
848 if len(b) >= 1 && b[0] < 0x80 {
849 v = uint64(b[0])
850 n = 1
851 } else if len(b) >= 2 && b[1] < 128 {
852 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
853 n = 2
854 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800855 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800856 }
Damien Neile91877d2019-06-27 10:54:42 -0700857 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700858 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700859 }
Damien Neilf0831e82020-01-21 14:25:12 -0800860 out.n = n
861 return protoreflect.ValueOfInt32(int32(v)), out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700862}
863
Damien Neil68b81c32019-08-22 11:41:32 -0700864var coderInt32Value = valueCoderFuncs{
865 size: sizeInt32Value,
866 marshal: appendInt32Value,
867 unmarshal: consumeInt32Value,
Damien Neile8e88752020-02-11 11:25:16 -0800868 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -0700869}
870
Damien Neil68b81c32019-08-22 11:41:32 -0700871// sizeInt32SliceValue returns the size of wire encoding a []int32 value as a repeated Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700872func sizeInt32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -0700873 list := listv.List()
874 for i, llen := 0, list.Len(); i < llen; i++ {
875 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800876 size += tagsize + protowire.SizeVarint(uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700877 }
878 return size
879}
880
Damien Neil68b81c32019-08-22 11:41:32 -0700881// appendInt32SliceValue encodes a []int32 value as a repeated Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700882func appendInt32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -0700883 list := listv.List()
884 for i, llen := 0, list.Len(); i < llen; i++ {
885 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800886 b = protowire.AppendVarint(b, wiretag)
887 b = protowire.AppendVarint(b, uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700888 }
889 return b, nil
890}
891
Damien Neil68b81c32019-08-22 11:41:32 -0700892// consumeInt32SliceValue wire decodes a []int32 value as a repeated Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700893func consumeInt32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -0700894 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -0800895 if wtyp == protowire.BytesType {
896 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -0700897 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700898 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700899 }
900 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -0800901 var v uint64
902 var n int
903 if len(b) >= 1 && b[0] < 0x80 {
904 v = uint64(b[0])
905 n = 1
906 } else if len(b) >= 2 && b[1] < 128 {
907 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
908 n = 2
909 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800910 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800911 }
Damien Neile91877d2019-06-27 10:54:42 -0700912 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700913 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700914 }
Damien Neil68b81c32019-08-22 11:41:32 -0700915 list.Append(protoreflect.ValueOfInt32(int32(v)))
Damien Neile91877d2019-06-27 10:54:42 -0700916 b = b[n:]
917 }
Damien Neilf0831e82020-01-21 14:25:12 -0800918 out.n = n
919 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700920 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800921 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -0800922 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700923 }
Damien Neiladbbc8e2020-01-24 17:01:14 -0800924 var v uint64
925 var n int
926 if len(b) >= 1 && b[0] < 0x80 {
927 v = uint64(b[0])
928 n = 1
929 } else if len(b) >= 2 && b[1] < 128 {
930 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
931 n = 2
932 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -0800933 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -0800934 }
Damien Neile91877d2019-06-27 10:54:42 -0700935 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -0700936 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -0700937 }
Damien Neil68b81c32019-08-22 11:41:32 -0700938 list.Append(protoreflect.ValueOfInt32(int32(v)))
Damien Neilf0831e82020-01-21 14:25:12 -0800939 out.n = n
940 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -0700941}
942
Damien Neil68b81c32019-08-22 11:41:32 -0700943var coderInt32SliceValue = valueCoderFuncs{
944 size: sizeInt32SliceValue,
945 marshal: appendInt32SliceValue,
946 unmarshal: consumeInt32SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -0800947 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -0700948}
949
Damien Neil68b81c32019-08-22 11:41:32 -0700950// sizeInt32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700951func sizeInt32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -0700952 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -0800953 llen := list.Len()
954 if llen == 0 {
955 return 0
956 }
Damien Neil7492a092019-07-10 15:23:29 -0700957 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -0800958 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -0700959 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800960 n += protowire.SizeVarint(uint64(int32(v.Int())))
Damien Neil7492a092019-07-10 15:23:29 -0700961 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800962 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -0700963}
964
Damien Neil68b81c32019-08-22 11:41:32 -0700965// appendInt32PackedSliceValue encodes a []int32 value as a packed repeated Int32.
Joe Tsai41134b72020-10-19 20:51:03 -0700966func appendInt32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -0700967 list := listv.List()
968 llen := list.Len()
969 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -0700970 return b, nil
971 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800972 b = protowire.AppendVarint(b, wiretag)
Damien Neil7492a092019-07-10 15:23:29 -0700973 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -0700974 for i := 0; i < llen; i++ {
975 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800976 n += protowire.SizeVarint(uint64(int32(v.Int())))
Damien Neil7492a092019-07-10 15:23:29 -0700977 }
Joe Tsaicd108d02020-02-14 18:08:02 -0800978 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -0700979 for i := 0; i < llen; i++ {
980 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -0800981 b = protowire.AppendVarint(b, uint64(int32(v.Int())))
Damien Neil7492a092019-07-10 15:23:29 -0700982 }
983 return b, nil
984}
985
Damien Neil68b81c32019-08-22 11:41:32 -0700986var coderInt32PackedSliceValue = valueCoderFuncs{
987 size: sizeInt32PackedSliceValue,
988 marshal: appendInt32PackedSliceValue,
989 unmarshal: consumeInt32SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -0800990 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -0700991}
992
Damien Neilc37adef2019-04-01 13:49:56 -0700993// sizeSint32 returns the size of wire encoding a int32 pointer as a Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -0700994func sizeSint32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -0700995 v := *p.Int32()
Joe Tsaicd108d02020-02-14 18:08:02 -0800996 return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
Damien Neilc37adef2019-04-01 13:49:56 -0700997}
998
999// appendSint32 wire encodes a int32 pointer as a Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001000func appendSint32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001001 v := *p.Int32()
Joe Tsaicd108d02020-02-14 18:08:02 -08001002 b = protowire.AppendVarint(b, f.wiretag)
1003 b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v)))
Damien Neilc37adef2019-04-01 13:49:56 -07001004 return b, nil
1005}
1006
Damien Neile91877d2019-06-27 10:54:42 -07001007// consumeSint32 wire decodes a int32 pointer as a Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001008func consumeSint32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08001009 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001010 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001011 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001012 var v uint64
1013 var n int
1014 if len(b) >= 1 && b[0] < 0x80 {
1015 v = uint64(b[0])
1016 n = 1
1017 } else if len(b) >= 2 && b[1] < 128 {
1018 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1019 n = 2
1020 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001021 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001022 }
Damien Neile91877d2019-06-27 10:54:42 -07001023 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001024 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001025 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001026 *p.Int32() = int32(protowire.DecodeZigZag(v & math.MaxUint32))
Damien Neilf0831e82020-01-21 14:25:12 -08001027 out.n = n
1028 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001029}
1030
Damien Neilc37adef2019-04-01 13:49:56 -07001031var coderSint32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001032 size: sizeSint32,
1033 marshal: appendSint32,
1034 unmarshal: consumeSint32,
Damien Neile8e88752020-02-11 11:25:16 -08001035 merge: mergeInt32,
Damien Neilc37adef2019-04-01 13:49:56 -07001036}
1037
Joe Tsaic51e2e02019-07-13 00:44:41 -07001038// sizeSint32NoZero returns the size of wire encoding a int32 pointer as a Sint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001039// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07001040func sizeSint32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001041 v := *p.Int32()
1042 if v == 0 {
1043 return 0
1044 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001045 return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
Damien Neilc37adef2019-04-01 13:49:56 -07001046}
1047
Joe Tsaic51e2e02019-07-13 00:44:41 -07001048// appendSint32NoZero wire encodes a int32 pointer as a Sint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001049// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07001050func appendSint32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001051 v := *p.Int32()
1052 if v == 0 {
1053 return b, nil
1054 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001055 b = protowire.AppendVarint(b, f.wiretag)
1056 b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v)))
Damien Neilc37adef2019-04-01 13:49:56 -07001057 return b, nil
1058}
1059
1060var coderSint32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001061 size: sizeSint32NoZero,
1062 marshal: appendSint32NoZero,
1063 unmarshal: consumeSint32,
Damien Neile8e88752020-02-11 11:25:16 -08001064 merge: mergeInt32NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07001065}
1066
1067// sizeSint32Ptr returns the size of wire encoding a *int32 pointer as a Sint32.
1068// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07001069func sizeSint32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001070 v := **p.Int32Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08001071 return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
Damien Neilc37adef2019-04-01 13:49:56 -07001072}
1073
Damien Neile91877d2019-06-27 10:54:42 -07001074// appendSint32Ptr wire encodes a *int32 pointer as a Sint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001075// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07001076func appendSint32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001077 v := **p.Int32Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08001078 b = protowire.AppendVarint(b, f.wiretag)
1079 b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v)))
Damien Neilc37adef2019-04-01 13:49:56 -07001080 return b, nil
1081}
1082
Damien Neile91877d2019-06-27 10:54:42 -07001083// consumeSint32Ptr wire decodes a *int32 pointer as a Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001084func consumeSint32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08001085 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001086 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001087 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001088 var v uint64
1089 var n int
1090 if len(b) >= 1 && b[0] < 0x80 {
1091 v = uint64(b[0])
1092 n = 1
1093 } else if len(b) >= 2 && b[1] < 128 {
1094 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1095 n = 2
1096 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001097 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001098 }
Damien Neile91877d2019-06-27 10:54:42 -07001099 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001100 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001101 }
1102 vp := p.Int32Ptr()
1103 if *vp == nil {
1104 *vp = new(int32)
1105 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001106 **vp = int32(protowire.DecodeZigZag(v & math.MaxUint32))
Damien Neilf0831e82020-01-21 14:25:12 -08001107 out.n = n
1108 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001109}
1110
Damien Neilc37adef2019-04-01 13:49:56 -07001111var coderSint32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001112 size: sizeSint32Ptr,
1113 marshal: appendSint32Ptr,
1114 unmarshal: consumeSint32Ptr,
Damien Neile8e88752020-02-11 11:25:16 -08001115 merge: mergeInt32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07001116}
1117
1118// sizeSint32Slice returns the size of wire encoding a []int32 pointer as a repeated Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001119func sizeSint32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001120 s := *p.Int32Slice()
1121 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001122 size += f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
Damien Neilc37adef2019-04-01 13:49:56 -07001123 }
1124 return size
1125}
1126
1127// appendSint32Slice encodes a []int32 pointer as a repeated Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001128func appendSint32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001129 s := *p.Int32Slice()
1130 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001131 b = protowire.AppendVarint(b, f.wiretag)
1132 b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v)))
Damien Neilc37adef2019-04-01 13:49:56 -07001133 }
1134 return b, nil
1135}
1136
Damien Neile91877d2019-06-27 10:54:42 -07001137// consumeSint32Slice wire decodes a []int32 pointer as a repeated Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001138func consumeSint32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07001139 sp := p.Int32Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08001140 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07001141 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -08001142 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07001143 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001144 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001145 }
1146 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -08001147 var v uint64
1148 var n int
1149 if len(b) >= 1 && b[0] < 0x80 {
1150 v = uint64(b[0])
1151 n = 1
1152 } else if len(b) >= 2 && b[1] < 128 {
1153 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1154 n = 2
1155 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001156 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001157 }
Damien Neile91877d2019-06-27 10:54:42 -07001158 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001159 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001160 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001161 s = append(s, int32(protowire.DecodeZigZag(v&math.MaxUint32)))
Damien Neile91877d2019-06-27 10:54:42 -07001162 b = b[n:]
1163 }
1164 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -08001165 out.n = n
1166 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001167 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001168 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001169 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001170 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001171 var v uint64
1172 var n int
1173 if len(b) >= 1 && b[0] < 0x80 {
1174 v = uint64(b[0])
1175 n = 1
1176 } else if len(b) >= 2 && b[1] < 128 {
1177 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1178 n = 2
1179 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001180 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001181 }
Damien Neile91877d2019-06-27 10:54:42 -07001182 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001183 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001184 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001185 *sp = append(*sp, int32(protowire.DecodeZigZag(v&math.MaxUint32)))
Damien Neilf0831e82020-01-21 14:25:12 -08001186 out.n = n
1187 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001188}
1189
Damien Neilc37adef2019-04-01 13:49:56 -07001190var coderSint32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001191 size: sizeSint32Slice,
1192 marshal: appendSint32Slice,
1193 unmarshal: consumeSint32Slice,
Damien Neile8e88752020-02-11 11:25:16 -08001194 merge: mergeInt32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001195}
1196
1197// sizeSint32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001198func sizeSint32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001199 s := *p.Int32Slice()
1200 if len(s) == 0 {
1201 return 0
1202 }
1203 n := 0
1204 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001205 n += protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
Damien Neilc37adef2019-04-01 13:49:56 -07001206 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001207 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -07001208}
1209
1210// appendSint32PackedSlice encodes a []int32 pointer as a packed repeated Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001211func appendSint32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001212 s := *p.Int32Slice()
1213 if len(s) == 0 {
1214 return b, nil
1215 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001216 b = protowire.AppendVarint(b, f.wiretag)
Damien Neilc37adef2019-04-01 13:49:56 -07001217 n := 0
1218 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001219 n += protowire.SizeVarint(protowire.EncodeZigZag(int64(v)))
Damien Neilc37adef2019-04-01 13:49:56 -07001220 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001221 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -07001222 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001223 b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v)))
Damien Neilc37adef2019-04-01 13:49:56 -07001224 }
1225 return b, nil
1226}
1227
1228var coderSint32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001229 size: sizeSint32PackedSlice,
1230 marshal: appendSint32PackedSlice,
1231 unmarshal: consumeSint32Slice,
Damien Neile8e88752020-02-11 11:25:16 -08001232 merge: mergeInt32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001233}
1234
Damien Neil68b81c32019-08-22 11:41:32 -07001235// sizeSint32Value returns the size of wire encoding a int32 value as a Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001236func sizeSint32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08001237 return tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -07001238}
1239
Damien Neil68b81c32019-08-22 11:41:32 -07001240// appendSint32Value encodes a int32 value as a Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001241func appendSint32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08001242 b = protowire.AppendVarint(b, wiretag)
1243 b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -07001244 return b, nil
1245}
1246
Damien Neil68b81c32019-08-22 11:41:32 -07001247// consumeSint32Value decodes a int32 value as a Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001248func consumeSint32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08001249 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001250 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001251 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001252 var v uint64
1253 var n int
1254 if len(b) >= 1 && b[0] < 0x80 {
1255 v = uint64(b[0])
1256 n = 1
1257 } else if len(b) >= 2 && b[1] < 128 {
1258 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1259 n = 2
1260 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001261 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001262 }
Damien Neile91877d2019-06-27 10:54:42 -07001263 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001264 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001265 }
Damien Neilf0831e82020-01-21 14:25:12 -08001266 out.n = n
Joe Tsaicd108d02020-02-14 18:08:02 -08001267 return protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001268}
1269
Damien Neil68b81c32019-08-22 11:41:32 -07001270var coderSint32Value = valueCoderFuncs{
1271 size: sizeSint32Value,
1272 marshal: appendSint32Value,
1273 unmarshal: consumeSint32Value,
Damien Neile8e88752020-02-11 11:25:16 -08001274 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07001275}
1276
Damien Neil68b81c32019-08-22 11:41:32 -07001277// sizeSint32SliceValue returns the size of wire encoding a []int32 value as a repeated Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001278func sizeSint32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07001279 list := listv.List()
1280 for i, llen := 0, list.Len(); i < llen; i++ {
1281 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08001282 size += tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -07001283 }
1284 return size
1285}
1286
Damien Neil68b81c32019-08-22 11:41:32 -07001287// appendSint32SliceValue encodes a []int32 value as a repeated Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001288func appendSint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07001289 list := listv.List()
1290 for i, llen := 0, list.Len(); i < llen; i++ {
1291 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08001292 b = protowire.AppendVarint(b, wiretag)
1293 b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -07001294 }
1295 return b, nil
1296}
1297
Damien Neil68b81c32019-08-22 11:41:32 -07001298// consumeSint32SliceValue wire decodes a []int32 value as a repeated Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001299func consumeSint32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07001300 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08001301 if wtyp == protowire.BytesType {
1302 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07001303 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001304 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001305 }
1306 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -08001307 var v uint64
1308 var n int
1309 if len(b) >= 1 && b[0] < 0x80 {
1310 v = uint64(b[0])
1311 n = 1
1312 } else if len(b) >= 2 && b[1] < 128 {
1313 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1314 n = 2
1315 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001316 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001317 }
Damien Neile91877d2019-06-27 10:54:42 -07001318 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001319 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001320 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001321 list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))))
Damien Neile91877d2019-06-27 10:54:42 -07001322 b = b[n:]
1323 }
Damien Neilf0831e82020-01-21 14:25:12 -08001324 out.n = n
1325 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001326 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001327 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001328 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001329 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001330 var v uint64
1331 var n int
1332 if len(b) >= 1 && b[0] < 0x80 {
1333 v = uint64(b[0])
1334 n = 1
1335 } else if len(b) >= 2 && b[1] < 128 {
1336 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1337 n = 2
1338 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001339 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001340 }
Damien Neile91877d2019-06-27 10:54:42 -07001341 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001342 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001343 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001344 list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))))
Damien Neilf0831e82020-01-21 14:25:12 -08001345 out.n = n
1346 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001347}
1348
Damien Neil68b81c32019-08-22 11:41:32 -07001349var coderSint32SliceValue = valueCoderFuncs{
1350 size: sizeSint32SliceValue,
1351 marshal: appendSint32SliceValue,
1352 unmarshal: consumeSint32SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08001353 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07001354}
1355
Damien Neil68b81c32019-08-22 11:41:32 -07001356// sizeSint32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001357func sizeSint32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07001358 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08001359 llen := list.Len()
1360 if llen == 0 {
1361 return 0
1362 }
Damien Neil7492a092019-07-10 15:23:29 -07001363 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -08001364 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -07001365 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08001366 n += protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neil7492a092019-07-10 15:23:29 -07001367 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001368 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -07001369}
1370
Damien Neil68b81c32019-08-22 11:41:32 -07001371// appendSint32PackedSliceValue encodes a []int32 value as a packed repeated Sint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001372func appendSint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07001373 list := listv.List()
1374 llen := list.Len()
1375 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07001376 return b, nil
1377 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001378 b = protowire.AppendVarint(b, wiretag)
Damien Neil7492a092019-07-10 15:23:29 -07001379 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07001380 for i := 0; i < llen; i++ {
1381 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08001382 n += protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neil7492a092019-07-10 15:23:29 -07001383 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001384 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07001385 for i := 0; i < llen; i++ {
1386 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08001387 b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neil7492a092019-07-10 15:23:29 -07001388 }
1389 return b, nil
1390}
1391
Damien Neil68b81c32019-08-22 11:41:32 -07001392var coderSint32PackedSliceValue = valueCoderFuncs{
1393 size: sizeSint32PackedSliceValue,
1394 marshal: appendSint32PackedSliceValue,
1395 unmarshal: consumeSint32SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08001396 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -07001397}
1398
Damien Neilc37adef2019-04-01 13:49:56 -07001399// sizeUint32 returns the size of wire encoding a uint32 pointer as a Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001400func sizeUint32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001401 v := *p.Uint32()
Joe Tsaicd108d02020-02-14 18:08:02 -08001402 return f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001403}
1404
1405// appendUint32 wire encodes a uint32 pointer as a Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001406func appendUint32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001407 v := *p.Uint32()
Joe Tsaicd108d02020-02-14 18:08:02 -08001408 b = protowire.AppendVarint(b, f.wiretag)
1409 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001410 return b, nil
1411}
1412
Damien Neile91877d2019-06-27 10:54:42 -07001413// consumeUint32 wire decodes a uint32 pointer as a Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001414func consumeUint32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08001415 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001416 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001417 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001418 var v uint64
1419 var n int
1420 if len(b) >= 1 && b[0] < 0x80 {
1421 v = uint64(b[0])
1422 n = 1
1423 } else if len(b) >= 2 && b[1] < 128 {
1424 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1425 n = 2
1426 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001427 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001428 }
Damien Neile91877d2019-06-27 10:54:42 -07001429 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001430 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001431 }
1432 *p.Uint32() = uint32(v)
Damien Neilf0831e82020-01-21 14:25:12 -08001433 out.n = n
1434 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001435}
1436
Damien Neilc37adef2019-04-01 13:49:56 -07001437var coderUint32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001438 size: sizeUint32,
1439 marshal: appendUint32,
1440 unmarshal: consumeUint32,
Damien Neile8e88752020-02-11 11:25:16 -08001441 merge: mergeUint32,
Damien Neilc37adef2019-04-01 13:49:56 -07001442}
1443
Joe Tsaic51e2e02019-07-13 00:44:41 -07001444// sizeUint32NoZero returns the size of wire encoding a uint32 pointer as a Uint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001445// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07001446func sizeUint32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001447 v := *p.Uint32()
1448 if v == 0 {
1449 return 0
1450 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001451 return f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001452}
1453
Joe Tsaic51e2e02019-07-13 00:44:41 -07001454// appendUint32NoZero wire encodes a uint32 pointer as a Uint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001455// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07001456func appendUint32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001457 v := *p.Uint32()
1458 if v == 0 {
1459 return b, nil
1460 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001461 b = protowire.AppendVarint(b, f.wiretag)
1462 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001463 return b, nil
1464}
1465
1466var coderUint32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001467 size: sizeUint32NoZero,
1468 marshal: appendUint32NoZero,
1469 unmarshal: consumeUint32,
Damien Neile8e88752020-02-11 11:25:16 -08001470 merge: mergeUint32NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07001471}
1472
1473// sizeUint32Ptr returns the size of wire encoding a *uint32 pointer as a Uint32.
1474// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07001475func sizeUint32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001476 v := **p.Uint32Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08001477 return f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001478}
1479
Damien Neile91877d2019-06-27 10:54:42 -07001480// appendUint32Ptr wire encodes a *uint32 pointer as a Uint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001481// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07001482func appendUint32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001483 v := **p.Uint32Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08001484 b = protowire.AppendVarint(b, f.wiretag)
1485 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001486 return b, nil
1487}
1488
Damien Neile91877d2019-06-27 10:54:42 -07001489// consumeUint32Ptr wire decodes a *uint32 pointer as a Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001490func consumeUint32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08001491 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001492 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001493 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001494 var v uint64
1495 var n int
1496 if len(b) >= 1 && b[0] < 0x80 {
1497 v = uint64(b[0])
1498 n = 1
1499 } else if len(b) >= 2 && b[1] < 128 {
1500 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1501 n = 2
1502 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001503 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001504 }
Damien Neile91877d2019-06-27 10:54:42 -07001505 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001506 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001507 }
1508 vp := p.Uint32Ptr()
1509 if *vp == nil {
1510 *vp = new(uint32)
1511 }
1512 **vp = uint32(v)
Damien Neilf0831e82020-01-21 14:25:12 -08001513 out.n = n
1514 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001515}
1516
Damien Neilc37adef2019-04-01 13:49:56 -07001517var coderUint32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001518 size: sizeUint32Ptr,
1519 marshal: appendUint32Ptr,
1520 unmarshal: consumeUint32Ptr,
Damien Neile8e88752020-02-11 11:25:16 -08001521 merge: mergeUint32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07001522}
1523
1524// sizeUint32Slice returns the size of wire encoding a []uint32 pointer as a repeated Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001525func sizeUint32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001526 s := *p.Uint32Slice()
1527 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001528 size += f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001529 }
1530 return size
1531}
1532
1533// appendUint32Slice encodes a []uint32 pointer as a repeated Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001534func appendUint32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001535 s := *p.Uint32Slice()
1536 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001537 b = protowire.AppendVarint(b, f.wiretag)
1538 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001539 }
1540 return b, nil
1541}
1542
Damien Neile91877d2019-06-27 10:54:42 -07001543// consumeUint32Slice wire decodes a []uint32 pointer as a repeated Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001544func consumeUint32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07001545 sp := p.Uint32Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08001546 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07001547 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -08001548 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07001549 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001550 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001551 }
1552 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -08001553 var v uint64
1554 var n int
1555 if len(b) >= 1 && b[0] < 0x80 {
1556 v = uint64(b[0])
1557 n = 1
1558 } else if len(b) >= 2 && b[1] < 128 {
1559 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1560 n = 2
1561 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001562 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001563 }
Damien Neile91877d2019-06-27 10:54:42 -07001564 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001565 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001566 }
1567 s = append(s, uint32(v))
1568 b = b[n:]
1569 }
1570 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -08001571 out.n = n
1572 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001573 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001574 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001575 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001576 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001577 var v uint64
1578 var n int
1579 if len(b) >= 1 && b[0] < 0x80 {
1580 v = uint64(b[0])
1581 n = 1
1582 } else if len(b) >= 2 && b[1] < 128 {
1583 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1584 n = 2
1585 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001586 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001587 }
Damien Neile91877d2019-06-27 10:54:42 -07001588 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001589 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001590 }
1591 *sp = append(*sp, uint32(v))
Damien Neilf0831e82020-01-21 14:25:12 -08001592 out.n = n
1593 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001594}
1595
Damien Neilc37adef2019-04-01 13:49:56 -07001596var coderUint32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001597 size: sizeUint32Slice,
1598 marshal: appendUint32Slice,
1599 unmarshal: consumeUint32Slice,
Damien Neile8e88752020-02-11 11:25:16 -08001600 merge: mergeUint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001601}
1602
1603// sizeUint32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001604func sizeUint32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001605 s := *p.Uint32Slice()
1606 if len(s) == 0 {
1607 return 0
1608 }
1609 n := 0
1610 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001611 n += protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001612 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001613 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -07001614}
1615
1616// appendUint32PackedSlice encodes a []uint32 pointer as a packed repeated Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001617func appendUint32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001618 s := *p.Uint32Slice()
1619 if len(s) == 0 {
1620 return b, nil
1621 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001622 b = protowire.AppendVarint(b, f.wiretag)
Damien Neilc37adef2019-04-01 13:49:56 -07001623 n := 0
1624 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001625 n += protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001626 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001627 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -07001628 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001629 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001630 }
1631 return b, nil
1632}
1633
1634var coderUint32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001635 size: sizeUint32PackedSlice,
1636 marshal: appendUint32PackedSlice,
1637 unmarshal: consumeUint32Slice,
Damien Neile8e88752020-02-11 11:25:16 -08001638 merge: mergeUint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001639}
1640
Damien Neil68b81c32019-08-22 11:41:32 -07001641// sizeUint32Value returns the size of wire encoding a uint32 value as a Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001642func sizeUint32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08001643 return tagsize + protowire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001644}
1645
Damien Neil68b81c32019-08-22 11:41:32 -07001646// appendUint32Value encodes a uint32 value as a Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001647func appendUint32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08001648 b = protowire.AppendVarint(b, wiretag)
1649 b = protowire.AppendVarint(b, uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001650 return b, nil
1651}
1652
Damien Neil68b81c32019-08-22 11:41:32 -07001653// consumeUint32Value decodes a uint32 value as a Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001654func consumeUint32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08001655 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001656 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001657 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001658 var v uint64
1659 var n int
1660 if len(b) >= 1 && b[0] < 0x80 {
1661 v = uint64(b[0])
1662 n = 1
1663 } else if len(b) >= 2 && b[1] < 128 {
1664 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1665 n = 2
1666 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001667 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001668 }
Damien Neile91877d2019-06-27 10:54:42 -07001669 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001670 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001671 }
Damien Neilf0831e82020-01-21 14:25:12 -08001672 out.n = n
1673 return protoreflect.ValueOfUint32(uint32(v)), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001674}
1675
Damien Neil68b81c32019-08-22 11:41:32 -07001676var coderUint32Value = valueCoderFuncs{
1677 size: sizeUint32Value,
1678 marshal: appendUint32Value,
1679 unmarshal: consumeUint32Value,
Damien Neile8e88752020-02-11 11:25:16 -08001680 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07001681}
1682
Damien Neil68b81c32019-08-22 11:41:32 -07001683// sizeUint32SliceValue returns the size of wire encoding a []uint32 value as a repeated Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001684func sizeUint32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07001685 list := listv.List()
1686 for i, llen := 0, list.Len(); i < llen; i++ {
1687 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08001688 size += tagsize + protowire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001689 }
1690 return size
1691}
1692
Damien Neil68b81c32019-08-22 11:41:32 -07001693// appendUint32SliceValue encodes a []uint32 value as a repeated Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001694func appendUint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07001695 list := listv.List()
1696 for i, llen := 0, list.Len(); i < llen; i++ {
1697 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08001698 b = protowire.AppendVarint(b, wiretag)
1699 b = protowire.AppendVarint(b, uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001700 }
1701 return b, nil
1702}
1703
Damien Neil68b81c32019-08-22 11:41:32 -07001704// consumeUint32SliceValue wire decodes a []uint32 value as a repeated Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001705func consumeUint32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07001706 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08001707 if wtyp == protowire.BytesType {
1708 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07001709 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001710 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001711 }
1712 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -08001713 var v uint64
1714 var n int
1715 if len(b) >= 1 && b[0] < 0x80 {
1716 v = uint64(b[0])
1717 n = 1
1718 } else if len(b) >= 2 && b[1] < 128 {
1719 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1720 n = 2
1721 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001722 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001723 }
Damien Neile91877d2019-06-27 10:54:42 -07001724 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001725 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001726 }
Damien Neil68b81c32019-08-22 11:41:32 -07001727 list.Append(protoreflect.ValueOfUint32(uint32(v)))
Damien Neile91877d2019-06-27 10:54:42 -07001728 b = b[n:]
1729 }
Damien Neilf0831e82020-01-21 14:25:12 -08001730 out.n = n
1731 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001732 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001733 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001734 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001735 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001736 var v uint64
1737 var n int
1738 if len(b) >= 1 && b[0] < 0x80 {
1739 v = uint64(b[0])
1740 n = 1
1741 } else if len(b) >= 2 && b[1] < 128 {
1742 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1743 n = 2
1744 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001745 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001746 }
Damien Neile91877d2019-06-27 10:54:42 -07001747 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001748 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001749 }
Damien Neil68b81c32019-08-22 11:41:32 -07001750 list.Append(protoreflect.ValueOfUint32(uint32(v)))
Damien Neilf0831e82020-01-21 14:25:12 -08001751 out.n = n
1752 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001753}
1754
Damien Neil68b81c32019-08-22 11:41:32 -07001755var coderUint32SliceValue = valueCoderFuncs{
1756 size: sizeUint32SliceValue,
1757 marshal: appendUint32SliceValue,
1758 unmarshal: consumeUint32SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08001759 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07001760}
1761
Damien Neil68b81c32019-08-22 11:41:32 -07001762// sizeUint32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001763func sizeUint32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07001764 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08001765 llen := list.Len()
1766 if llen == 0 {
1767 return 0
1768 }
Damien Neil7492a092019-07-10 15:23:29 -07001769 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -08001770 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -07001771 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08001772 n += protowire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neil7492a092019-07-10 15:23:29 -07001773 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001774 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -07001775}
1776
Damien Neil68b81c32019-08-22 11:41:32 -07001777// appendUint32PackedSliceValue encodes a []uint32 value as a packed repeated Uint32.
Joe Tsai41134b72020-10-19 20:51:03 -07001778func appendUint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07001779 list := listv.List()
1780 llen := list.Len()
1781 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07001782 return b, nil
1783 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001784 b = protowire.AppendVarint(b, wiretag)
Damien Neil7492a092019-07-10 15:23:29 -07001785 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07001786 for i := 0; i < llen; i++ {
1787 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08001788 n += protowire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neil7492a092019-07-10 15:23:29 -07001789 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001790 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07001791 for i := 0; i < llen; i++ {
1792 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08001793 b = protowire.AppendVarint(b, uint64(uint32(v.Uint())))
Damien Neil7492a092019-07-10 15:23:29 -07001794 }
1795 return b, nil
1796}
1797
Damien Neil68b81c32019-08-22 11:41:32 -07001798var coderUint32PackedSliceValue = valueCoderFuncs{
1799 size: sizeUint32PackedSliceValue,
1800 marshal: appendUint32PackedSliceValue,
1801 unmarshal: consumeUint32SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08001802 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -07001803}
1804
Damien Neilc37adef2019-04-01 13:49:56 -07001805// sizeInt64 returns the size of wire encoding a int64 pointer as a Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07001806func sizeInt64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001807 v := *p.Int64()
Joe Tsaicd108d02020-02-14 18:08:02 -08001808 return f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001809}
1810
1811// appendInt64 wire encodes a int64 pointer as a Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07001812func appendInt64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001813 v := *p.Int64()
Joe Tsaicd108d02020-02-14 18:08:02 -08001814 b = protowire.AppendVarint(b, f.wiretag)
1815 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001816 return b, nil
1817}
1818
Damien Neile91877d2019-06-27 10:54:42 -07001819// consumeInt64 wire decodes a int64 pointer as a Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07001820func consumeInt64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08001821 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001822 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001823 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001824 var v uint64
1825 var n int
1826 if len(b) >= 1 && b[0] < 0x80 {
1827 v = uint64(b[0])
1828 n = 1
1829 } else if len(b) >= 2 && b[1] < 128 {
1830 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1831 n = 2
1832 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001833 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001834 }
Damien Neile91877d2019-06-27 10:54:42 -07001835 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001836 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001837 }
1838 *p.Int64() = int64(v)
Damien Neilf0831e82020-01-21 14:25:12 -08001839 out.n = n
1840 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001841}
1842
Damien Neilc37adef2019-04-01 13:49:56 -07001843var coderInt64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001844 size: sizeInt64,
1845 marshal: appendInt64,
1846 unmarshal: consumeInt64,
Damien Neile8e88752020-02-11 11:25:16 -08001847 merge: mergeInt64,
Damien Neilc37adef2019-04-01 13:49:56 -07001848}
1849
Joe Tsaic51e2e02019-07-13 00:44:41 -07001850// sizeInt64NoZero returns the size of wire encoding a int64 pointer as a Int64.
Damien Neilc37adef2019-04-01 13:49:56 -07001851// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07001852func sizeInt64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001853 v := *p.Int64()
1854 if v == 0 {
1855 return 0
1856 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001857 return f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001858}
1859
Joe Tsaic51e2e02019-07-13 00:44:41 -07001860// appendInt64NoZero wire encodes a int64 pointer as a Int64.
Damien Neilc37adef2019-04-01 13:49:56 -07001861// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07001862func appendInt64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001863 v := *p.Int64()
1864 if v == 0 {
1865 return b, nil
1866 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001867 b = protowire.AppendVarint(b, f.wiretag)
1868 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001869 return b, nil
1870}
1871
1872var coderInt64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001873 size: sizeInt64NoZero,
1874 marshal: appendInt64NoZero,
1875 unmarshal: consumeInt64,
Damien Neile8e88752020-02-11 11:25:16 -08001876 merge: mergeInt64NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07001877}
1878
1879// sizeInt64Ptr returns the size of wire encoding a *int64 pointer as a Int64.
1880// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07001881func sizeInt64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001882 v := **p.Int64Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08001883 return f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001884}
1885
Damien Neile91877d2019-06-27 10:54:42 -07001886// appendInt64Ptr wire encodes a *int64 pointer as a Int64.
Damien Neilc37adef2019-04-01 13:49:56 -07001887// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07001888func appendInt64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001889 v := **p.Int64Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08001890 b = protowire.AppendVarint(b, f.wiretag)
1891 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001892 return b, nil
1893}
1894
Damien Neile91877d2019-06-27 10:54:42 -07001895// consumeInt64Ptr wire decodes a *int64 pointer as a Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07001896func consumeInt64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08001897 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001898 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001899 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001900 var v uint64
1901 var n int
1902 if len(b) >= 1 && b[0] < 0x80 {
1903 v = uint64(b[0])
1904 n = 1
1905 } else if len(b) >= 2 && b[1] < 128 {
1906 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1907 n = 2
1908 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001909 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001910 }
Damien Neile91877d2019-06-27 10:54:42 -07001911 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001912 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001913 }
1914 vp := p.Int64Ptr()
1915 if *vp == nil {
1916 *vp = new(int64)
1917 }
1918 **vp = int64(v)
Damien Neilf0831e82020-01-21 14:25:12 -08001919 out.n = n
1920 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001921}
1922
Damien Neilc37adef2019-04-01 13:49:56 -07001923var coderInt64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001924 size: sizeInt64Ptr,
1925 marshal: appendInt64Ptr,
1926 unmarshal: consumeInt64Ptr,
Damien Neile8e88752020-02-11 11:25:16 -08001927 merge: mergeInt64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07001928}
1929
1930// sizeInt64Slice returns the size of wire encoding a []int64 pointer as a repeated Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07001931func sizeInt64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07001932 s := *p.Int64Slice()
1933 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001934 size += f.tagsize + protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001935 }
1936 return size
1937}
1938
1939// appendInt64Slice encodes a []int64 pointer as a repeated Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07001940func appendInt64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001941 s := *p.Int64Slice()
1942 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08001943 b = protowire.AppendVarint(b, f.wiretag)
1944 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07001945 }
1946 return b, nil
1947}
1948
Damien Neile91877d2019-06-27 10:54:42 -07001949// consumeInt64Slice wire decodes a []int64 pointer as a repeated Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07001950func consumeInt64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07001951 sp := p.Int64Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08001952 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07001953 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -08001954 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07001955 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001956 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001957 }
1958 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -08001959 var v uint64
1960 var n int
1961 if len(b) >= 1 && b[0] < 0x80 {
1962 v = uint64(b[0])
1963 n = 1
1964 } else if len(b) >= 2 && b[1] < 128 {
1965 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1966 n = 2
1967 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001968 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001969 }
Damien Neile91877d2019-06-27 10:54:42 -07001970 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001971 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001972 }
1973 s = append(s, int64(v))
1974 b = b[n:]
1975 }
1976 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -08001977 out.n = n
1978 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07001979 }
Joe Tsaicd108d02020-02-14 18:08:02 -08001980 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08001981 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001982 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08001983 var v uint64
1984 var n int
1985 if len(b) >= 1 && b[0] < 0x80 {
1986 v = uint64(b[0])
1987 n = 1
1988 } else if len(b) >= 2 && b[1] < 128 {
1989 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
1990 n = 2
1991 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08001992 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08001993 }
Damien Neile91877d2019-06-27 10:54:42 -07001994 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07001995 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07001996 }
1997 *sp = append(*sp, int64(v))
Damien Neilf0831e82020-01-21 14:25:12 -08001998 out.n = n
1999 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002000}
2001
Damien Neilc37adef2019-04-01 13:49:56 -07002002var coderInt64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002003 size: sizeInt64Slice,
2004 marshal: appendInt64Slice,
2005 unmarshal: consumeInt64Slice,
Damien Neile8e88752020-02-11 11:25:16 -08002006 merge: mergeInt64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002007}
2008
2009// sizeInt64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07002010func sizeInt64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07002011 s := *p.Int64Slice()
2012 if len(s) == 0 {
2013 return 0
2014 }
2015 n := 0
2016 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002017 n += protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002018 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002019 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -07002020}
2021
2022// appendInt64PackedSlice encodes a []int64 pointer as a packed repeated Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07002023func appendInt64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002024 s := *p.Int64Slice()
2025 if len(s) == 0 {
2026 return b, nil
2027 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002028 b = protowire.AppendVarint(b, f.wiretag)
Damien Neilc37adef2019-04-01 13:49:56 -07002029 n := 0
2030 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002031 n += protowire.SizeVarint(uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002032 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002033 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -07002034 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002035 b = protowire.AppendVarint(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002036 }
2037 return b, nil
2038}
2039
2040var coderInt64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002041 size: sizeInt64PackedSlice,
2042 marshal: appendInt64PackedSlice,
2043 unmarshal: consumeInt64Slice,
Damien Neile8e88752020-02-11 11:25:16 -08002044 merge: mergeInt64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002045}
2046
Damien Neil68b81c32019-08-22 11:41:32 -07002047// sizeInt64Value returns the size of wire encoding a int64 value as a Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07002048func sizeInt64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08002049 return tagsize + protowire.SizeVarint(uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002050}
2051
Damien Neil68b81c32019-08-22 11:41:32 -07002052// appendInt64Value encodes a int64 value as a Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07002053func appendInt64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08002054 b = protowire.AppendVarint(b, wiretag)
2055 b = protowire.AppendVarint(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002056 return b, nil
2057}
2058
Damien Neil68b81c32019-08-22 11:41:32 -07002059// consumeInt64Value decodes a int64 value as a Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07002060func consumeInt64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08002061 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002062 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002063 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002064 var v uint64
2065 var n int
2066 if len(b) >= 1 && b[0] < 0x80 {
2067 v = uint64(b[0])
2068 n = 1
2069 } else if len(b) >= 2 && b[1] < 128 {
2070 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2071 n = 2
2072 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002073 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002074 }
Damien Neile91877d2019-06-27 10:54:42 -07002075 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002076 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002077 }
Damien Neilf0831e82020-01-21 14:25:12 -08002078 out.n = n
2079 return protoreflect.ValueOfInt64(int64(v)), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002080}
2081
Damien Neil68b81c32019-08-22 11:41:32 -07002082var coderInt64Value = valueCoderFuncs{
2083 size: sizeInt64Value,
2084 marshal: appendInt64Value,
2085 unmarshal: consumeInt64Value,
Damien Neile8e88752020-02-11 11:25:16 -08002086 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002087}
2088
Damien Neil68b81c32019-08-22 11:41:32 -07002089// sizeInt64SliceValue returns the size of wire encoding a []int64 value as a repeated Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07002090func sizeInt64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07002091 list := listv.List()
2092 for i, llen := 0, list.Len(); i < llen; i++ {
2093 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002094 size += tagsize + protowire.SizeVarint(uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002095 }
2096 return size
2097}
2098
Damien Neil68b81c32019-08-22 11:41:32 -07002099// appendInt64SliceValue encodes a []int64 value as a repeated Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07002100func appendInt64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07002101 list := listv.List()
2102 for i, llen := 0, list.Len(); i < llen; i++ {
2103 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002104 b = protowire.AppendVarint(b, wiretag)
2105 b = protowire.AppendVarint(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002106 }
2107 return b, nil
2108}
2109
Damien Neil68b81c32019-08-22 11:41:32 -07002110// consumeInt64SliceValue wire decodes a []int64 value as a repeated Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07002111func consumeInt64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07002112 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08002113 if wtyp == protowire.BytesType {
2114 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07002115 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002116 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002117 }
2118 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -08002119 var v uint64
2120 var n int
2121 if len(b) >= 1 && b[0] < 0x80 {
2122 v = uint64(b[0])
2123 n = 1
2124 } else if len(b) >= 2 && b[1] < 128 {
2125 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2126 n = 2
2127 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002128 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002129 }
Damien Neile91877d2019-06-27 10:54:42 -07002130 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002131 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002132 }
Damien Neil68b81c32019-08-22 11:41:32 -07002133 list.Append(protoreflect.ValueOfInt64(int64(v)))
Damien Neile91877d2019-06-27 10:54:42 -07002134 b = b[n:]
2135 }
Damien Neilf0831e82020-01-21 14:25:12 -08002136 out.n = n
2137 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002138 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002139 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002140 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002141 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002142 var v uint64
2143 var n int
2144 if len(b) >= 1 && b[0] < 0x80 {
2145 v = uint64(b[0])
2146 n = 1
2147 } else if len(b) >= 2 && b[1] < 128 {
2148 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2149 n = 2
2150 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002151 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002152 }
Damien Neile91877d2019-06-27 10:54:42 -07002153 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002154 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002155 }
Damien Neil68b81c32019-08-22 11:41:32 -07002156 list.Append(protoreflect.ValueOfInt64(int64(v)))
Damien Neilf0831e82020-01-21 14:25:12 -08002157 out.n = n
2158 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002159}
2160
Damien Neil68b81c32019-08-22 11:41:32 -07002161var coderInt64SliceValue = valueCoderFuncs{
2162 size: sizeInt64SliceValue,
2163 marshal: appendInt64SliceValue,
2164 unmarshal: consumeInt64SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08002165 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002166}
2167
Damien Neil68b81c32019-08-22 11:41:32 -07002168// sizeInt64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07002169func sizeInt64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07002170 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08002171 llen := list.Len()
2172 if llen == 0 {
2173 return 0
2174 }
Damien Neil7492a092019-07-10 15:23:29 -07002175 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -08002176 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -07002177 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002178 n += protowire.SizeVarint(uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002179 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002180 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -07002181}
2182
Damien Neil68b81c32019-08-22 11:41:32 -07002183// appendInt64PackedSliceValue encodes a []int64 value as a packed repeated Int64.
Joe Tsai41134b72020-10-19 20:51:03 -07002184func appendInt64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07002185 list := listv.List()
2186 llen := list.Len()
2187 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07002188 return b, nil
2189 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002190 b = protowire.AppendVarint(b, wiretag)
Damien Neil7492a092019-07-10 15:23:29 -07002191 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07002192 for i := 0; i < llen; i++ {
2193 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002194 n += protowire.SizeVarint(uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002195 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002196 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07002197 for i := 0; i < llen; i++ {
2198 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002199 b = protowire.AppendVarint(b, uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002200 }
2201 return b, nil
2202}
2203
Damien Neil68b81c32019-08-22 11:41:32 -07002204var coderInt64PackedSliceValue = valueCoderFuncs{
2205 size: sizeInt64PackedSliceValue,
2206 marshal: appendInt64PackedSliceValue,
2207 unmarshal: consumeInt64SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08002208 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -07002209}
2210
Damien Neilc37adef2019-04-01 13:49:56 -07002211// sizeSint64 returns the size of wire encoding a int64 pointer as a Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002212func sizeSint64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07002213 v := *p.Int64()
Joe Tsaicd108d02020-02-14 18:08:02 -08002214 return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002215}
2216
2217// appendSint64 wire encodes a int64 pointer as a Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002218func appendSint64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002219 v := *p.Int64()
Joe Tsaicd108d02020-02-14 18:08:02 -08002220 b = protowire.AppendVarint(b, f.wiretag)
2221 b = protowire.AppendVarint(b, protowire.EncodeZigZag(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002222 return b, nil
2223}
2224
Damien Neile91877d2019-06-27 10:54:42 -07002225// consumeSint64 wire decodes a int64 pointer as a Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002226func consumeSint64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08002227 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002228 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002229 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002230 var v uint64
2231 var n int
2232 if len(b) >= 1 && b[0] < 0x80 {
2233 v = uint64(b[0])
2234 n = 1
2235 } else if len(b) >= 2 && b[1] < 128 {
2236 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2237 n = 2
2238 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002239 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002240 }
Damien Neile91877d2019-06-27 10:54:42 -07002241 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002242 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002243 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002244 *p.Int64() = protowire.DecodeZigZag(v)
Damien Neilf0831e82020-01-21 14:25:12 -08002245 out.n = n
2246 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002247}
2248
Damien Neilc37adef2019-04-01 13:49:56 -07002249var coderSint64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002250 size: sizeSint64,
2251 marshal: appendSint64,
2252 unmarshal: consumeSint64,
Damien Neile8e88752020-02-11 11:25:16 -08002253 merge: mergeInt64,
Damien Neilc37adef2019-04-01 13:49:56 -07002254}
2255
Joe Tsaic51e2e02019-07-13 00:44:41 -07002256// sizeSint64NoZero returns the size of wire encoding a int64 pointer as a Sint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002257// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07002258func sizeSint64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07002259 v := *p.Int64()
2260 if v == 0 {
2261 return 0
2262 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002263 return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002264}
2265
Joe Tsaic51e2e02019-07-13 00:44:41 -07002266// appendSint64NoZero wire encodes a int64 pointer as a Sint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002267// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07002268func appendSint64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002269 v := *p.Int64()
2270 if v == 0 {
2271 return b, nil
2272 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002273 b = protowire.AppendVarint(b, f.wiretag)
2274 b = protowire.AppendVarint(b, protowire.EncodeZigZag(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002275 return b, nil
2276}
2277
2278var coderSint64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002279 size: sizeSint64NoZero,
2280 marshal: appendSint64NoZero,
2281 unmarshal: consumeSint64,
Damien Neile8e88752020-02-11 11:25:16 -08002282 merge: mergeInt64NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07002283}
2284
2285// sizeSint64Ptr returns the size of wire encoding a *int64 pointer as a Sint64.
2286// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07002287func sizeSint64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07002288 v := **p.Int64Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08002289 return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002290}
2291
Damien Neile91877d2019-06-27 10:54:42 -07002292// appendSint64Ptr wire encodes a *int64 pointer as a Sint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002293// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07002294func appendSint64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002295 v := **p.Int64Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08002296 b = protowire.AppendVarint(b, f.wiretag)
2297 b = protowire.AppendVarint(b, protowire.EncodeZigZag(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002298 return b, nil
2299}
2300
Damien Neile91877d2019-06-27 10:54:42 -07002301// consumeSint64Ptr wire decodes a *int64 pointer as a Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002302func consumeSint64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08002303 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002304 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002305 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002306 var v uint64
2307 var n int
2308 if len(b) >= 1 && b[0] < 0x80 {
2309 v = uint64(b[0])
2310 n = 1
2311 } else if len(b) >= 2 && b[1] < 128 {
2312 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2313 n = 2
2314 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002315 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002316 }
Damien Neile91877d2019-06-27 10:54:42 -07002317 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002318 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002319 }
2320 vp := p.Int64Ptr()
2321 if *vp == nil {
2322 *vp = new(int64)
2323 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002324 **vp = protowire.DecodeZigZag(v)
Damien Neilf0831e82020-01-21 14:25:12 -08002325 out.n = n
2326 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002327}
2328
Damien Neilc37adef2019-04-01 13:49:56 -07002329var coderSint64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002330 size: sizeSint64Ptr,
2331 marshal: appendSint64Ptr,
2332 unmarshal: consumeSint64Ptr,
Damien Neile8e88752020-02-11 11:25:16 -08002333 merge: mergeInt64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07002334}
2335
2336// sizeSint64Slice returns the size of wire encoding a []int64 pointer as a repeated Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002337func sizeSint64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07002338 s := *p.Int64Slice()
2339 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002340 size += f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002341 }
2342 return size
2343}
2344
2345// appendSint64Slice encodes a []int64 pointer as a repeated Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002346func appendSint64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002347 s := *p.Int64Slice()
2348 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002349 b = protowire.AppendVarint(b, f.wiretag)
2350 b = protowire.AppendVarint(b, protowire.EncodeZigZag(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002351 }
2352 return b, nil
2353}
2354
Damien Neile91877d2019-06-27 10:54:42 -07002355// consumeSint64Slice wire decodes a []int64 pointer as a repeated Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002356func consumeSint64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07002357 sp := p.Int64Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08002358 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07002359 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -08002360 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07002361 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002362 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002363 }
2364 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -08002365 var v uint64
2366 var n int
2367 if len(b) >= 1 && b[0] < 0x80 {
2368 v = uint64(b[0])
2369 n = 1
2370 } else if len(b) >= 2 && b[1] < 128 {
2371 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2372 n = 2
2373 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002374 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002375 }
Damien Neile91877d2019-06-27 10:54:42 -07002376 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002377 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002378 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002379 s = append(s, protowire.DecodeZigZag(v))
Damien Neile91877d2019-06-27 10:54:42 -07002380 b = b[n:]
2381 }
2382 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -08002383 out.n = n
2384 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002385 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002386 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002387 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002388 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002389 var v uint64
2390 var n int
2391 if len(b) >= 1 && b[0] < 0x80 {
2392 v = uint64(b[0])
2393 n = 1
2394 } else if len(b) >= 2 && b[1] < 128 {
2395 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2396 n = 2
2397 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002398 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002399 }
Damien Neile91877d2019-06-27 10:54:42 -07002400 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002401 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002402 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002403 *sp = append(*sp, protowire.DecodeZigZag(v))
Damien Neilf0831e82020-01-21 14:25:12 -08002404 out.n = n
2405 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002406}
2407
Damien Neilc37adef2019-04-01 13:49:56 -07002408var coderSint64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002409 size: sizeSint64Slice,
2410 marshal: appendSint64Slice,
2411 unmarshal: consumeSint64Slice,
Damien Neile8e88752020-02-11 11:25:16 -08002412 merge: mergeInt64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002413}
2414
2415// sizeSint64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002416func sizeSint64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07002417 s := *p.Int64Slice()
2418 if len(s) == 0 {
2419 return 0
2420 }
2421 n := 0
2422 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002423 n += protowire.SizeVarint(protowire.EncodeZigZag(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002424 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002425 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -07002426}
2427
2428// appendSint64PackedSlice encodes a []int64 pointer as a packed repeated Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002429func appendSint64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002430 s := *p.Int64Slice()
2431 if len(s) == 0 {
2432 return b, nil
2433 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002434 b = protowire.AppendVarint(b, f.wiretag)
Damien Neilc37adef2019-04-01 13:49:56 -07002435 n := 0
2436 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002437 n += protowire.SizeVarint(protowire.EncodeZigZag(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002438 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002439 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -07002440 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002441 b = protowire.AppendVarint(b, protowire.EncodeZigZag(v))
Damien Neilc37adef2019-04-01 13:49:56 -07002442 }
2443 return b, nil
2444}
2445
2446var coderSint64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002447 size: sizeSint64PackedSlice,
2448 marshal: appendSint64PackedSlice,
2449 unmarshal: consumeSint64Slice,
Damien Neile8e88752020-02-11 11:25:16 -08002450 merge: mergeInt64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002451}
2452
Damien Neil68b81c32019-08-22 11:41:32 -07002453// sizeSint64Value returns the size of wire encoding a int64 value as a Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002454func sizeSint64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08002455 return tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002456}
2457
Damien Neil68b81c32019-08-22 11:41:32 -07002458// appendSint64Value encodes a int64 value as a Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002459func appendSint64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08002460 b = protowire.AppendVarint(b, wiretag)
2461 b = protowire.AppendVarint(b, protowire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002462 return b, nil
2463}
2464
Damien Neil68b81c32019-08-22 11:41:32 -07002465// consumeSint64Value decodes a int64 value as a Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002466func consumeSint64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08002467 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002468 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002469 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002470 var v uint64
2471 var n int
2472 if len(b) >= 1 && b[0] < 0x80 {
2473 v = uint64(b[0])
2474 n = 1
2475 } else if len(b) >= 2 && b[1] < 128 {
2476 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2477 n = 2
2478 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002479 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002480 }
Damien Neile91877d2019-06-27 10:54:42 -07002481 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002482 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002483 }
Damien Neilf0831e82020-01-21 14:25:12 -08002484 out.n = n
Joe Tsaicd108d02020-02-14 18:08:02 -08002485 return protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002486}
2487
Damien Neil68b81c32019-08-22 11:41:32 -07002488var coderSint64Value = valueCoderFuncs{
2489 size: sizeSint64Value,
2490 marshal: appendSint64Value,
2491 unmarshal: consumeSint64Value,
Damien Neile8e88752020-02-11 11:25:16 -08002492 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002493}
2494
Damien Neil68b81c32019-08-22 11:41:32 -07002495// sizeSint64SliceValue returns the size of wire encoding a []int64 value as a repeated Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002496func sizeSint64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07002497 list := listv.List()
2498 for i, llen := 0, list.Len(); i < llen; i++ {
2499 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002500 size += tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002501 }
2502 return size
2503}
2504
Damien Neil68b81c32019-08-22 11:41:32 -07002505// appendSint64SliceValue encodes a []int64 value as a repeated Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002506func appendSint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07002507 list := listv.List()
2508 for i, llen := 0, list.Len(); i < llen; i++ {
2509 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002510 b = protowire.AppendVarint(b, wiretag)
2511 b = protowire.AppendVarint(b, protowire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002512 }
2513 return b, nil
2514}
2515
Damien Neil68b81c32019-08-22 11:41:32 -07002516// consumeSint64SliceValue wire decodes a []int64 value as a repeated Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002517func consumeSint64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07002518 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08002519 if wtyp == protowire.BytesType {
2520 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07002521 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002522 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002523 }
2524 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -08002525 var v uint64
2526 var n int
2527 if len(b) >= 1 && b[0] < 0x80 {
2528 v = uint64(b[0])
2529 n = 1
2530 } else if len(b) >= 2 && b[1] < 128 {
2531 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2532 n = 2
2533 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002534 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002535 }
Damien Neile91877d2019-06-27 10:54:42 -07002536 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002537 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002538 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002539 list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)))
Damien Neile91877d2019-06-27 10:54:42 -07002540 b = b[n:]
2541 }
Damien Neilf0831e82020-01-21 14:25:12 -08002542 out.n = n
2543 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002544 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002545 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002546 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002547 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002548 var v uint64
2549 var n int
2550 if len(b) >= 1 && b[0] < 0x80 {
2551 v = uint64(b[0])
2552 n = 1
2553 } else if len(b) >= 2 && b[1] < 128 {
2554 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2555 n = 2
2556 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002557 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002558 }
Damien Neile91877d2019-06-27 10:54:42 -07002559 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002560 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002561 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002562 list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)))
Damien Neilf0831e82020-01-21 14:25:12 -08002563 out.n = n
2564 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002565}
2566
Damien Neil68b81c32019-08-22 11:41:32 -07002567var coderSint64SliceValue = valueCoderFuncs{
2568 size: sizeSint64SliceValue,
2569 marshal: appendSint64SliceValue,
2570 unmarshal: consumeSint64SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08002571 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002572}
2573
Damien Neil68b81c32019-08-22 11:41:32 -07002574// sizeSint64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002575func sizeSint64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07002576 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08002577 llen := list.Len()
2578 if llen == 0 {
2579 return 0
2580 }
Damien Neil7492a092019-07-10 15:23:29 -07002581 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -08002582 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -07002583 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002584 n += protowire.SizeVarint(protowire.EncodeZigZag(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002585 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002586 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -07002587}
2588
Damien Neil68b81c32019-08-22 11:41:32 -07002589// appendSint64PackedSliceValue encodes a []int64 value as a packed repeated Sint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002590func appendSint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07002591 list := listv.List()
2592 llen := list.Len()
2593 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07002594 return b, nil
2595 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002596 b = protowire.AppendVarint(b, wiretag)
Damien Neil7492a092019-07-10 15:23:29 -07002597 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07002598 for i := 0; i < llen; i++ {
2599 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002600 n += protowire.SizeVarint(protowire.EncodeZigZag(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002601 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002602 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07002603 for i := 0; i < llen; i++ {
2604 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002605 b = protowire.AppendVarint(b, protowire.EncodeZigZag(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002606 }
2607 return b, nil
2608}
2609
Damien Neil68b81c32019-08-22 11:41:32 -07002610var coderSint64PackedSliceValue = valueCoderFuncs{
2611 size: sizeSint64PackedSliceValue,
2612 marshal: appendSint64PackedSliceValue,
2613 unmarshal: consumeSint64SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08002614 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -07002615}
2616
Damien Neilc37adef2019-04-01 13:49:56 -07002617// sizeUint64 returns the size of wire encoding a uint64 pointer as a Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002618func sizeUint64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07002619 v := *p.Uint64()
Joe Tsaicd108d02020-02-14 18:08:02 -08002620 return f.tagsize + protowire.SizeVarint(v)
Damien Neilc37adef2019-04-01 13:49:56 -07002621}
2622
2623// appendUint64 wire encodes a uint64 pointer as a Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002624func appendUint64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002625 v := *p.Uint64()
Joe Tsaicd108d02020-02-14 18:08:02 -08002626 b = protowire.AppendVarint(b, f.wiretag)
2627 b = protowire.AppendVarint(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07002628 return b, nil
2629}
2630
Damien Neile91877d2019-06-27 10:54:42 -07002631// consumeUint64 wire decodes a uint64 pointer as a Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002632func consumeUint64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08002633 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002634 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002635 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002636 var v uint64
2637 var n int
2638 if len(b) >= 1 && b[0] < 0x80 {
2639 v = uint64(b[0])
2640 n = 1
2641 } else if len(b) >= 2 && b[1] < 128 {
2642 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2643 n = 2
2644 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002645 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002646 }
Damien Neile91877d2019-06-27 10:54:42 -07002647 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002648 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002649 }
2650 *p.Uint64() = v
Damien Neilf0831e82020-01-21 14:25:12 -08002651 out.n = n
2652 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002653}
2654
Damien Neilc37adef2019-04-01 13:49:56 -07002655var coderUint64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002656 size: sizeUint64,
2657 marshal: appendUint64,
2658 unmarshal: consumeUint64,
Damien Neile8e88752020-02-11 11:25:16 -08002659 merge: mergeUint64,
Damien Neilc37adef2019-04-01 13:49:56 -07002660}
2661
Joe Tsaic51e2e02019-07-13 00:44:41 -07002662// sizeUint64NoZero returns the size of wire encoding a uint64 pointer as a Uint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002663// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07002664func sizeUint64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07002665 v := *p.Uint64()
2666 if v == 0 {
2667 return 0
2668 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002669 return f.tagsize + protowire.SizeVarint(v)
Damien Neilc37adef2019-04-01 13:49:56 -07002670}
2671
Joe Tsaic51e2e02019-07-13 00:44:41 -07002672// appendUint64NoZero wire encodes a uint64 pointer as a Uint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002673// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07002674func appendUint64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002675 v := *p.Uint64()
2676 if v == 0 {
2677 return b, nil
2678 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002679 b = protowire.AppendVarint(b, f.wiretag)
2680 b = protowire.AppendVarint(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07002681 return b, nil
2682}
2683
2684var coderUint64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002685 size: sizeUint64NoZero,
2686 marshal: appendUint64NoZero,
2687 unmarshal: consumeUint64,
Damien Neile8e88752020-02-11 11:25:16 -08002688 merge: mergeUint64NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07002689}
2690
2691// sizeUint64Ptr returns the size of wire encoding a *uint64 pointer as a Uint64.
2692// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07002693func sizeUint64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07002694 v := **p.Uint64Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08002695 return f.tagsize + protowire.SizeVarint(v)
Damien Neilc37adef2019-04-01 13:49:56 -07002696}
2697
Damien Neile91877d2019-06-27 10:54:42 -07002698// appendUint64Ptr wire encodes a *uint64 pointer as a Uint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002699// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07002700func appendUint64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002701 v := **p.Uint64Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08002702 b = protowire.AppendVarint(b, f.wiretag)
2703 b = protowire.AppendVarint(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07002704 return b, nil
2705}
2706
Damien Neile91877d2019-06-27 10:54:42 -07002707// consumeUint64Ptr wire decodes a *uint64 pointer as a Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002708func consumeUint64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08002709 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002710 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002711 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002712 var v uint64
2713 var n int
2714 if len(b) >= 1 && b[0] < 0x80 {
2715 v = uint64(b[0])
2716 n = 1
2717 } else if len(b) >= 2 && b[1] < 128 {
2718 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2719 n = 2
2720 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002721 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002722 }
Damien Neile91877d2019-06-27 10:54:42 -07002723 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002724 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002725 }
2726 vp := p.Uint64Ptr()
2727 if *vp == nil {
2728 *vp = new(uint64)
2729 }
2730 **vp = v
Damien Neilf0831e82020-01-21 14:25:12 -08002731 out.n = n
2732 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002733}
2734
Damien Neilc37adef2019-04-01 13:49:56 -07002735var coderUint64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002736 size: sizeUint64Ptr,
2737 marshal: appendUint64Ptr,
2738 unmarshal: consumeUint64Ptr,
Damien Neile8e88752020-02-11 11:25:16 -08002739 merge: mergeUint64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07002740}
2741
2742// sizeUint64Slice returns the size of wire encoding a []uint64 pointer as a repeated Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002743func sizeUint64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07002744 s := *p.Uint64Slice()
2745 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002746 size += f.tagsize + protowire.SizeVarint(v)
Damien Neilc37adef2019-04-01 13:49:56 -07002747 }
2748 return size
2749}
2750
2751// appendUint64Slice encodes a []uint64 pointer as a repeated Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002752func appendUint64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002753 s := *p.Uint64Slice()
2754 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002755 b = protowire.AppendVarint(b, f.wiretag)
2756 b = protowire.AppendVarint(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07002757 }
2758 return b, nil
2759}
2760
Damien Neile91877d2019-06-27 10:54:42 -07002761// consumeUint64Slice wire decodes a []uint64 pointer as a repeated Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002762func consumeUint64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07002763 sp := p.Uint64Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08002764 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07002765 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -08002766 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07002767 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002768 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002769 }
2770 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -08002771 var v uint64
2772 var n int
2773 if len(b) >= 1 && b[0] < 0x80 {
2774 v = uint64(b[0])
2775 n = 1
2776 } else if len(b) >= 2 && b[1] < 128 {
2777 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2778 n = 2
2779 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002780 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002781 }
Damien Neile91877d2019-06-27 10:54:42 -07002782 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002783 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002784 }
2785 s = append(s, v)
2786 b = b[n:]
2787 }
2788 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -08002789 out.n = n
2790 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002791 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002792 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002793 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002794 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002795 var v uint64
2796 var n int
2797 if len(b) >= 1 && b[0] < 0x80 {
2798 v = uint64(b[0])
2799 n = 1
2800 } else if len(b) >= 2 && b[1] < 128 {
2801 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2802 n = 2
2803 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002804 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002805 }
Damien Neile91877d2019-06-27 10:54:42 -07002806 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002807 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002808 }
2809 *sp = append(*sp, v)
Damien Neilf0831e82020-01-21 14:25:12 -08002810 out.n = n
2811 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002812}
2813
Damien Neilc37adef2019-04-01 13:49:56 -07002814var coderUint64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002815 size: sizeUint64Slice,
2816 marshal: appendUint64Slice,
2817 unmarshal: consumeUint64Slice,
Damien Neile8e88752020-02-11 11:25:16 -08002818 merge: mergeUint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002819}
2820
2821// sizeUint64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002822func sizeUint64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07002823 s := *p.Uint64Slice()
2824 if len(s) == 0 {
2825 return 0
2826 }
2827 n := 0
2828 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002829 n += protowire.SizeVarint(v)
Damien Neilc37adef2019-04-01 13:49:56 -07002830 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002831 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -07002832}
2833
2834// appendUint64PackedSlice encodes a []uint64 pointer as a packed repeated Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002835func appendUint64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002836 s := *p.Uint64Slice()
2837 if len(s) == 0 {
2838 return b, nil
2839 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002840 b = protowire.AppendVarint(b, f.wiretag)
Damien Neilc37adef2019-04-01 13:49:56 -07002841 n := 0
2842 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002843 n += protowire.SizeVarint(v)
Damien Neilc37adef2019-04-01 13:49:56 -07002844 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002845 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -07002846 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08002847 b = protowire.AppendVarint(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07002848 }
2849 return b, nil
2850}
2851
2852var coderUint64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002853 size: sizeUint64PackedSlice,
2854 marshal: appendUint64PackedSlice,
2855 unmarshal: consumeUint64Slice,
Damien Neile8e88752020-02-11 11:25:16 -08002856 merge: mergeUint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002857}
2858
Damien Neil68b81c32019-08-22 11:41:32 -07002859// sizeUint64Value returns the size of wire encoding a uint64 value as a Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002860func sizeUint64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08002861 return tagsize + protowire.SizeVarint(v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002862}
2863
Damien Neil68b81c32019-08-22 11:41:32 -07002864// appendUint64Value encodes a uint64 value as a Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002865func appendUint64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08002866 b = protowire.AppendVarint(b, wiretag)
2867 b = protowire.AppendVarint(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002868 return b, nil
2869}
2870
Damien Neil68b81c32019-08-22 11:41:32 -07002871// consumeUint64Value decodes a uint64 value as a Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002872func consumeUint64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08002873 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002874 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002875 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002876 var v uint64
2877 var n int
2878 if len(b) >= 1 && b[0] < 0x80 {
2879 v = uint64(b[0])
2880 n = 1
2881 } else if len(b) >= 2 && b[1] < 128 {
2882 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2883 n = 2
2884 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002885 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002886 }
Damien Neile91877d2019-06-27 10:54:42 -07002887 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002888 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002889 }
Damien Neilf0831e82020-01-21 14:25:12 -08002890 out.n = n
2891 return protoreflect.ValueOfUint64(v), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002892}
2893
Damien Neil68b81c32019-08-22 11:41:32 -07002894var coderUint64Value = valueCoderFuncs{
2895 size: sizeUint64Value,
2896 marshal: appendUint64Value,
2897 unmarshal: consumeUint64Value,
Damien Neile8e88752020-02-11 11:25:16 -08002898 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002899}
2900
Damien Neil68b81c32019-08-22 11:41:32 -07002901// sizeUint64SliceValue returns the size of wire encoding a []uint64 value as a repeated Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002902func sizeUint64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07002903 list := listv.List()
2904 for i, llen := 0, list.Len(); i < llen; i++ {
2905 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002906 size += tagsize + protowire.SizeVarint(v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002907 }
2908 return size
2909}
2910
Damien Neil68b81c32019-08-22 11:41:32 -07002911// appendUint64SliceValue encodes a []uint64 value as a repeated Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002912func appendUint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07002913 list := listv.List()
2914 for i, llen := 0, list.Len(); i < llen; i++ {
2915 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002916 b = protowire.AppendVarint(b, wiretag)
2917 b = protowire.AppendVarint(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002918 }
2919 return b, nil
2920}
2921
Damien Neil68b81c32019-08-22 11:41:32 -07002922// consumeUint64SliceValue wire decodes a []uint64 value as a repeated Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002923func consumeUint64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07002924 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08002925 if wtyp == protowire.BytesType {
2926 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07002927 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002928 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002929 }
2930 for len(b) > 0 {
Damien Neiladbbc8e2020-01-24 17:01:14 -08002931 var v uint64
2932 var n int
2933 if len(b) >= 1 && b[0] < 0x80 {
2934 v = uint64(b[0])
2935 n = 1
2936 } else if len(b) >= 2 && b[1] < 128 {
2937 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2938 n = 2
2939 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002940 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002941 }
Damien Neile91877d2019-06-27 10:54:42 -07002942 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002943 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002944 }
Damien Neil68b81c32019-08-22 11:41:32 -07002945 list.Append(protoreflect.ValueOfUint64(v))
Damien Neile91877d2019-06-27 10:54:42 -07002946 b = b[n:]
2947 }
Damien Neilf0831e82020-01-21 14:25:12 -08002948 out.n = n
2949 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002950 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002951 if wtyp != protowire.VarintType {
Damien Neilf0831e82020-01-21 14:25:12 -08002952 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002953 }
Damien Neiladbbc8e2020-01-24 17:01:14 -08002954 var v uint64
2955 var n int
2956 if len(b) >= 1 && b[0] < 0x80 {
2957 v = uint64(b[0])
2958 n = 1
2959 } else if len(b) >= 2 && b[1] < 128 {
2960 v = uint64(b[0]&0x7f) + uint64(b[1])<<7
2961 n = 2
2962 } else {
Joe Tsaicd108d02020-02-14 18:08:02 -08002963 v, n = protowire.ConsumeVarint(b)
Damien Neiladbbc8e2020-01-24 17:01:14 -08002964 }
Damien Neile91877d2019-06-27 10:54:42 -07002965 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07002966 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07002967 }
Damien Neil68b81c32019-08-22 11:41:32 -07002968 list.Append(protoreflect.ValueOfUint64(v))
Damien Neilf0831e82020-01-21 14:25:12 -08002969 out.n = n
2970 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07002971}
2972
Damien Neil68b81c32019-08-22 11:41:32 -07002973var coderUint64SliceValue = valueCoderFuncs{
2974 size: sizeUint64SliceValue,
2975 marshal: appendUint64SliceValue,
2976 unmarshal: consumeUint64SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08002977 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002978}
2979
Damien Neil68b81c32019-08-22 11:41:32 -07002980// sizeUint64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002981func sizeUint64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07002982 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08002983 llen := list.Len()
2984 if llen == 0 {
2985 return 0
2986 }
Damien Neil7492a092019-07-10 15:23:29 -07002987 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -08002988 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -07002989 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08002990 n += protowire.SizeVarint(v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07002991 }
Joe Tsaicd108d02020-02-14 18:08:02 -08002992 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -07002993}
2994
Damien Neil68b81c32019-08-22 11:41:32 -07002995// appendUint64PackedSliceValue encodes a []uint64 value as a packed repeated Uint64.
Joe Tsai41134b72020-10-19 20:51:03 -07002996func appendUint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07002997 list := listv.List()
2998 llen := list.Len()
2999 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07003000 return b, nil
3001 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003002 b = protowire.AppendVarint(b, wiretag)
Damien Neil7492a092019-07-10 15:23:29 -07003003 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07003004 for i := 0; i < llen; i++ {
3005 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08003006 n += protowire.SizeVarint(v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07003007 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003008 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07003009 for i := 0; i < llen; i++ {
3010 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08003011 b = protowire.AppendVarint(b, v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07003012 }
3013 return b, nil
3014}
3015
Damien Neil68b81c32019-08-22 11:41:32 -07003016var coderUint64PackedSliceValue = valueCoderFuncs{
3017 size: sizeUint64PackedSliceValue,
3018 marshal: appendUint64PackedSliceValue,
3019 unmarshal: consumeUint64SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08003020 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -07003021}
3022
Damien Neilc37adef2019-04-01 13:49:56 -07003023// sizeSfixed32 returns the size of wire encoding a int32 pointer as a Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003024func sizeSfixed32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003025
Joe Tsaicd108d02020-02-14 18:08:02 -08003026 return f.tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003027}
3028
3029// appendSfixed32 wire encodes a int32 pointer as a Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003030func appendSfixed32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003031 v := *p.Int32()
Joe Tsaicd108d02020-02-14 18:08:02 -08003032 b = protowire.AppendVarint(b, f.wiretag)
3033 b = protowire.AppendFixed32(b, uint32(v))
Damien Neilc37adef2019-04-01 13:49:56 -07003034 return b, nil
3035}
3036
Damien Neile91877d2019-06-27 10:54:42 -07003037// consumeSfixed32 wire decodes a int32 pointer as a Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003038func consumeSfixed32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003039 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003040 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003041 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003042 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003043 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003044 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003045 }
3046 *p.Int32() = int32(v)
Damien Neilf0831e82020-01-21 14:25:12 -08003047 out.n = n
3048 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003049}
3050
Damien Neilc37adef2019-04-01 13:49:56 -07003051var coderSfixed32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003052 size: sizeSfixed32,
3053 marshal: appendSfixed32,
3054 unmarshal: consumeSfixed32,
Damien Neile8e88752020-02-11 11:25:16 -08003055 merge: mergeInt32,
Damien Neilc37adef2019-04-01 13:49:56 -07003056}
3057
Joe Tsaic51e2e02019-07-13 00:44:41 -07003058// sizeSfixed32NoZero returns the size of wire encoding a int32 pointer as a Sfixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07003059// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07003060func sizeSfixed32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003061 v := *p.Int32()
3062 if v == 0 {
3063 return 0
3064 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003065 return f.tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003066}
3067
Joe Tsaic51e2e02019-07-13 00:44:41 -07003068// appendSfixed32NoZero wire encodes a int32 pointer as a Sfixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07003069// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07003070func appendSfixed32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003071 v := *p.Int32()
3072 if v == 0 {
3073 return b, nil
3074 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003075 b = protowire.AppendVarint(b, f.wiretag)
3076 b = protowire.AppendFixed32(b, uint32(v))
Damien Neilc37adef2019-04-01 13:49:56 -07003077 return b, nil
3078}
3079
3080var coderSfixed32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003081 size: sizeSfixed32NoZero,
3082 marshal: appendSfixed32NoZero,
3083 unmarshal: consumeSfixed32,
Damien Neile8e88752020-02-11 11:25:16 -08003084 merge: mergeInt32NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07003085}
3086
3087// sizeSfixed32Ptr returns the size of wire encoding a *int32 pointer as a Sfixed32.
3088// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07003089func sizeSfixed32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003090 return f.tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003091}
3092
Damien Neile91877d2019-06-27 10:54:42 -07003093// appendSfixed32Ptr wire encodes a *int32 pointer as a Sfixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07003094// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07003095func appendSfixed32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003096 v := **p.Int32Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08003097 b = protowire.AppendVarint(b, f.wiretag)
3098 b = protowire.AppendFixed32(b, uint32(v))
Damien Neilc37adef2019-04-01 13:49:56 -07003099 return b, nil
3100}
3101
Damien Neile91877d2019-06-27 10:54:42 -07003102// consumeSfixed32Ptr wire decodes a *int32 pointer as a Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003103func consumeSfixed32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003104 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003105 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003106 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003107 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003108 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003109 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003110 }
3111 vp := p.Int32Ptr()
3112 if *vp == nil {
3113 *vp = new(int32)
3114 }
3115 **vp = int32(v)
Damien Neilf0831e82020-01-21 14:25:12 -08003116 out.n = n
3117 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003118}
3119
Damien Neilc37adef2019-04-01 13:49:56 -07003120var coderSfixed32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003121 size: sizeSfixed32Ptr,
3122 marshal: appendSfixed32Ptr,
3123 unmarshal: consumeSfixed32Ptr,
Damien Neile8e88752020-02-11 11:25:16 -08003124 merge: mergeInt32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07003125}
3126
3127// sizeSfixed32Slice returns the size of wire encoding a []int32 pointer as a repeated Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003128func sizeSfixed32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003129 s := *p.Int32Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08003130 size = len(s) * (f.tagsize + protowire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07003131 return size
3132}
3133
3134// appendSfixed32Slice encodes a []int32 pointer as a repeated Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003135func appendSfixed32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003136 s := *p.Int32Slice()
3137 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08003138 b = protowire.AppendVarint(b, f.wiretag)
3139 b = protowire.AppendFixed32(b, uint32(v))
Damien Neilc37adef2019-04-01 13:49:56 -07003140 }
3141 return b, nil
3142}
3143
Damien Neile91877d2019-06-27 10:54:42 -07003144// consumeSfixed32Slice wire decodes a []int32 pointer as a repeated Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003145func consumeSfixed32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07003146 sp := p.Int32Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08003147 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07003148 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -08003149 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07003150 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003151 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003152 }
3153 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08003154 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003155 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003156 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003157 }
3158 s = append(s, int32(v))
3159 b = b[n:]
3160 }
3161 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -08003162 out.n = n
3163 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003164 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003165 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003166 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003167 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003168 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003169 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003170 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003171 }
3172 *sp = append(*sp, int32(v))
Damien Neilf0831e82020-01-21 14:25:12 -08003173 out.n = n
3174 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003175}
3176
Damien Neilc37adef2019-04-01 13:49:56 -07003177var coderSfixed32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003178 size: sizeSfixed32Slice,
3179 marshal: appendSfixed32Slice,
3180 unmarshal: consumeSfixed32Slice,
Damien Neile8e88752020-02-11 11:25:16 -08003181 merge: mergeInt32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003182}
3183
3184// sizeSfixed32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003185func sizeSfixed32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003186 s := *p.Int32Slice()
3187 if len(s) == 0 {
3188 return 0
3189 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003190 n := len(s) * protowire.SizeFixed32()
3191 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -07003192}
3193
3194// appendSfixed32PackedSlice encodes a []int32 pointer as a packed repeated Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003195func appendSfixed32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003196 s := *p.Int32Slice()
3197 if len(s) == 0 {
3198 return b, nil
3199 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003200 b = protowire.AppendVarint(b, f.wiretag)
3201 n := len(s) * protowire.SizeFixed32()
3202 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -07003203 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08003204 b = protowire.AppendFixed32(b, uint32(v))
Damien Neilc37adef2019-04-01 13:49:56 -07003205 }
3206 return b, nil
3207}
3208
3209var coderSfixed32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003210 size: sizeSfixed32PackedSlice,
3211 marshal: appendSfixed32PackedSlice,
3212 unmarshal: consumeSfixed32Slice,
Damien Neile8e88752020-02-11 11:25:16 -08003213 merge: mergeInt32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003214}
3215
Damien Neil68b81c32019-08-22 11:41:32 -07003216// sizeSfixed32Value returns the size of wire encoding a int32 value as a Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003217func sizeSfixed32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08003218 return tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003219}
3220
Damien Neil68b81c32019-08-22 11:41:32 -07003221// appendSfixed32Value encodes a int32 value as a Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003222func appendSfixed32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003223 b = protowire.AppendVarint(b, wiretag)
3224 b = protowire.AppendFixed32(b, uint32(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07003225 return b, nil
3226}
3227
Damien Neil68b81c32019-08-22 11:41:32 -07003228// consumeSfixed32Value decodes a int32 value as a Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003229func consumeSfixed32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003230 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003231 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003232 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003233 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003234 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003235 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003236 }
Damien Neilf0831e82020-01-21 14:25:12 -08003237 out.n = n
3238 return protoreflect.ValueOfInt32(int32(v)), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003239}
3240
Damien Neil68b81c32019-08-22 11:41:32 -07003241var coderSfixed32Value = valueCoderFuncs{
3242 size: sizeSfixed32Value,
3243 marshal: appendSfixed32Value,
3244 unmarshal: consumeSfixed32Value,
Damien Neile8e88752020-02-11 11:25:16 -08003245 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003246}
3247
Damien Neil68b81c32019-08-22 11:41:32 -07003248// sizeSfixed32SliceValue returns the size of wire encoding a []int32 value as a repeated Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003249func sizeSfixed32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07003250 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08003251 size = list.Len() * (tagsize + protowire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07003252 return size
3253}
3254
Damien Neil68b81c32019-08-22 11:41:32 -07003255// appendSfixed32SliceValue encodes a []int32 value as a repeated Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003256func appendSfixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07003257 list := listv.List()
3258 for i, llen := 0, list.Len(); i < llen; i++ {
3259 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08003260 b = protowire.AppendVarint(b, wiretag)
3261 b = protowire.AppendFixed32(b, uint32(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07003262 }
3263 return b, nil
3264}
3265
Damien Neil68b81c32019-08-22 11:41:32 -07003266// consumeSfixed32SliceValue wire decodes a []int32 value as a repeated Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003267func consumeSfixed32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07003268 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08003269 if wtyp == protowire.BytesType {
3270 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07003271 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003272 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003273 }
3274 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08003275 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003276 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003277 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003278 }
Damien Neil68b81c32019-08-22 11:41:32 -07003279 list.Append(protoreflect.ValueOfInt32(int32(v)))
Damien Neile91877d2019-06-27 10:54:42 -07003280 b = b[n:]
3281 }
Damien Neilf0831e82020-01-21 14:25:12 -08003282 out.n = n
3283 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003284 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003285 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003286 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003287 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003288 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003289 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003290 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003291 }
Damien Neil68b81c32019-08-22 11:41:32 -07003292 list.Append(protoreflect.ValueOfInt32(int32(v)))
Damien Neilf0831e82020-01-21 14:25:12 -08003293 out.n = n
3294 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003295}
3296
Damien Neil68b81c32019-08-22 11:41:32 -07003297var coderSfixed32SliceValue = valueCoderFuncs{
3298 size: sizeSfixed32SliceValue,
3299 marshal: appendSfixed32SliceValue,
3300 unmarshal: consumeSfixed32SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08003301 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003302}
3303
Damien Neil68b81c32019-08-22 11:41:32 -07003304// sizeSfixed32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003305func sizeSfixed32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07003306 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08003307 llen := list.Len()
3308 if llen == 0 {
3309 return 0
3310 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003311 n := llen * protowire.SizeFixed32()
3312 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -07003313}
3314
Damien Neil68b81c32019-08-22 11:41:32 -07003315// appendSfixed32PackedSliceValue encodes a []int32 value as a packed repeated Sfixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003316func appendSfixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07003317 list := listv.List()
3318 llen := list.Len()
3319 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07003320 return b, nil
3321 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003322 b = protowire.AppendVarint(b, wiretag)
3323 n := llen * protowire.SizeFixed32()
3324 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07003325 for i := 0; i < llen; i++ {
3326 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08003327 b = protowire.AppendFixed32(b, uint32(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07003328 }
3329 return b, nil
3330}
3331
Damien Neil68b81c32019-08-22 11:41:32 -07003332var coderSfixed32PackedSliceValue = valueCoderFuncs{
3333 size: sizeSfixed32PackedSliceValue,
3334 marshal: appendSfixed32PackedSliceValue,
3335 unmarshal: consumeSfixed32SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08003336 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -07003337}
3338
Damien Neilc37adef2019-04-01 13:49:56 -07003339// sizeFixed32 returns the size of wire encoding a uint32 pointer as a Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003340func sizeFixed32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003341
Joe Tsaicd108d02020-02-14 18:08:02 -08003342 return f.tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003343}
3344
3345// appendFixed32 wire encodes a uint32 pointer as a Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003346func appendFixed32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003347 v := *p.Uint32()
Joe Tsaicd108d02020-02-14 18:08:02 -08003348 b = protowire.AppendVarint(b, f.wiretag)
3349 b = protowire.AppendFixed32(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07003350 return b, nil
3351}
3352
Damien Neile91877d2019-06-27 10:54:42 -07003353// consumeFixed32 wire decodes a uint32 pointer as a Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003354func consumeFixed32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003355 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003356 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003357 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003358 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003359 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003360 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003361 }
3362 *p.Uint32() = v
Damien Neilf0831e82020-01-21 14:25:12 -08003363 out.n = n
3364 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003365}
3366
Damien Neilc37adef2019-04-01 13:49:56 -07003367var coderFixed32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003368 size: sizeFixed32,
3369 marshal: appendFixed32,
3370 unmarshal: consumeFixed32,
Damien Neile8e88752020-02-11 11:25:16 -08003371 merge: mergeUint32,
Damien Neilc37adef2019-04-01 13:49:56 -07003372}
3373
Joe Tsaic51e2e02019-07-13 00:44:41 -07003374// sizeFixed32NoZero returns the size of wire encoding a uint32 pointer as a Fixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07003375// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07003376func sizeFixed32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003377 v := *p.Uint32()
3378 if v == 0 {
3379 return 0
3380 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003381 return f.tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003382}
3383
Joe Tsaic51e2e02019-07-13 00:44:41 -07003384// appendFixed32NoZero wire encodes a uint32 pointer as a Fixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07003385// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07003386func appendFixed32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003387 v := *p.Uint32()
3388 if v == 0 {
3389 return b, nil
3390 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003391 b = protowire.AppendVarint(b, f.wiretag)
3392 b = protowire.AppendFixed32(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07003393 return b, nil
3394}
3395
3396var coderFixed32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003397 size: sizeFixed32NoZero,
3398 marshal: appendFixed32NoZero,
3399 unmarshal: consumeFixed32,
Damien Neile8e88752020-02-11 11:25:16 -08003400 merge: mergeUint32NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07003401}
3402
3403// sizeFixed32Ptr returns the size of wire encoding a *uint32 pointer as a Fixed32.
3404// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07003405func sizeFixed32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003406 return f.tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003407}
3408
Damien Neile91877d2019-06-27 10:54:42 -07003409// appendFixed32Ptr wire encodes a *uint32 pointer as a Fixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07003410// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07003411func appendFixed32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003412 v := **p.Uint32Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08003413 b = protowire.AppendVarint(b, f.wiretag)
3414 b = protowire.AppendFixed32(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07003415 return b, nil
3416}
3417
Damien Neile91877d2019-06-27 10:54:42 -07003418// consumeFixed32Ptr wire decodes a *uint32 pointer as a Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003419func consumeFixed32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003420 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003421 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003422 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003423 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003424 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003425 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003426 }
3427 vp := p.Uint32Ptr()
3428 if *vp == nil {
3429 *vp = new(uint32)
3430 }
3431 **vp = v
Damien Neilf0831e82020-01-21 14:25:12 -08003432 out.n = n
3433 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003434}
3435
Damien Neilc37adef2019-04-01 13:49:56 -07003436var coderFixed32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003437 size: sizeFixed32Ptr,
3438 marshal: appendFixed32Ptr,
3439 unmarshal: consumeFixed32Ptr,
Damien Neile8e88752020-02-11 11:25:16 -08003440 merge: mergeUint32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07003441}
3442
3443// sizeFixed32Slice returns the size of wire encoding a []uint32 pointer as a repeated Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003444func sizeFixed32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003445 s := *p.Uint32Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08003446 size = len(s) * (f.tagsize + protowire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07003447 return size
3448}
3449
3450// appendFixed32Slice encodes a []uint32 pointer as a repeated Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003451func appendFixed32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003452 s := *p.Uint32Slice()
3453 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08003454 b = protowire.AppendVarint(b, f.wiretag)
3455 b = protowire.AppendFixed32(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07003456 }
3457 return b, nil
3458}
3459
Damien Neile91877d2019-06-27 10:54:42 -07003460// consumeFixed32Slice wire decodes a []uint32 pointer as a repeated Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003461func consumeFixed32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07003462 sp := p.Uint32Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08003463 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07003464 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -08003465 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07003466 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003467 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003468 }
3469 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08003470 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003471 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003472 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003473 }
3474 s = append(s, v)
3475 b = b[n:]
3476 }
3477 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -08003478 out.n = n
3479 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003480 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003481 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003482 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003483 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003484 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003485 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003486 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003487 }
3488 *sp = append(*sp, v)
Damien Neilf0831e82020-01-21 14:25:12 -08003489 out.n = n
3490 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003491}
3492
Damien Neilc37adef2019-04-01 13:49:56 -07003493var coderFixed32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003494 size: sizeFixed32Slice,
3495 marshal: appendFixed32Slice,
3496 unmarshal: consumeFixed32Slice,
Damien Neile8e88752020-02-11 11:25:16 -08003497 merge: mergeUint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003498}
3499
3500// sizeFixed32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003501func sizeFixed32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003502 s := *p.Uint32Slice()
3503 if len(s) == 0 {
3504 return 0
3505 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003506 n := len(s) * protowire.SizeFixed32()
3507 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -07003508}
3509
3510// appendFixed32PackedSlice encodes a []uint32 pointer as a packed repeated Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003511func appendFixed32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003512 s := *p.Uint32Slice()
3513 if len(s) == 0 {
3514 return b, nil
3515 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003516 b = protowire.AppendVarint(b, f.wiretag)
3517 n := len(s) * protowire.SizeFixed32()
3518 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -07003519 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08003520 b = protowire.AppendFixed32(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07003521 }
3522 return b, nil
3523}
3524
3525var coderFixed32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003526 size: sizeFixed32PackedSlice,
3527 marshal: appendFixed32PackedSlice,
3528 unmarshal: consumeFixed32Slice,
Damien Neile8e88752020-02-11 11:25:16 -08003529 merge: mergeUint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003530}
3531
Damien Neil68b81c32019-08-22 11:41:32 -07003532// sizeFixed32Value returns the size of wire encoding a uint32 value as a Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003533func sizeFixed32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08003534 return tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003535}
3536
Damien Neil68b81c32019-08-22 11:41:32 -07003537// appendFixed32Value encodes a uint32 value as a Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003538func appendFixed32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003539 b = protowire.AppendVarint(b, wiretag)
3540 b = protowire.AppendFixed32(b, uint32(v.Uint()))
Damien Neilc37adef2019-04-01 13:49:56 -07003541 return b, nil
3542}
3543
Damien Neil68b81c32019-08-22 11:41:32 -07003544// consumeFixed32Value decodes a uint32 value as a Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003545func consumeFixed32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003546 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003547 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003548 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003549 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003550 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003551 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003552 }
Damien Neilf0831e82020-01-21 14:25:12 -08003553 out.n = n
3554 return protoreflect.ValueOfUint32(uint32(v)), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003555}
3556
Damien Neil68b81c32019-08-22 11:41:32 -07003557var coderFixed32Value = valueCoderFuncs{
3558 size: sizeFixed32Value,
3559 marshal: appendFixed32Value,
3560 unmarshal: consumeFixed32Value,
Damien Neile8e88752020-02-11 11:25:16 -08003561 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003562}
3563
Damien Neil68b81c32019-08-22 11:41:32 -07003564// sizeFixed32SliceValue returns the size of wire encoding a []uint32 value as a repeated Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003565func sizeFixed32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07003566 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08003567 size = list.Len() * (tagsize + protowire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07003568 return size
3569}
3570
Damien Neil68b81c32019-08-22 11:41:32 -07003571// appendFixed32SliceValue encodes a []uint32 value as a repeated Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003572func appendFixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07003573 list := listv.List()
3574 for i, llen := 0, list.Len(); i < llen; i++ {
3575 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08003576 b = protowire.AppendVarint(b, wiretag)
3577 b = protowire.AppendFixed32(b, uint32(v.Uint()))
Damien Neilc37adef2019-04-01 13:49:56 -07003578 }
3579 return b, nil
3580}
3581
Damien Neil68b81c32019-08-22 11:41:32 -07003582// consumeFixed32SliceValue wire decodes a []uint32 value as a repeated Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003583func consumeFixed32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07003584 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08003585 if wtyp == protowire.BytesType {
3586 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07003587 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003588 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003589 }
3590 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08003591 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003592 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003593 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003594 }
Damien Neil68b81c32019-08-22 11:41:32 -07003595 list.Append(protoreflect.ValueOfUint32(uint32(v)))
Damien Neile91877d2019-06-27 10:54:42 -07003596 b = b[n:]
3597 }
Damien Neilf0831e82020-01-21 14:25:12 -08003598 out.n = n
3599 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003600 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003601 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003602 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003603 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003604 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003605 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003606 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003607 }
Damien Neil68b81c32019-08-22 11:41:32 -07003608 list.Append(protoreflect.ValueOfUint32(uint32(v)))
Damien Neilf0831e82020-01-21 14:25:12 -08003609 out.n = n
3610 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003611}
3612
Damien Neil68b81c32019-08-22 11:41:32 -07003613var coderFixed32SliceValue = valueCoderFuncs{
3614 size: sizeFixed32SliceValue,
3615 marshal: appendFixed32SliceValue,
3616 unmarshal: consumeFixed32SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08003617 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003618}
3619
Damien Neil68b81c32019-08-22 11:41:32 -07003620// sizeFixed32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003621func sizeFixed32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07003622 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08003623 llen := list.Len()
3624 if llen == 0 {
3625 return 0
3626 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003627 n := llen * protowire.SizeFixed32()
3628 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -07003629}
3630
Damien Neil68b81c32019-08-22 11:41:32 -07003631// appendFixed32PackedSliceValue encodes a []uint32 value as a packed repeated Fixed32.
Joe Tsai41134b72020-10-19 20:51:03 -07003632func appendFixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07003633 list := listv.List()
3634 llen := list.Len()
3635 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07003636 return b, nil
3637 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003638 b = protowire.AppendVarint(b, wiretag)
3639 n := llen * protowire.SizeFixed32()
3640 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07003641 for i := 0; i < llen; i++ {
3642 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08003643 b = protowire.AppendFixed32(b, uint32(v.Uint()))
Damien Neil7492a092019-07-10 15:23:29 -07003644 }
3645 return b, nil
3646}
3647
Damien Neil68b81c32019-08-22 11:41:32 -07003648var coderFixed32PackedSliceValue = valueCoderFuncs{
3649 size: sizeFixed32PackedSliceValue,
3650 marshal: appendFixed32PackedSliceValue,
3651 unmarshal: consumeFixed32SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08003652 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -07003653}
3654
Damien Neilc37adef2019-04-01 13:49:56 -07003655// sizeFloat returns the size of wire encoding a float32 pointer as a Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003656func sizeFloat(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003657
Joe Tsaicd108d02020-02-14 18:08:02 -08003658 return f.tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003659}
3660
3661// appendFloat wire encodes a float32 pointer as a Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003662func appendFloat(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003663 v := *p.Float32()
Joe Tsaicd108d02020-02-14 18:08:02 -08003664 b = protowire.AppendVarint(b, f.wiretag)
3665 b = protowire.AppendFixed32(b, math.Float32bits(v))
Damien Neilc37adef2019-04-01 13:49:56 -07003666 return b, nil
3667}
3668
Damien Neile91877d2019-06-27 10:54:42 -07003669// consumeFloat wire decodes a float32 pointer as a Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003670func consumeFloat(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003671 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003672 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003673 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003674 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003675 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003676 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003677 }
3678 *p.Float32() = math.Float32frombits(v)
Damien Neilf0831e82020-01-21 14:25:12 -08003679 out.n = n
3680 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003681}
3682
Damien Neilc37adef2019-04-01 13:49:56 -07003683var coderFloat = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003684 size: sizeFloat,
3685 marshal: appendFloat,
3686 unmarshal: consumeFloat,
Damien Neile8e88752020-02-11 11:25:16 -08003687 merge: mergeFloat32,
Damien Neilc37adef2019-04-01 13:49:56 -07003688}
3689
Joe Tsaic51e2e02019-07-13 00:44:41 -07003690// sizeFloatNoZero returns the size of wire encoding a float32 pointer as a Float.
Damien Neilc37adef2019-04-01 13:49:56 -07003691// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07003692func sizeFloatNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003693 v := *p.Float32()
3694 if v == 0 && !math.Signbit(float64(v)) {
3695 return 0
3696 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003697 return f.tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003698}
3699
Joe Tsaic51e2e02019-07-13 00:44:41 -07003700// appendFloatNoZero wire encodes a float32 pointer as a Float.
Damien Neilc37adef2019-04-01 13:49:56 -07003701// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07003702func appendFloatNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003703 v := *p.Float32()
3704 if v == 0 && !math.Signbit(float64(v)) {
3705 return b, nil
3706 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003707 b = protowire.AppendVarint(b, f.wiretag)
3708 b = protowire.AppendFixed32(b, math.Float32bits(v))
Damien Neilc37adef2019-04-01 13:49:56 -07003709 return b, nil
3710}
3711
3712var coderFloatNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003713 size: sizeFloatNoZero,
3714 marshal: appendFloatNoZero,
3715 unmarshal: consumeFloat,
Damien Neile8e88752020-02-11 11:25:16 -08003716 merge: mergeFloat32NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07003717}
3718
3719// sizeFloatPtr returns the size of wire encoding a *float32 pointer as a Float.
3720// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07003721func sizeFloatPtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003722 return f.tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003723}
3724
Damien Neile91877d2019-06-27 10:54:42 -07003725// appendFloatPtr wire encodes a *float32 pointer as a Float.
Damien Neilc37adef2019-04-01 13:49:56 -07003726// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07003727func appendFloatPtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003728 v := **p.Float32Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08003729 b = protowire.AppendVarint(b, f.wiretag)
3730 b = protowire.AppendFixed32(b, math.Float32bits(v))
Damien Neilc37adef2019-04-01 13:49:56 -07003731 return b, nil
3732}
3733
Damien Neile91877d2019-06-27 10:54:42 -07003734// consumeFloatPtr wire decodes a *float32 pointer as a Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003735func consumeFloatPtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003736 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003737 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003738 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003739 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003740 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003741 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003742 }
3743 vp := p.Float32Ptr()
3744 if *vp == nil {
3745 *vp = new(float32)
3746 }
3747 **vp = math.Float32frombits(v)
Damien Neilf0831e82020-01-21 14:25:12 -08003748 out.n = n
3749 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003750}
3751
Damien Neilc37adef2019-04-01 13:49:56 -07003752var coderFloatPtr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003753 size: sizeFloatPtr,
3754 marshal: appendFloatPtr,
3755 unmarshal: consumeFloatPtr,
Damien Neile8e88752020-02-11 11:25:16 -08003756 merge: mergeFloat32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07003757}
3758
3759// sizeFloatSlice returns the size of wire encoding a []float32 pointer as a repeated Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003760func sizeFloatSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003761 s := *p.Float32Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08003762 size = len(s) * (f.tagsize + protowire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07003763 return size
3764}
3765
3766// appendFloatSlice encodes a []float32 pointer as a repeated Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003767func appendFloatSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003768 s := *p.Float32Slice()
3769 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08003770 b = protowire.AppendVarint(b, f.wiretag)
3771 b = protowire.AppendFixed32(b, math.Float32bits(v))
Damien Neilc37adef2019-04-01 13:49:56 -07003772 }
3773 return b, nil
3774}
3775
Damien Neile91877d2019-06-27 10:54:42 -07003776// consumeFloatSlice wire decodes a []float32 pointer as a repeated Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003777func consumeFloatSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07003778 sp := p.Float32Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08003779 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07003780 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -08003781 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07003782 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003783 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003784 }
3785 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08003786 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003787 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003788 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003789 }
3790 s = append(s, math.Float32frombits(v))
3791 b = b[n:]
3792 }
3793 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -08003794 out.n = n
3795 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003796 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003797 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003798 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003799 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003800 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003801 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003802 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003803 }
3804 *sp = append(*sp, math.Float32frombits(v))
Damien Neilf0831e82020-01-21 14:25:12 -08003805 out.n = n
3806 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003807}
3808
Damien Neilc37adef2019-04-01 13:49:56 -07003809var coderFloatSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003810 size: sizeFloatSlice,
3811 marshal: appendFloatSlice,
3812 unmarshal: consumeFloatSlice,
Damien Neile8e88752020-02-11 11:25:16 -08003813 merge: mergeFloat32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003814}
3815
3816// sizeFloatPackedSlice returns the size of wire encoding a []float32 pointer as a packed repeated Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003817func sizeFloatPackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003818 s := *p.Float32Slice()
3819 if len(s) == 0 {
3820 return 0
3821 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003822 n := len(s) * protowire.SizeFixed32()
3823 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -07003824}
3825
3826// appendFloatPackedSlice encodes a []float32 pointer as a packed repeated Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003827func appendFloatPackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003828 s := *p.Float32Slice()
3829 if len(s) == 0 {
3830 return b, nil
3831 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003832 b = protowire.AppendVarint(b, f.wiretag)
3833 n := len(s) * protowire.SizeFixed32()
3834 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -07003835 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08003836 b = protowire.AppendFixed32(b, math.Float32bits(v))
Damien Neilc37adef2019-04-01 13:49:56 -07003837 }
3838 return b, nil
3839}
3840
3841var coderFloatPackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003842 size: sizeFloatPackedSlice,
3843 marshal: appendFloatPackedSlice,
3844 unmarshal: consumeFloatSlice,
Damien Neile8e88752020-02-11 11:25:16 -08003845 merge: mergeFloat32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003846}
3847
Damien Neil68b81c32019-08-22 11:41:32 -07003848// sizeFloatValue returns the size of wire encoding a float32 value as a Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003849func sizeFloatValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08003850 return tagsize + protowire.SizeFixed32()
Damien Neilc37adef2019-04-01 13:49:56 -07003851}
3852
Damien Neil68b81c32019-08-22 11:41:32 -07003853// appendFloatValue encodes a float32 value as a Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003854func appendFloatValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003855 b = protowire.AppendVarint(b, wiretag)
3856 b = protowire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
Damien Neilc37adef2019-04-01 13:49:56 -07003857 return b, nil
3858}
3859
Damien Neil68b81c32019-08-22 11:41:32 -07003860// consumeFloatValue decodes a float32 value as a Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003861func consumeFloatValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003862 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003863 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003864 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003865 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003866 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003867 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003868 }
Damien Neilf0831e82020-01-21 14:25:12 -08003869 out.n = n
3870 return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003871}
3872
Damien Neil68b81c32019-08-22 11:41:32 -07003873var coderFloatValue = valueCoderFuncs{
3874 size: sizeFloatValue,
3875 marshal: appendFloatValue,
3876 unmarshal: consumeFloatValue,
Damien Neile8e88752020-02-11 11:25:16 -08003877 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003878}
3879
Damien Neil68b81c32019-08-22 11:41:32 -07003880// sizeFloatSliceValue returns the size of wire encoding a []float32 value as a repeated Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003881func sizeFloatSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07003882 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08003883 size = list.Len() * (tagsize + protowire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07003884 return size
3885}
3886
Damien Neil68b81c32019-08-22 11:41:32 -07003887// appendFloatSliceValue encodes a []float32 value as a repeated Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003888func appendFloatSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07003889 list := listv.List()
3890 for i, llen := 0, list.Len(); i < llen; i++ {
3891 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08003892 b = protowire.AppendVarint(b, wiretag)
3893 b = protowire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
Damien Neilc37adef2019-04-01 13:49:56 -07003894 }
3895 return b, nil
3896}
3897
Damien Neil68b81c32019-08-22 11:41:32 -07003898// consumeFloatSliceValue wire decodes a []float32 value as a repeated Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003899func consumeFloatSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07003900 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08003901 if wtyp == protowire.BytesType {
3902 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07003903 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003904 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003905 }
3906 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08003907 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003908 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003909 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003910 }
Damien Neil68b81c32019-08-22 11:41:32 -07003911 list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
Damien Neile91877d2019-06-27 10:54:42 -07003912 b = b[n:]
3913 }
Damien Neilf0831e82020-01-21 14:25:12 -08003914 out.n = n
3915 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003916 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003917 if wtyp != protowire.Fixed32Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003918 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003919 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003920 v, n := protowire.ConsumeFixed32(b)
Damien Neile91877d2019-06-27 10:54:42 -07003921 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003922 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003923 }
Damien Neil68b81c32019-08-22 11:41:32 -07003924 list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
Damien Neilf0831e82020-01-21 14:25:12 -08003925 out.n = n
3926 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003927}
3928
Damien Neil68b81c32019-08-22 11:41:32 -07003929var coderFloatSliceValue = valueCoderFuncs{
3930 size: sizeFloatSliceValue,
3931 marshal: appendFloatSliceValue,
3932 unmarshal: consumeFloatSliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08003933 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003934}
3935
Damien Neil68b81c32019-08-22 11:41:32 -07003936// sizeFloatPackedSliceValue returns the size of wire encoding a []float32 value as a packed repeated Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003937func sizeFloatPackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07003938 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08003939 llen := list.Len()
3940 if llen == 0 {
3941 return 0
3942 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003943 n := llen * protowire.SizeFixed32()
3944 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -07003945}
3946
Damien Neil68b81c32019-08-22 11:41:32 -07003947// appendFloatPackedSliceValue encodes a []float32 value as a packed repeated Float.
Joe Tsai41134b72020-10-19 20:51:03 -07003948func appendFloatPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07003949 list := listv.List()
3950 llen := list.Len()
3951 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07003952 return b, nil
3953 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003954 b = protowire.AppendVarint(b, wiretag)
3955 n := llen * protowire.SizeFixed32()
3956 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07003957 for i := 0; i < llen; i++ {
3958 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08003959 b = protowire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
Damien Neil7492a092019-07-10 15:23:29 -07003960 }
3961 return b, nil
3962}
3963
Damien Neil68b81c32019-08-22 11:41:32 -07003964var coderFloatPackedSliceValue = valueCoderFuncs{
3965 size: sizeFloatPackedSliceValue,
3966 marshal: appendFloatPackedSliceValue,
3967 unmarshal: consumeFloatSliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08003968 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -07003969}
3970
Damien Neilc37adef2019-04-01 13:49:56 -07003971// sizeSfixed64 returns the size of wire encoding a int64 pointer as a Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07003972func sizeSfixed64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07003973
Joe Tsaicd108d02020-02-14 18:08:02 -08003974 return f.tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07003975}
3976
3977// appendSfixed64 wire encodes a int64 pointer as a Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07003978func appendSfixed64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003979 v := *p.Int64()
Joe Tsaicd108d02020-02-14 18:08:02 -08003980 b = protowire.AppendVarint(b, f.wiretag)
3981 b = protowire.AppendFixed64(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07003982 return b, nil
3983}
3984
Damien Neile91877d2019-06-27 10:54:42 -07003985// consumeSfixed64 wire decodes a int64 pointer as a Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07003986func consumeSfixed64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08003987 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08003988 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003989 }
Joe Tsaicd108d02020-02-14 18:08:02 -08003990 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07003991 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07003992 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07003993 }
3994 *p.Int64() = int64(v)
Damien Neilf0831e82020-01-21 14:25:12 -08003995 out.n = n
3996 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07003997}
3998
Damien Neilc37adef2019-04-01 13:49:56 -07003999var coderSfixed64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004000 size: sizeSfixed64,
4001 marshal: appendSfixed64,
4002 unmarshal: consumeSfixed64,
Damien Neile8e88752020-02-11 11:25:16 -08004003 merge: mergeInt64,
Damien Neilc37adef2019-04-01 13:49:56 -07004004}
4005
Joe Tsaic51e2e02019-07-13 00:44:41 -07004006// sizeSfixed64NoZero returns the size of wire encoding a int64 pointer as a Sfixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07004007// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07004008func sizeSfixed64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004009 v := *p.Int64()
4010 if v == 0 {
4011 return 0
4012 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004013 return f.tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07004014}
4015
Joe Tsaic51e2e02019-07-13 00:44:41 -07004016// appendSfixed64NoZero wire encodes a int64 pointer as a Sfixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07004017// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07004018func appendSfixed64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004019 v := *p.Int64()
4020 if v == 0 {
4021 return b, nil
4022 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004023 b = protowire.AppendVarint(b, f.wiretag)
4024 b = protowire.AppendFixed64(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004025 return b, nil
4026}
4027
4028var coderSfixed64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004029 size: sizeSfixed64NoZero,
4030 marshal: appendSfixed64NoZero,
4031 unmarshal: consumeSfixed64,
Damien Neile8e88752020-02-11 11:25:16 -08004032 merge: mergeInt64NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07004033}
4034
4035// sizeSfixed64Ptr returns the size of wire encoding a *int64 pointer as a Sfixed64.
4036// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07004037func sizeSfixed64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004038 return f.tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07004039}
4040
Damien Neile91877d2019-06-27 10:54:42 -07004041// appendSfixed64Ptr wire encodes a *int64 pointer as a Sfixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07004042// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07004043func appendSfixed64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004044 v := **p.Int64Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08004045 b = protowire.AppendVarint(b, f.wiretag)
4046 b = protowire.AppendFixed64(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004047 return b, nil
4048}
4049
Damien Neile91877d2019-06-27 10:54:42 -07004050// consumeSfixed64Ptr wire decodes a *int64 pointer as a Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004051func consumeSfixed64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004052 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004053 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004054 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004055 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004056 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004057 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004058 }
4059 vp := p.Int64Ptr()
4060 if *vp == nil {
4061 *vp = new(int64)
4062 }
4063 **vp = int64(v)
Damien Neilf0831e82020-01-21 14:25:12 -08004064 out.n = n
4065 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004066}
4067
Damien Neilc37adef2019-04-01 13:49:56 -07004068var coderSfixed64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004069 size: sizeSfixed64Ptr,
4070 marshal: appendSfixed64Ptr,
4071 unmarshal: consumeSfixed64Ptr,
Damien Neile8e88752020-02-11 11:25:16 -08004072 merge: mergeInt64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07004073}
4074
4075// sizeSfixed64Slice returns the size of wire encoding a []int64 pointer as a repeated Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004076func sizeSfixed64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004077 s := *p.Int64Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08004078 size = len(s) * (f.tagsize + protowire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07004079 return size
4080}
4081
4082// appendSfixed64Slice encodes a []int64 pointer as a repeated Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004083func appendSfixed64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004084 s := *p.Int64Slice()
4085 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08004086 b = protowire.AppendVarint(b, f.wiretag)
4087 b = protowire.AppendFixed64(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004088 }
4089 return b, nil
4090}
4091
Damien Neile91877d2019-06-27 10:54:42 -07004092// consumeSfixed64Slice wire decodes a []int64 pointer as a repeated Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004093func consumeSfixed64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07004094 sp := p.Int64Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08004095 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07004096 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -08004097 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07004098 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004099 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004100 }
4101 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08004102 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004103 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004104 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004105 }
4106 s = append(s, int64(v))
4107 b = b[n:]
4108 }
4109 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -08004110 out.n = n
4111 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004112 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004113 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004114 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004115 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004116 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004117 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004118 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004119 }
4120 *sp = append(*sp, int64(v))
Damien Neilf0831e82020-01-21 14:25:12 -08004121 out.n = n
4122 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004123}
4124
Damien Neilc37adef2019-04-01 13:49:56 -07004125var coderSfixed64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004126 size: sizeSfixed64Slice,
4127 marshal: appendSfixed64Slice,
4128 unmarshal: consumeSfixed64Slice,
Damien Neile8e88752020-02-11 11:25:16 -08004129 merge: mergeInt64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07004130}
4131
4132// sizeSfixed64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004133func sizeSfixed64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004134 s := *p.Int64Slice()
4135 if len(s) == 0 {
4136 return 0
4137 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004138 n := len(s) * protowire.SizeFixed64()
4139 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -07004140}
4141
4142// appendSfixed64PackedSlice encodes a []int64 pointer as a packed repeated Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004143func appendSfixed64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004144 s := *p.Int64Slice()
4145 if len(s) == 0 {
4146 return b, nil
4147 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004148 b = protowire.AppendVarint(b, f.wiretag)
4149 n := len(s) * protowire.SizeFixed64()
4150 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -07004151 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08004152 b = protowire.AppendFixed64(b, uint64(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004153 }
4154 return b, nil
4155}
4156
4157var coderSfixed64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004158 size: sizeSfixed64PackedSlice,
4159 marshal: appendSfixed64PackedSlice,
4160 unmarshal: consumeSfixed64Slice,
Damien Neile8e88752020-02-11 11:25:16 -08004161 merge: mergeInt64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07004162}
4163
Damien Neil68b81c32019-08-22 11:41:32 -07004164// sizeSfixed64Value returns the size of wire encoding a int64 value as a Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004165func sizeSfixed64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08004166 return tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07004167}
4168
Damien Neil68b81c32019-08-22 11:41:32 -07004169// appendSfixed64Value encodes a int64 value as a Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004170func appendSfixed64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004171 b = protowire.AppendVarint(b, wiretag)
4172 b = protowire.AppendFixed64(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07004173 return b, nil
4174}
4175
Damien Neil68b81c32019-08-22 11:41:32 -07004176// consumeSfixed64Value decodes a int64 value as a Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004177func consumeSfixed64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004178 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004179 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004180 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004181 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004182 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004183 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004184 }
Damien Neilf0831e82020-01-21 14:25:12 -08004185 out.n = n
4186 return protoreflect.ValueOfInt64(int64(v)), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004187}
4188
Damien Neil68b81c32019-08-22 11:41:32 -07004189var coderSfixed64Value = valueCoderFuncs{
4190 size: sizeSfixed64Value,
4191 marshal: appendSfixed64Value,
4192 unmarshal: consumeSfixed64Value,
Damien Neile8e88752020-02-11 11:25:16 -08004193 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004194}
4195
Damien Neil68b81c32019-08-22 11:41:32 -07004196// sizeSfixed64SliceValue returns the size of wire encoding a []int64 value as a repeated Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004197func sizeSfixed64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07004198 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08004199 size = list.Len() * (tagsize + protowire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07004200 return size
4201}
4202
Damien Neil68b81c32019-08-22 11:41:32 -07004203// appendSfixed64SliceValue encodes a []int64 value as a repeated Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004204func appendSfixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07004205 list := listv.List()
4206 for i, llen := 0, list.Len(); i < llen; i++ {
4207 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08004208 b = protowire.AppendVarint(b, wiretag)
4209 b = protowire.AppendFixed64(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07004210 }
4211 return b, nil
4212}
4213
Damien Neil68b81c32019-08-22 11:41:32 -07004214// consumeSfixed64SliceValue wire decodes a []int64 value as a repeated Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004215func consumeSfixed64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07004216 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08004217 if wtyp == protowire.BytesType {
4218 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07004219 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004220 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004221 }
4222 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08004223 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004224 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004225 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004226 }
Damien Neil68b81c32019-08-22 11:41:32 -07004227 list.Append(protoreflect.ValueOfInt64(int64(v)))
Damien Neile91877d2019-06-27 10:54:42 -07004228 b = b[n:]
4229 }
Damien Neilf0831e82020-01-21 14:25:12 -08004230 out.n = n
4231 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004232 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004233 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004234 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004235 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004236 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004237 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004238 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004239 }
Damien Neil68b81c32019-08-22 11:41:32 -07004240 list.Append(protoreflect.ValueOfInt64(int64(v)))
Damien Neilf0831e82020-01-21 14:25:12 -08004241 out.n = n
4242 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004243}
4244
Damien Neil68b81c32019-08-22 11:41:32 -07004245var coderSfixed64SliceValue = valueCoderFuncs{
4246 size: sizeSfixed64SliceValue,
4247 marshal: appendSfixed64SliceValue,
4248 unmarshal: consumeSfixed64SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08004249 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004250}
4251
Damien Neil68b81c32019-08-22 11:41:32 -07004252// sizeSfixed64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004253func sizeSfixed64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07004254 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08004255 llen := list.Len()
4256 if llen == 0 {
4257 return 0
4258 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004259 n := llen * protowire.SizeFixed64()
4260 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -07004261}
4262
Damien Neil68b81c32019-08-22 11:41:32 -07004263// appendSfixed64PackedSliceValue encodes a []int64 value as a packed repeated Sfixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004264func appendSfixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07004265 list := listv.List()
4266 llen := list.Len()
4267 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07004268 return b, nil
4269 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004270 b = protowire.AppendVarint(b, wiretag)
4271 n := llen * protowire.SizeFixed64()
4272 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07004273 for i := 0; i < llen; i++ {
4274 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08004275 b = protowire.AppendFixed64(b, uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07004276 }
4277 return b, nil
4278}
4279
Damien Neil68b81c32019-08-22 11:41:32 -07004280var coderSfixed64PackedSliceValue = valueCoderFuncs{
4281 size: sizeSfixed64PackedSliceValue,
4282 marshal: appendSfixed64PackedSliceValue,
4283 unmarshal: consumeSfixed64SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08004284 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -07004285}
4286
Damien Neilc37adef2019-04-01 13:49:56 -07004287// sizeFixed64 returns the size of wire encoding a uint64 pointer as a Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004288func sizeFixed64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004289
Joe Tsaicd108d02020-02-14 18:08:02 -08004290 return f.tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07004291}
4292
4293// appendFixed64 wire encodes a uint64 pointer as a Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004294func appendFixed64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004295 v := *p.Uint64()
Joe Tsaicd108d02020-02-14 18:08:02 -08004296 b = protowire.AppendVarint(b, f.wiretag)
4297 b = protowire.AppendFixed64(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004298 return b, nil
4299}
4300
Damien Neile91877d2019-06-27 10:54:42 -07004301// consumeFixed64 wire decodes a uint64 pointer as a Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004302func consumeFixed64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004303 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004304 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004305 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004306 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004307 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004308 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004309 }
4310 *p.Uint64() = v
Damien Neilf0831e82020-01-21 14:25:12 -08004311 out.n = n
4312 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004313}
4314
Damien Neilc37adef2019-04-01 13:49:56 -07004315var coderFixed64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004316 size: sizeFixed64,
4317 marshal: appendFixed64,
4318 unmarshal: consumeFixed64,
Damien Neile8e88752020-02-11 11:25:16 -08004319 merge: mergeUint64,
Damien Neilc37adef2019-04-01 13:49:56 -07004320}
4321
Joe Tsaic51e2e02019-07-13 00:44:41 -07004322// sizeFixed64NoZero returns the size of wire encoding a uint64 pointer as a Fixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07004323// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07004324func sizeFixed64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004325 v := *p.Uint64()
4326 if v == 0 {
4327 return 0
4328 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004329 return f.tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07004330}
4331
Joe Tsaic51e2e02019-07-13 00:44:41 -07004332// appendFixed64NoZero wire encodes a uint64 pointer as a Fixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07004333// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07004334func appendFixed64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004335 v := *p.Uint64()
4336 if v == 0 {
4337 return b, nil
4338 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004339 b = protowire.AppendVarint(b, f.wiretag)
4340 b = protowire.AppendFixed64(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004341 return b, nil
4342}
4343
4344var coderFixed64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004345 size: sizeFixed64NoZero,
4346 marshal: appendFixed64NoZero,
4347 unmarshal: consumeFixed64,
Damien Neile8e88752020-02-11 11:25:16 -08004348 merge: mergeUint64NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07004349}
4350
4351// sizeFixed64Ptr returns the size of wire encoding a *uint64 pointer as a Fixed64.
4352// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07004353func sizeFixed64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004354 return f.tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07004355}
4356
Damien Neile91877d2019-06-27 10:54:42 -07004357// appendFixed64Ptr wire encodes a *uint64 pointer as a Fixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07004358// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07004359func appendFixed64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004360 v := **p.Uint64Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08004361 b = protowire.AppendVarint(b, f.wiretag)
4362 b = protowire.AppendFixed64(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004363 return b, nil
4364}
4365
Damien Neile91877d2019-06-27 10:54:42 -07004366// consumeFixed64Ptr wire decodes a *uint64 pointer as a Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004367func consumeFixed64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004368 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004369 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004370 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004371 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004372 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004373 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004374 }
4375 vp := p.Uint64Ptr()
4376 if *vp == nil {
4377 *vp = new(uint64)
4378 }
4379 **vp = v
Damien Neilf0831e82020-01-21 14:25:12 -08004380 out.n = n
4381 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004382}
4383
Damien Neilc37adef2019-04-01 13:49:56 -07004384var coderFixed64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004385 size: sizeFixed64Ptr,
4386 marshal: appendFixed64Ptr,
4387 unmarshal: consumeFixed64Ptr,
Damien Neile8e88752020-02-11 11:25:16 -08004388 merge: mergeUint64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07004389}
4390
4391// sizeFixed64Slice returns the size of wire encoding a []uint64 pointer as a repeated Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004392func sizeFixed64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004393 s := *p.Uint64Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08004394 size = len(s) * (f.tagsize + protowire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07004395 return size
4396}
4397
4398// appendFixed64Slice encodes a []uint64 pointer as a repeated Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004399func appendFixed64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004400 s := *p.Uint64Slice()
4401 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08004402 b = protowire.AppendVarint(b, f.wiretag)
4403 b = protowire.AppendFixed64(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004404 }
4405 return b, nil
4406}
4407
Damien Neile91877d2019-06-27 10:54:42 -07004408// consumeFixed64Slice wire decodes a []uint64 pointer as a repeated Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004409func consumeFixed64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07004410 sp := p.Uint64Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08004411 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07004412 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -08004413 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07004414 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004415 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004416 }
4417 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08004418 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004419 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004420 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004421 }
4422 s = append(s, v)
4423 b = b[n:]
4424 }
4425 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -08004426 out.n = n
4427 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004428 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004429 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004430 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004431 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004432 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004433 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004434 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004435 }
4436 *sp = append(*sp, v)
Damien Neilf0831e82020-01-21 14:25:12 -08004437 out.n = n
4438 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004439}
4440
Damien Neilc37adef2019-04-01 13:49:56 -07004441var coderFixed64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004442 size: sizeFixed64Slice,
4443 marshal: appendFixed64Slice,
4444 unmarshal: consumeFixed64Slice,
Damien Neile8e88752020-02-11 11:25:16 -08004445 merge: mergeUint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07004446}
4447
4448// sizeFixed64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004449func sizeFixed64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004450 s := *p.Uint64Slice()
4451 if len(s) == 0 {
4452 return 0
4453 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004454 n := len(s) * protowire.SizeFixed64()
4455 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -07004456}
4457
4458// appendFixed64PackedSlice encodes a []uint64 pointer as a packed repeated Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004459func appendFixed64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004460 s := *p.Uint64Slice()
4461 if len(s) == 0 {
4462 return b, nil
4463 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004464 b = protowire.AppendVarint(b, f.wiretag)
4465 n := len(s) * protowire.SizeFixed64()
4466 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -07004467 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08004468 b = protowire.AppendFixed64(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004469 }
4470 return b, nil
4471}
4472
4473var coderFixed64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004474 size: sizeFixed64PackedSlice,
4475 marshal: appendFixed64PackedSlice,
4476 unmarshal: consumeFixed64Slice,
Damien Neile8e88752020-02-11 11:25:16 -08004477 merge: mergeUint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07004478}
4479
Damien Neil68b81c32019-08-22 11:41:32 -07004480// sizeFixed64Value returns the size of wire encoding a uint64 value as a Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004481func sizeFixed64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08004482 return tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07004483}
4484
Damien Neil68b81c32019-08-22 11:41:32 -07004485// appendFixed64Value encodes a uint64 value as a Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004486func appendFixed64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004487 b = protowire.AppendVarint(b, wiretag)
4488 b = protowire.AppendFixed64(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07004489 return b, nil
4490}
4491
Damien Neil68b81c32019-08-22 11:41:32 -07004492// consumeFixed64Value decodes a uint64 value as a Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004493func consumeFixed64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004494 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004495 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004496 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004497 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004498 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004499 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004500 }
Damien Neilf0831e82020-01-21 14:25:12 -08004501 out.n = n
4502 return protoreflect.ValueOfUint64(v), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004503}
4504
Damien Neil68b81c32019-08-22 11:41:32 -07004505var coderFixed64Value = valueCoderFuncs{
4506 size: sizeFixed64Value,
4507 marshal: appendFixed64Value,
4508 unmarshal: consumeFixed64Value,
Damien Neile8e88752020-02-11 11:25:16 -08004509 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004510}
4511
Damien Neil68b81c32019-08-22 11:41:32 -07004512// sizeFixed64SliceValue returns the size of wire encoding a []uint64 value as a repeated Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004513func sizeFixed64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07004514 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08004515 size = list.Len() * (tagsize + protowire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07004516 return size
4517}
4518
Damien Neil68b81c32019-08-22 11:41:32 -07004519// appendFixed64SliceValue encodes a []uint64 value as a repeated Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004520func appendFixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07004521 list := listv.List()
4522 for i, llen := 0, list.Len(); i < llen; i++ {
4523 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08004524 b = protowire.AppendVarint(b, wiretag)
4525 b = protowire.AppendFixed64(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07004526 }
4527 return b, nil
4528}
4529
Damien Neil68b81c32019-08-22 11:41:32 -07004530// consumeFixed64SliceValue wire decodes a []uint64 value as a repeated Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004531func consumeFixed64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07004532 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08004533 if wtyp == protowire.BytesType {
4534 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07004535 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004536 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004537 }
4538 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08004539 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004540 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004541 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004542 }
Damien Neil68b81c32019-08-22 11:41:32 -07004543 list.Append(protoreflect.ValueOfUint64(v))
Damien Neile91877d2019-06-27 10:54:42 -07004544 b = b[n:]
4545 }
Damien Neilf0831e82020-01-21 14:25:12 -08004546 out.n = n
4547 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004548 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004549 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004550 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004551 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004552 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004553 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004554 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004555 }
Damien Neil68b81c32019-08-22 11:41:32 -07004556 list.Append(protoreflect.ValueOfUint64(v))
Damien Neilf0831e82020-01-21 14:25:12 -08004557 out.n = n
4558 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004559}
4560
Damien Neil68b81c32019-08-22 11:41:32 -07004561var coderFixed64SliceValue = valueCoderFuncs{
4562 size: sizeFixed64SliceValue,
4563 marshal: appendFixed64SliceValue,
4564 unmarshal: consumeFixed64SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08004565 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004566}
4567
Damien Neil68b81c32019-08-22 11:41:32 -07004568// sizeFixed64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004569func sizeFixed64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07004570 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08004571 llen := list.Len()
4572 if llen == 0 {
4573 return 0
4574 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004575 n := llen * protowire.SizeFixed64()
4576 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -07004577}
4578
Damien Neil68b81c32019-08-22 11:41:32 -07004579// appendFixed64PackedSliceValue encodes a []uint64 value as a packed repeated Fixed64.
Joe Tsai41134b72020-10-19 20:51:03 -07004580func appendFixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07004581 list := listv.List()
4582 llen := list.Len()
4583 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07004584 return b, nil
4585 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004586 b = protowire.AppendVarint(b, wiretag)
4587 n := llen * protowire.SizeFixed64()
4588 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07004589 for i := 0; i < llen; i++ {
4590 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08004591 b = protowire.AppendFixed64(b, v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07004592 }
4593 return b, nil
4594}
4595
Damien Neil68b81c32019-08-22 11:41:32 -07004596var coderFixed64PackedSliceValue = valueCoderFuncs{
4597 size: sizeFixed64PackedSliceValue,
4598 marshal: appendFixed64PackedSliceValue,
4599 unmarshal: consumeFixed64SliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08004600 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -07004601}
4602
Damien Neilc37adef2019-04-01 13:49:56 -07004603// sizeDouble returns the size of wire encoding a float64 pointer as a Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004604func sizeDouble(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004605
Joe Tsaicd108d02020-02-14 18:08:02 -08004606 return f.tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07004607}
4608
4609// appendDouble wire encodes a float64 pointer as a Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004610func appendDouble(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004611 v := *p.Float64()
Joe Tsaicd108d02020-02-14 18:08:02 -08004612 b = protowire.AppendVarint(b, f.wiretag)
4613 b = protowire.AppendFixed64(b, math.Float64bits(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004614 return b, nil
4615}
4616
Damien Neile91877d2019-06-27 10:54:42 -07004617// consumeDouble wire decodes a float64 pointer as a Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004618func consumeDouble(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004619 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004620 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004621 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004622 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004623 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004624 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004625 }
4626 *p.Float64() = math.Float64frombits(v)
Damien Neilf0831e82020-01-21 14:25:12 -08004627 out.n = n
4628 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004629}
4630
Damien Neilc37adef2019-04-01 13:49:56 -07004631var coderDouble = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004632 size: sizeDouble,
4633 marshal: appendDouble,
4634 unmarshal: consumeDouble,
Damien Neile8e88752020-02-11 11:25:16 -08004635 merge: mergeFloat64,
Damien Neilc37adef2019-04-01 13:49:56 -07004636}
4637
Joe Tsaic51e2e02019-07-13 00:44:41 -07004638// sizeDoubleNoZero returns the size of wire encoding a float64 pointer as a Double.
Damien Neilc37adef2019-04-01 13:49:56 -07004639// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07004640func sizeDoubleNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004641 v := *p.Float64()
4642 if v == 0 && !math.Signbit(float64(v)) {
4643 return 0
4644 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004645 return f.tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07004646}
4647
Joe Tsaic51e2e02019-07-13 00:44:41 -07004648// appendDoubleNoZero wire encodes a float64 pointer as a Double.
Damien Neilc37adef2019-04-01 13:49:56 -07004649// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07004650func appendDoubleNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004651 v := *p.Float64()
4652 if v == 0 && !math.Signbit(float64(v)) {
4653 return b, nil
4654 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004655 b = protowire.AppendVarint(b, f.wiretag)
4656 b = protowire.AppendFixed64(b, math.Float64bits(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004657 return b, nil
4658}
4659
4660var coderDoubleNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004661 size: sizeDoubleNoZero,
4662 marshal: appendDoubleNoZero,
4663 unmarshal: consumeDouble,
Damien Neile8e88752020-02-11 11:25:16 -08004664 merge: mergeFloat64NoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07004665}
4666
4667// sizeDoublePtr returns the size of wire encoding a *float64 pointer as a Double.
4668// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07004669func sizeDoublePtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004670 return f.tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07004671}
4672
Damien Neile91877d2019-06-27 10:54:42 -07004673// appendDoublePtr wire encodes a *float64 pointer as a Double.
Damien Neilc37adef2019-04-01 13:49:56 -07004674// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07004675func appendDoublePtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004676 v := **p.Float64Ptr()
Joe Tsaicd108d02020-02-14 18:08:02 -08004677 b = protowire.AppendVarint(b, f.wiretag)
4678 b = protowire.AppendFixed64(b, math.Float64bits(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004679 return b, nil
4680}
4681
Damien Neile91877d2019-06-27 10:54:42 -07004682// consumeDoublePtr wire decodes a *float64 pointer as a Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004683func consumeDoublePtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004684 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004685 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004686 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004687 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004688 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004689 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004690 }
4691 vp := p.Float64Ptr()
4692 if *vp == nil {
4693 *vp = new(float64)
4694 }
4695 **vp = math.Float64frombits(v)
Damien Neilf0831e82020-01-21 14:25:12 -08004696 out.n = n
4697 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004698}
4699
Damien Neilc37adef2019-04-01 13:49:56 -07004700var coderDoublePtr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004701 size: sizeDoublePtr,
4702 marshal: appendDoublePtr,
4703 unmarshal: consumeDoublePtr,
Damien Neile8e88752020-02-11 11:25:16 -08004704 merge: mergeFloat64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07004705}
4706
4707// sizeDoubleSlice returns the size of wire encoding a []float64 pointer as a repeated Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004708func sizeDoubleSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004709 s := *p.Float64Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08004710 size = len(s) * (f.tagsize + protowire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07004711 return size
4712}
4713
4714// appendDoubleSlice encodes a []float64 pointer as a repeated Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004715func appendDoubleSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004716 s := *p.Float64Slice()
4717 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08004718 b = protowire.AppendVarint(b, f.wiretag)
4719 b = protowire.AppendFixed64(b, math.Float64bits(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004720 }
4721 return b, nil
4722}
4723
Damien Neile91877d2019-06-27 10:54:42 -07004724// consumeDoubleSlice wire decodes a []float64 pointer as a repeated Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004725func consumeDoubleSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07004726 sp := p.Float64Slice()
Joe Tsaicd108d02020-02-14 18:08:02 -08004727 if wtyp == protowire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07004728 s := *sp
Joe Tsaicd108d02020-02-14 18:08:02 -08004729 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07004730 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004731 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004732 }
4733 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08004734 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004735 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004736 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004737 }
4738 s = append(s, math.Float64frombits(v))
4739 b = b[n:]
4740 }
4741 *sp = s
Damien Neilf0831e82020-01-21 14:25:12 -08004742 out.n = n
4743 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004744 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004745 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004746 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004747 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004748 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004749 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004750 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004751 }
4752 *sp = append(*sp, math.Float64frombits(v))
Damien Neilf0831e82020-01-21 14:25:12 -08004753 out.n = n
4754 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004755}
4756
Damien Neilc37adef2019-04-01 13:49:56 -07004757var coderDoubleSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004758 size: sizeDoubleSlice,
4759 marshal: appendDoubleSlice,
4760 unmarshal: consumeDoubleSlice,
Damien Neile8e88752020-02-11 11:25:16 -08004761 merge: mergeFloat64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07004762}
4763
4764// sizeDoublePackedSlice returns the size of wire encoding a []float64 pointer as a packed repeated Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004765func sizeDoublePackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004766 s := *p.Float64Slice()
4767 if len(s) == 0 {
4768 return 0
4769 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004770 n := len(s) * protowire.SizeFixed64()
4771 return f.tagsize + protowire.SizeBytes(n)
Damien Neilc37adef2019-04-01 13:49:56 -07004772}
4773
4774// appendDoublePackedSlice encodes a []float64 pointer as a packed repeated Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004775func appendDoublePackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004776 s := *p.Float64Slice()
4777 if len(s) == 0 {
4778 return b, nil
4779 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004780 b = protowire.AppendVarint(b, f.wiretag)
4781 n := len(s) * protowire.SizeFixed64()
4782 b = protowire.AppendVarint(b, uint64(n))
Damien Neilc37adef2019-04-01 13:49:56 -07004783 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08004784 b = protowire.AppendFixed64(b, math.Float64bits(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004785 }
4786 return b, nil
4787}
4788
4789var coderDoublePackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004790 size: sizeDoublePackedSlice,
4791 marshal: appendDoublePackedSlice,
4792 unmarshal: consumeDoubleSlice,
Damien Neile8e88752020-02-11 11:25:16 -08004793 merge: mergeFloat64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07004794}
4795
Damien Neil68b81c32019-08-22 11:41:32 -07004796// sizeDoubleValue returns the size of wire encoding a float64 value as a Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004797func sizeDoubleValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08004798 return tagsize + protowire.SizeFixed64()
Damien Neilc37adef2019-04-01 13:49:56 -07004799}
4800
Damien Neil68b81c32019-08-22 11:41:32 -07004801// appendDoubleValue encodes a float64 value as a Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004802func appendDoubleValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004803 b = protowire.AppendVarint(b, wiretag)
4804 b = protowire.AppendFixed64(b, math.Float64bits(v.Float()))
Damien Neilc37adef2019-04-01 13:49:56 -07004805 return b, nil
4806}
4807
Damien Neil68b81c32019-08-22 11:41:32 -07004808// consumeDoubleValue decodes a float64 value as a Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004809func consumeDoubleValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004810 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004811 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004812 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004813 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004814 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004815 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004816 }
Damien Neilf0831e82020-01-21 14:25:12 -08004817 out.n = n
4818 return protoreflect.ValueOfFloat64(math.Float64frombits(v)), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004819}
4820
Damien Neil68b81c32019-08-22 11:41:32 -07004821var coderDoubleValue = valueCoderFuncs{
4822 size: sizeDoubleValue,
4823 marshal: appendDoubleValue,
4824 unmarshal: consumeDoubleValue,
Damien Neile8e88752020-02-11 11:25:16 -08004825 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004826}
4827
Damien Neil68b81c32019-08-22 11:41:32 -07004828// sizeDoubleSliceValue returns the size of wire encoding a []float64 value as a repeated Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004829func sizeDoubleSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07004830 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08004831 size = list.Len() * (tagsize + protowire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07004832 return size
4833}
4834
Damien Neil68b81c32019-08-22 11:41:32 -07004835// appendDoubleSliceValue encodes a []float64 value as a repeated Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004836func appendDoubleSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07004837 list := listv.List()
4838 for i, llen := 0, list.Len(); i < llen; i++ {
4839 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08004840 b = protowire.AppendVarint(b, wiretag)
4841 b = protowire.AppendFixed64(b, math.Float64bits(v.Float()))
Damien Neilc37adef2019-04-01 13:49:56 -07004842 }
4843 return b, nil
4844}
4845
Damien Neil68b81c32019-08-22 11:41:32 -07004846// consumeDoubleSliceValue wire decodes a []float64 value as a repeated Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004847func consumeDoubleSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07004848 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08004849 if wtyp == protowire.BytesType {
4850 b, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07004851 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004852 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004853 }
4854 for len(b) > 0 {
Joe Tsaicd108d02020-02-14 18:08:02 -08004855 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004856 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004857 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004858 }
Damien Neil68b81c32019-08-22 11:41:32 -07004859 list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
Damien Neile91877d2019-06-27 10:54:42 -07004860 b = b[n:]
4861 }
Damien Neilf0831e82020-01-21 14:25:12 -08004862 out.n = n
4863 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004864 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004865 if wtyp != protowire.Fixed64Type {
Damien Neilf0831e82020-01-21 14:25:12 -08004866 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004867 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004868 v, n := protowire.ConsumeFixed64(b)
Damien Neile91877d2019-06-27 10:54:42 -07004869 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004870 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004871 }
Damien Neil68b81c32019-08-22 11:41:32 -07004872 list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
Damien Neilf0831e82020-01-21 14:25:12 -08004873 out.n = n
4874 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004875}
4876
Damien Neil68b81c32019-08-22 11:41:32 -07004877var coderDoubleSliceValue = valueCoderFuncs{
4878 size: sizeDoubleSliceValue,
4879 marshal: appendDoubleSliceValue,
4880 unmarshal: consumeDoubleSliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08004881 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004882}
4883
Damien Neil68b81c32019-08-22 11:41:32 -07004884// sizeDoublePackedSliceValue returns the size of wire encoding a []float64 value as a packed repeated Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004885func sizeDoublePackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07004886 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08004887 llen := list.Len()
4888 if llen == 0 {
4889 return 0
4890 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004891 n := llen * protowire.SizeFixed64()
4892 return tagsize + protowire.SizeBytes(n)
Damien Neil7492a092019-07-10 15:23:29 -07004893}
4894
Damien Neil68b81c32019-08-22 11:41:32 -07004895// appendDoublePackedSliceValue encodes a []float64 value as a packed repeated Double.
Joe Tsai41134b72020-10-19 20:51:03 -07004896func appendDoublePackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07004897 list := listv.List()
4898 llen := list.Len()
4899 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07004900 return b, nil
4901 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004902 b = protowire.AppendVarint(b, wiretag)
4903 n := llen * protowire.SizeFixed64()
4904 b = protowire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07004905 for i := 0; i < llen; i++ {
4906 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08004907 b = protowire.AppendFixed64(b, math.Float64bits(v.Float()))
Damien Neil7492a092019-07-10 15:23:29 -07004908 }
4909 return b, nil
4910}
4911
Damien Neil68b81c32019-08-22 11:41:32 -07004912var coderDoublePackedSliceValue = valueCoderFuncs{
4913 size: sizeDoublePackedSliceValue,
4914 marshal: appendDoublePackedSliceValue,
4915 unmarshal: consumeDoubleSliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08004916 merge: mergeListValue,
Damien Neil7492a092019-07-10 15:23:29 -07004917}
4918
Damien Neilc37adef2019-04-01 13:49:56 -07004919// sizeString returns the size of wire encoding a string pointer as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07004920func sizeString(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004921 v := *p.String()
Joe Tsaicd108d02020-02-14 18:08:02 -08004922 return f.tagsize + protowire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004923}
4924
4925// appendString wire encodes a string pointer as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07004926func appendString(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004927 v := *p.String()
Joe Tsaicd108d02020-02-14 18:08:02 -08004928 b = protowire.AppendVarint(b, f.wiretag)
4929 b = protowire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004930 return b, nil
4931}
4932
Damien Neile91877d2019-06-27 10:54:42 -07004933// consumeString wire decodes a string pointer as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07004934func consumeString(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004935 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08004936 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004937 }
Joe Tsaid3470992020-10-19 20:57:54 -07004938 v, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07004939 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004940 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07004941 }
Joe Tsaid3470992020-10-19 20:57:54 -07004942 *p.String() = string(v)
Damien Neilf0831e82020-01-21 14:25:12 -08004943 out.n = n
4944 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07004945}
4946
Damien Neilc37adef2019-04-01 13:49:56 -07004947var coderString = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004948 size: sizeString,
4949 marshal: appendString,
4950 unmarshal: consumeString,
Damien Neile8e88752020-02-11 11:25:16 -08004951 merge: mergeString,
Damien Neilc37adef2019-04-01 13:49:56 -07004952}
4953
Joe Tsaic51e2e02019-07-13 00:44:41 -07004954// appendStringValidateUTF8 wire encodes a string pointer as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07004955func appendStringValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07004956 v := *p.String()
Joe Tsaicd108d02020-02-14 18:08:02 -08004957 b = protowire.AppendVarint(b, f.wiretag)
4958 b = protowire.AppendString(b, v)
Joe Tsaic51e2e02019-07-13 00:44:41 -07004959 if !utf8.ValidString(v) {
4960 return b, errInvalidUTF8{}
4961 }
4962 return b, nil
4963}
4964
4965// consumeStringValidateUTF8 wire decodes a string pointer as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07004966func consumeStringValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08004967 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08004968 return out, errUnknown
Joe Tsaic51e2e02019-07-13 00:44:41 -07004969 }
Joe Tsaid3470992020-10-19 20:57:54 -07004970 v, n := protowire.ConsumeBytes(b)
Joe Tsaic51e2e02019-07-13 00:44:41 -07004971 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07004972 return out, errDecode
Joe Tsaic51e2e02019-07-13 00:44:41 -07004973 }
Joe Tsaid3470992020-10-19 20:57:54 -07004974 if !utf8.Valid(v) {
Damien Neilf0831e82020-01-21 14:25:12 -08004975 return out, errInvalidUTF8{}
Joe Tsaic51e2e02019-07-13 00:44:41 -07004976 }
Joe Tsaid3470992020-10-19 20:57:54 -07004977 *p.String() = string(v)
Damien Neilf0831e82020-01-21 14:25:12 -08004978 out.n = n
4979 return out, nil
Joe Tsaic51e2e02019-07-13 00:44:41 -07004980}
4981
4982var coderStringValidateUTF8 = pointerCoderFuncs{
4983 size: sizeString,
4984 marshal: appendStringValidateUTF8,
4985 unmarshal: consumeStringValidateUTF8,
Damien Neile8e88752020-02-11 11:25:16 -08004986 merge: mergeString,
Joe Tsaic51e2e02019-07-13 00:44:41 -07004987}
4988
4989// sizeStringNoZero returns the size of wire encoding a string pointer as a String.
Damien Neilc37adef2019-04-01 13:49:56 -07004990// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07004991func sizeStringNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07004992 v := *p.String()
4993 if len(v) == 0 {
4994 return 0
4995 }
Joe Tsaicd108d02020-02-14 18:08:02 -08004996 return f.tagsize + protowire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004997}
4998
Joe Tsaic51e2e02019-07-13 00:44:41 -07004999// appendStringNoZero wire encodes a string pointer as a String.
Damien Neilc37adef2019-04-01 13:49:56 -07005000// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07005001func appendStringNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07005002 v := *p.String()
5003 if len(v) == 0 {
5004 return b, nil
5005 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005006 b = protowire.AppendVarint(b, f.wiretag)
5007 b = protowire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07005008 return b, nil
5009}
5010
5011var coderStringNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07005012 size: sizeStringNoZero,
5013 marshal: appendStringNoZero,
5014 unmarshal: consumeString,
Damien Neile8e88752020-02-11 11:25:16 -08005015 merge: mergeStringNoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07005016}
5017
Joe Tsaic51e2e02019-07-13 00:44:41 -07005018// appendStringNoZeroValidateUTF8 wire encodes a string pointer as a String.
5019// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07005020func appendStringNoZeroValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07005021 v := *p.String()
5022 if len(v) == 0 {
5023 return b, nil
5024 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005025 b = protowire.AppendVarint(b, f.wiretag)
5026 b = protowire.AppendString(b, v)
Joe Tsaic51e2e02019-07-13 00:44:41 -07005027 if !utf8.ValidString(v) {
5028 return b, errInvalidUTF8{}
5029 }
5030 return b, nil
5031}
5032
5033var coderStringNoZeroValidateUTF8 = pointerCoderFuncs{
5034 size: sizeStringNoZero,
5035 marshal: appendStringNoZeroValidateUTF8,
5036 unmarshal: consumeStringValidateUTF8,
Damien Neile8e88752020-02-11 11:25:16 -08005037 merge: mergeStringNoZero,
Joe Tsaic51e2e02019-07-13 00:44:41 -07005038}
5039
Damien Neilc37adef2019-04-01 13:49:56 -07005040// sizeStringPtr returns the size of wire encoding a *string pointer as a String.
5041// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07005042func sizeStringPtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07005043 v := **p.StringPtr()
Joe Tsaicd108d02020-02-14 18:08:02 -08005044 return f.tagsize + protowire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07005045}
5046
Damien Neile91877d2019-06-27 10:54:42 -07005047// appendStringPtr wire encodes a *string pointer as a String.
Damien Neilc37adef2019-04-01 13:49:56 -07005048// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07005049func appendStringPtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07005050 v := **p.StringPtr()
Joe Tsaicd108d02020-02-14 18:08:02 -08005051 b = protowire.AppendVarint(b, f.wiretag)
5052 b = protowire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07005053 return b, nil
5054}
5055
Damien Neile91877d2019-06-27 10:54:42 -07005056// consumeStringPtr wire decodes a *string pointer as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07005057func consumeStringPtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005058 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005059 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07005060 }
Joe Tsaid3470992020-10-19 20:57:54 -07005061 v, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07005062 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005063 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07005064 }
5065 vp := p.StringPtr()
5066 if *vp == nil {
5067 *vp = new(string)
5068 }
Joe Tsaid3470992020-10-19 20:57:54 -07005069 **vp = string(v)
Damien Neilf0831e82020-01-21 14:25:12 -08005070 out.n = n
5071 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07005072}
5073
Damien Neilc37adef2019-04-01 13:49:56 -07005074var coderStringPtr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07005075 size: sizeStringPtr,
5076 marshal: appendStringPtr,
5077 unmarshal: consumeStringPtr,
Damien Neile8e88752020-02-11 11:25:16 -08005078 merge: mergeStringPtr,
Damien Neilc37adef2019-04-01 13:49:56 -07005079}
5080
Joe Tsaid0a499b2020-04-30 17:45:48 -07005081// appendStringPtrValidateUTF8 wire encodes a *string pointer as a String.
5082// It panics if the pointer is nil.
Joe Tsai41134b72020-10-19 20:51:03 -07005083func appendStringPtrValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Joe Tsaid0a499b2020-04-30 17:45:48 -07005084 v := **p.StringPtr()
5085 b = protowire.AppendVarint(b, f.wiretag)
5086 b = protowire.AppendString(b, v)
5087 if !utf8.ValidString(v) {
5088 return b, errInvalidUTF8{}
5089 }
5090 return b, nil
5091}
5092
5093// consumeStringPtrValidateUTF8 wire decodes a *string pointer as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07005094func consumeStringPtrValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaid0a499b2020-04-30 17:45:48 -07005095 if wtyp != protowire.BytesType {
5096 return out, errUnknown
5097 }
Joe Tsaid3470992020-10-19 20:57:54 -07005098 v, n := protowire.ConsumeBytes(b)
Joe Tsaid0a499b2020-04-30 17:45:48 -07005099 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005100 return out, errDecode
Joe Tsaid0a499b2020-04-30 17:45:48 -07005101 }
Joe Tsaid3470992020-10-19 20:57:54 -07005102 if !utf8.Valid(v) {
Joe Tsaid0a499b2020-04-30 17:45:48 -07005103 return out, errInvalidUTF8{}
5104 }
5105 vp := p.StringPtr()
5106 if *vp == nil {
5107 *vp = new(string)
5108 }
Joe Tsaid3470992020-10-19 20:57:54 -07005109 **vp = string(v)
Joe Tsaid0a499b2020-04-30 17:45:48 -07005110 out.n = n
5111 return out, nil
5112}
5113
5114var coderStringPtrValidateUTF8 = pointerCoderFuncs{
5115 size: sizeStringPtr,
5116 marshal: appendStringPtrValidateUTF8,
5117 unmarshal: consumeStringPtrValidateUTF8,
5118 merge: mergeStringPtr,
5119}
5120
Damien Neilc37adef2019-04-01 13:49:56 -07005121// sizeStringSlice returns the size of wire encoding a []string pointer as a repeated String.
Joe Tsai41134b72020-10-19 20:51:03 -07005122func sizeStringSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07005123 s := *p.StringSlice()
5124 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08005125 size += f.tagsize + protowire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07005126 }
5127 return size
5128}
5129
5130// appendStringSlice encodes a []string pointer as a repeated String.
Joe Tsai41134b72020-10-19 20:51:03 -07005131func appendStringSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07005132 s := *p.StringSlice()
5133 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08005134 b = protowire.AppendVarint(b, f.wiretag)
5135 b = protowire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07005136 }
5137 return b, nil
5138}
5139
Damien Neile91877d2019-06-27 10:54:42 -07005140// consumeStringSlice wire decodes a []string pointer as a repeated String.
Joe Tsai41134b72020-10-19 20:51:03 -07005141func consumeStringSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07005142 sp := p.StringSlice()
Joe Tsaicd108d02020-02-14 18:08:02 -08005143 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005144 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07005145 }
Joe Tsaid3470992020-10-19 20:57:54 -07005146 v, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07005147 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005148 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07005149 }
Joe Tsaid3470992020-10-19 20:57:54 -07005150 *sp = append(*sp, string(v))
Damien Neilf0831e82020-01-21 14:25:12 -08005151 out.n = n
5152 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07005153}
5154
Damien Neilc37adef2019-04-01 13:49:56 -07005155var coderStringSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07005156 size: sizeStringSlice,
5157 marshal: appendStringSlice,
5158 unmarshal: consumeStringSlice,
Damien Neile8e88752020-02-11 11:25:16 -08005159 merge: mergeStringSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07005160}
5161
Joe Tsaic51e2e02019-07-13 00:44:41 -07005162// appendStringSliceValidateUTF8 encodes a []string pointer as a repeated String.
Joe Tsai41134b72020-10-19 20:51:03 -07005163func appendStringSliceValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07005164 s := *p.StringSlice()
5165 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08005166 b = protowire.AppendVarint(b, f.wiretag)
5167 b = protowire.AppendString(b, v)
Joe Tsaic51e2e02019-07-13 00:44:41 -07005168 if !utf8.ValidString(v) {
5169 return b, errInvalidUTF8{}
5170 }
5171 }
5172 return b, nil
5173}
5174
5175// consumeStringSliceValidateUTF8 wire decodes a []string pointer as a repeated String.
Joe Tsai41134b72020-10-19 20:51:03 -07005176func consumeStringSliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005177 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005178 return out, errUnknown
Joe Tsaic51e2e02019-07-13 00:44:41 -07005179 }
Joe Tsaid3470992020-10-19 20:57:54 -07005180 v, n := protowire.ConsumeBytes(b)
Joe Tsaic51e2e02019-07-13 00:44:41 -07005181 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005182 return out, errDecode
Joe Tsaic51e2e02019-07-13 00:44:41 -07005183 }
Joe Tsaid3470992020-10-19 20:57:54 -07005184 if !utf8.Valid(v) {
Damien Neilf0831e82020-01-21 14:25:12 -08005185 return out, errInvalidUTF8{}
Joe Tsaic51e2e02019-07-13 00:44:41 -07005186 }
Joe Tsai44626bc2020-10-19 20:32:27 -07005187 sp := p.StringSlice()
Joe Tsaid3470992020-10-19 20:57:54 -07005188 *sp = append(*sp, string(v))
Damien Neilf0831e82020-01-21 14:25:12 -08005189 out.n = n
5190 return out, nil
Joe Tsaic51e2e02019-07-13 00:44:41 -07005191}
5192
5193var coderStringSliceValidateUTF8 = pointerCoderFuncs{
5194 size: sizeStringSlice,
5195 marshal: appendStringSliceValidateUTF8,
5196 unmarshal: consumeStringSliceValidateUTF8,
Damien Neile8e88752020-02-11 11:25:16 -08005197 merge: mergeStringSlice,
Joe Tsaic51e2e02019-07-13 00:44:41 -07005198}
5199
Damien Neil68b81c32019-08-22 11:41:32 -07005200// sizeStringValue returns the size of wire encoding a string value as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07005201func sizeStringValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08005202 return tagsize + protowire.SizeBytes(len(v.String()))
Damien Neilc37adef2019-04-01 13:49:56 -07005203}
5204
Damien Neil68b81c32019-08-22 11:41:32 -07005205// appendStringValue encodes a string value as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07005206func appendStringValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005207 b = protowire.AppendVarint(b, wiretag)
5208 b = protowire.AppendString(b, v.String())
Damien Neilc37adef2019-04-01 13:49:56 -07005209 return b, nil
5210}
5211
Damien Neil68b81c32019-08-22 11:41:32 -07005212// consumeStringValue decodes a string value as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07005213func consumeStringValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005214 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005215 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07005216 }
Joe Tsaid3470992020-10-19 20:57:54 -07005217 v, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07005218 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005219 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07005220 }
Damien Neilf0831e82020-01-21 14:25:12 -08005221 out.n = n
5222 return protoreflect.ValueOfString(string(v)), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07005223}
5224
Damien Neil68b81c32019-08-22 11:41:32 -07005225var coderStringValue = valueCoderFuncs{
5226 size: sizeStringValue,
5227 marshal: appendStringValue,
5228 unmarshal: consumeStringValue,
Damien Neile8e88752020-02-11 11:25:16 -08005229 merge: mergeScalarValue,
Damien Neilc37adef2019-04-01 13:49:56 -07005230}
5231
Damien Neil68b81c32019-08-22 11:41:32 -07005232// appendStringValueValidateUTF8 encodes a string value as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07005233func appendStringValueValidateUTF8(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005234 b = protowire.AppendVarint(b, wiretag)
5235 b = protowire.AppendString(b, v.String())
Damien Neil68b81c32019-08-22 11:41:32 -07005236 if !utf8.ValidString(v.String()) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07005237 return b, errInvalidUTF8{}
5238 }
5239 return b, nil
5240}
5241
Damien Neil68b81c32019-08-22 11:41:32 -07005242// consumeStringValueValidateUTF8 decodes a string value as a String.
Joe Tsai41134b72020-10-19 20:51:03 -07005243func consumeStringValueValidateUTF8(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005244 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005245 return protoreflect.Value{}, out, errUnknown
Joe Tsaic51e2e02019-07-13 00:44:41 -07005246 }
Joe Tsaid3470992020-10-19 20:57:54 -07005247 v, n := protowire.ConsumeBytes(b)
Joe Tsaic51e2e02019-07-13 00:44:41 -07005248 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005249 return protoreflect.Value{}, out, errDecode
Joe Tsaic51e2e02019-07-13 00:44:41 -07005250 }
Joe Tsaid3470992020-10-19 20:57:54 -07005251 if !utf8.Valid(v) {
Damien Neilf0831e82020-01-21 14:25:12 -08005252 return protoreflect.Value{}, out, errInvalidUTF8{}
Joe Tsaic51e2e02019-07-13 00:44:41 -07005253 }
Damien Neilf0831e82020-01-21 14:25:12 -08005254 out.n = n
5255 return protoreflect.ValueOfString(string(v)), out, nil
Joe Tsaic51e2e02019-07-13 00:44:41 -07005256}
5257
Damien Neil68b81c32019-08-22 11:41:32 -07005258var coderStringValueValidateUTF8 = valueCoderFuncs{
5259 size: sizeStringValue,
5260 marshal: appendStringValueValidateUTF8,
5261 unmarshal: consumeStringValueValidateUTF8,
Damien Neile8e88752020-02-11 11:25:16 -08005262 merge: mergeScalarValue,
Joe Tsaic51e2e02019-07-13 00:44:41 -07005263}
5264
Damien Neil68b81c32019-08-22 11:41:32 -07005265// sizeStringSliceValue returns the size of wire encoding a []string value as a repeated String.
Joe Tsai41134b72020-10-19 20:51:03 -07005266func sizeStringSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07005267 list := listv.List()
5268 for i, llen := 0, list.Len(); i < llen; i++ {
5269 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08005270 size += tagsize + protowire.SizeBytes(len(v.String()))
Damien Neilc37adef2019-04-01 13:49:56 -07005271 }
5272 return size
5273}
5274
Damien Neil68b81c32019-08-22 11:41:32 -07005275// appendStringSliceValue encodes a []string value as a repeated String.
Joe Tsai41134b72020-10-19 20:51:03 -07005276func appendStringSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07005277 list := listv.List()
5278 for i, llen := 0, list.Len(); i < llen; i++ {
5279 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08005280 b = protowire.AppendVarint(b, wiretag)
5281 b = protowire.AppendString(b, v.String())
Damien Neilc37adef2019-04-01 13:49:56 -07005282 }
5283 return b, nil
5284}
5285
Damien Neil68b81c32019-08-22 11:41:32 -07005286// consumeStringSliceValue wire decodes a []string value as a repeated String.
Joe Tsai41134b72020-10-19 20:51:03 -07005287func consumeStringSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07005288 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08005289 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005290 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07005291 }
Joe Tsaid3470992020-10-19 20:57:54 -07005292 v, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07005293 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005294 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07005295 }
Damien Neil68b81c32019-08-22 11:41:32 -07005296 list.Append(protoreflect.ValueOfString(string(v)))
Damien Neilf0831e82020-01-21 14:25:12 -08005297 out.n = n
5298 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07005299}
5300
Damien Neil68b81c32019-08-22 11:41:32 -07005301var coderStringSliceValue = valueCoderFuncs{
5302 size: sizeStringSliceValue,
5303 marshal: appendStringSliceValue,
5304 unmarshal: consumeStringSliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08005305 merge: mergeListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07005306}
5307
5308// sizeBytes returns the size of wire encoding a []byte pointer as a Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005309func sizeBytes(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07005310 v := *p.Bytes()
Joe Tsaicd108d02020-02-14 18:08:02 -08005311 return f.tagsize + protowire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07005312}
5313
5314// appendBytes wire encodes a []byte pointer as a Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005315func appendBytes(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07005316 v := *p.Bytes()
Joe Tsaicd108d02020-02-14 18:08:02 -08005317 b = protowire.AppendVarint(b, f.wiretag)
5318 b = protowire.AppendBytes(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07005319 return b, nil
5320}
5321
Damien Neile91877d2019-06-27 10:54:42 -07005322// consumeBytes wire decodes a []byte pointer as a Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005323func consumeBytes(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005324 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005325 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07005326 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005327 v, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07005328 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005329 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07005330 }
Damien Neil8003f082019-08-02 15:13:00 -07005331 *p.Bytes() = append(emptyBuf[:], v...)
Damien Neilf0831e82020-01-21 14:25:12 -08005332 out.n = n
5333 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07005334}
5335
Damien Neilc37adef2019-04-01 13:49:56 -07005336var coderBytes = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07005337 size: sizeBytes,
5338 marshal: appendBytes,
5339 unmarshal: consumeBytes,
Damien Neile8e88752020-02-11 11:25:16 -08005340 merge: mergeBytes,
Damien Neilc37adef2019-04-01 13:49:56 -07005341}
5342
Joe Tsaic51e2e02019-07-13 00:44:41 -07005343// appendBytesValidateUTF8 wire encodes a []byte pointer as a Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005344func appendBytesValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07005345 v := *p.Bytes()
Joe Tsaicd108d02020-02-14 18:08:02 -08005346 b = protowire.AppendVarint(b, f.wiretag)
5347 b = protowire.AppendBytes(b, v)
Joe Tsaic51e2e02019-07-13 00:44:41 -07005348 if !utf8.Valid(v) {
5349 return b, errInvalidUTF8{}
5350 }
5351 return b, nil
5352}
5353
5354// consumeBytesValidateUTF8 wire decodes a []byte pointer as a Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005355func consumeBytesValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005356 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005357 return out, errUnknown
Joe Tsaic51e2e02019-07-13 00:44:41 -07005358 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005359 v, n := protowire.ConsumeBytes(b)
Joe Tsaic51e2e02019-07-13 00:44:41 -07005360 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005361 return out, errDecode
Joe Tsaic51e2e02019-07-13 00:44:41 -07005362 }
5363 if !utf8.Valid(v) {
Damien Neilf0831e82020-01-21 14:25:12 -08005364 return out, errInvalidUTF8{}
Joe Tsaic51e2e02019-07-13 00:44:41 -07005365 }
Damien Neil8003f082019-08-02 15:13:00 -07005366 *p.Bytes() = append(emptyBuf[:], v...)
Damien Neilf0831e82020-01-21 14:25:12 -08005367 out.n = n
5368 return out, nil
Joe Tsaic51e2e02019-07-13 00:44:41 -07005369}
5370
5371var coderBytesValidateUTF8 = pointerCoderFuncs{
5372 size: sizeBytes,
5373 marshal: appendBytesValidateUTF8,
5374 unmarshal: consumeBytesValidateUTF8,
Damien Neile8e88752020-02-11 11:25:16 -08005375 merge: mergeBytes,
Joe Tsaic51e2e02019-07-13 00:44:41 -07005376}
5377
5378// sizeBytesNoZero returns the size of wire encoding a []byte pointer as a Bytes.
Damien Neilc37adef2019-04-01 13:49:56 -07005379// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07005380func sizeBytesNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07005381 v := *p.Bytes()
5382 if len(v) == 0 {
5383 return 0
5384 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005385 return f.tagsize + protowire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07005386}
5387
Joe Tsaic51e2e02019-07-13 00:44:41 -07005388// appendBytesNoZero wire encodes a []byte pointer as a Bytes.
Damien Neilc37adef2019-04-01 13:49:56 -07005389// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07005390func appendBytesNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07005391 v := *p.Bytes()
5392 if len(v) == 0 {
5393 return b, nil
5394 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005395 b = protowire.AppendVarint(b, f.wiretag)
5396 b = protowire.AppendBytes(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07005397 return b, nil
5398}
5399
Damien Neil8003f082019-08-02 15:13:00 -07005400// consumeBytesNoZero wire decodes a []byte pointer as a Bytes.
5401// The zero value is not decoded.
Joe Tsai41134b72020-10-19 20:51:03 -07005402func consumeBytesNoZero(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005403 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005404 return out, errUnknown
Damien Neil8003f082019-08-02 15:13:00 -07005405 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005406 v, n := protowire.ConsumeBytes(b)
Damien Neil8003f082019-08-02 15:13:00 -07005407 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005408 return out, errDecode
Damien Neil8003f082019-08-02 15:13:00 -07005409 }
5410 *p.Bytes() = append(([]byte)(nil), v...)
Damien Neilf0831e82020-01-21 14:25:12 -08005411 out.n = n
5412 return out, nil
Damien Neil8003f082019-08-02 15:13:00 -07005413}
5414
Damien Neilc37adef2019-04-01 13:49:56 -07005415var coderBytesNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07005416 size: sizeBytesNoZero,
5417 marshal: appendBytesNoZero,
Damien Neil8003f082019-08-02 15:13:00 -07005418 unmarshal: consumeBytesNoZero,
Damien Neile8e88752020-02-11 11:25:16 -08005419 merge: mergeBytesNoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07005420}
5421
Joe Tsaic51e2e02019-07-13 00:44:41 -07005422// appendBytesNoZeroValidateUTF8 wire encodes a []byte pointer as a Bytes.
5423// The zero value is not encoded.
Joe Tsai41134b72020-10-19 20:51:03 -07005424func appendBytesNoZeroValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07005425 v := *p.Bytes()
5426 if len(v) == 0 {
5427 return b, nil
5428 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005429 b = protowire.AppendVarint(b, f.wiretag)
5430 b = protowire.AppendBytes(b, v)
Joe Tsaic51e2e02019-07-13 00:44:41 -07005431 if !utf8.Valid(v) {
5432 return b, errInvalidUTF8{}
5433 }
5434 return b, nil
5435}
5436
Damien Neil8003f082019-08-02 15:13:00 -07005437// consumeBytesNoZeroValidateUTF8 wire decodes a []byte pointer as a Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005438func consumeBytesNoZeroValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005439 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005440 return out, errUnknown
Damien Neil8003f082019-08-02 15:13:00 -07005441 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005442 v, n := protowire.ConsumeBytes(b)
Damien Neil8003f082019-08-02 15:13:00 -07005443 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005444 return out, errDecode
Damien Neil8003f082019-08-02 15:13:00 -07005445 }
5446 if !utf8.Valid(v) {
Damien Neilf0831e82020-01-21 14:25:12 -08005447 return out, errInvalidUTF8{}
Damien Neil8003f082019-08-02 15:13:00 -07005448 }
5449 *p.Bytes() = append(([]byte)(nil), v...)
Damien Neilf0831e82020-01-21 14:25:12 -08005450 out.n = n
5451 return out, nil
Damien Neil8003f082019-08-02 15:13:00 -07005452}
5453
Joe Tsaic51e2e02019-07-13 00:44:41 -07005454var coderBytesNoZeroValidateUTF8 = pointerCoderFuncs{
5455 size: sizeBytesNoZero,
5456 marshal: appendBytesNoZeroValidateUTF8,
Damien Neil8003f082019-08-02 15:13:00 -07005457 unmarshal: consumeBytesNoZeroValidateUTF8,
Damien Neile8e88752020-02-11 11:25:16 -08005458 merge: mergeBytesNoZero,
Joe Tsaic51e2e02019-07-13 00:44:41 -07005459}
5460
Damien Neilc37adef2019-04-01 13:49:56 -07005461// sizeBytesSlice returns the size of wire encoding a [][]byte pointer as a repeated Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005462func sizeBytesSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
Damien Neilc37adef2019-04-01 13:49:56 -07005463 s := *p.BytesSlice()
5464 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08005465 size += f.tagsize + protowire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07005466 }
5467 return size
5468}
5469
5470// appendBytesSlice encodes a [][]byte pointer as a repeated Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005471func appendBytesSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07005472 s := *p.BytesSlice()
5473 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08005474 b = protowire.AppendVarint(b, f.wiretag)
5475 b = protowire.AppendBytes(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07005476 }
5477 return b, nil
5478}
5479
Damien Neile91877d2019-06-27 10:54:42 -07005480// consumeBytesSlice wire decodes a [][]byte pointer as a repeated Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005481func consumeBytesSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Damien Neile91877d2019-06-27 10:54:42 -07005482 sp := p.BytesSlice()
Joe Tsaicd108d02020-02-14 18:08:02 -08005483 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005484 return out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07005485 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005486 v, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07005487 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005488 return out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07005489 }
Damien Neil8003f082019-08-02 15:13:00 -07005490 *sp = append(*sp, append(emptyBuf[:], v...))
Damien Neilf0831e82020-01-21 14:25:12 -08005491 out.n = n
5492 return out, nil
Damien Neile91877d2019-06-27 10:54:42 -07005493}
5494
Damien Neilc37adef2019-04-01 13:49:56 -07005495var coderBytesSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07005496 size: sizeBytesSlice,
5497 marshal: appendBytesSlice,
5498 unmarshal: consumeBytesSlice,
Damien Neile8e88752020-02-11 11:25:16 -08005499 merge: mergeBytesSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07005500}
5501
Joe Tsaic51e2e02019-07-13 00:44:41 -07005502// appendBytesSliceValidateUTF8 encodes a [][]byte pointer as a repeated Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005503func appendBytesSliceValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07005504 s := *p.BytesSlice()
5505 for _, v := range s {
Joe Tsaicd108d02020-02-14 18:08:02 -08005506 b = protowire.AppendVarint(b, f.wiretag)
5507 b = protowire.AppendBytes(b, v)
Joe Tsaic51e2e02019-07-13 00:44:41 -07005508 if !utf8.Valid(v) {
5509 return b, errInvalidUTF8{}
5510 }
5511 }
5512 return b, nil
5513}
5514
5515// consumeBytesSliceValidateUTF8 wire decodes a [][]byte pointer as a repeated Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005516func consumeBytesSliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005517 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005518 return out, errUnknown
Joe Tsaic51e2e02019-07-13 00:44:41 -07005519 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005520 v, n := protowire.ConsumeBytes(b)
Joe Tsaic51e2e02019-07-13 00:44:41 -07005521 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005522 return out, errDecode
Joe Tsaic51e2e02019-07-13 00:44:41 -07005523 }
5524 if !utf8.Valid(v) {
Damien Neilf0831e82020-01-21 14:25:12 -08005525 return out, errInvalidUTF8{}
Joe Tsaic51e2e02019-07-13 00:44:41 -07005526 }
Joe Tsai44626bc2020-10-19 20:32:27 -07005527 sp := p.BytesSlice()
Damien Neil8003f082019-08-02 15:13:00 -07005528 *sp = append(*sp, append(emptyBuf[:], v...))
Damien Neilf0831e82020-01-21 14:25:12 -08005529 out.n = n
5530 return out, nil
Joe Tsaic51e2e02019-07-13 00:44:41 -07005531}
5532
5533var coderBytesSliceValidateUTF8 = pointerCoderFuncs{
5534 size: sizeBytesSlice,
5535 marshal: appendBytesSliceValidateUTF8,
5536 unmarshal: consumeBytesSliceValidateUTF8,
Damien Neile8e88752020-02-11 11:25:16 -08005537 merge: mergeBytesSlice,
Joe Tsaic51e2e02019-07-13 00:44:41 -07005538}
5539
Damien Neil68b81c32019-08-22 11:41:32 -07005540// sizeBytesValue returns the size of wire encoding a []byte value as a Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005541func sizeBytesValue(v protoreflect.Value, tagsize int, opts marshalOptions) int {
Joe Tsaicd108d02020-02-14 18:08:02 -08005542 return tagsize + protowire.SizeBytes(len(v.Bytes()))
Damien Neilc37adef2019-04-01 13:49:56 -07005543}
5544
Damien Neil68b81c32019-08-22 11:41:32 -07005545// appendBytesValue encodes a []byte value as a Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005546func appendBytesValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005547 b = protowire.AppendVarint(b, wiretag)
5548 b = protowire.AppendBytes(b, v.Bytes())
Damien Neilc37adef2019-04-01 13:49:56 -07005549 return b, nil
5550}
5551
Damien Neil68b81c32019-08-22 11:41:32 -07005552// consumeBytesValue decodes a []byte value as a Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005553func consumeBytesValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Joe Tsaicd108d02020-02-14 18:08:02 -08005554 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005555 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07005556 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005557 v, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07005558 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005559 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07005560 }
Damien Neilf0831e82020-01-21 14:25:12 -08005561 out.n = n
5562 return protoreflect.ValueOfBytes(append(emptyBuf[:], v...)), out, nil
Damien Neile91877d2019-06-27 10:54:42 -07005563}
5564
Damien Neil68b81c32019-08-22 11:41:32 -07005565var coderBytesValue = valueCoderFuncs{
5566 size: sizeBytesValue,
5567 marshal: appendBytesValue,
5568 unmarshal: consumeBytesValue,
Damien Neile8e88752020-02-11 11:25:16 -08005569 merge: mergeBytesValue,
Damien Neilc37adef2019-04-01 13:49:56 -07005570}
5571
Damien Neil68b81c32019-08-22 11:41:32 -07005572// sizeBytesSliceValue returns the size of wire encoding a [][]byte value as a repeated Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005573func sizeBytesSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) {
Damien Neil68b81c32019-08-22 11:41:32 -07005574 list := listv.List()
5575 for i, llen := 0, list.Len(); i < llen; i++ {
5576 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08005577 size += tagsize + protowire.SizeBytes(len(v.Bytes()))
Damien Neilc37adef2019-04-01 13:49:56 -07005578 }
5579 return size
5580}
5581
Damien Neil68b81c32019-08-22 11:41:32 -07005582// appendBytesSliceValue encodes a [][]byte value as a repeated Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005583func appendBytesSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) {
Damien Neil68b81c32019-08-22 11:41:32 -07005584 list := listv.List()
5585 for i, llen := 0, list.Len(); i < llen; i++ {
5586 v := list.Get(i)
Joe Tsaicd108d02020-02-14 18:08:02 -08005587 b = protowire.AppendVarint(b, wiretag)
5588 b = protowire.AppendBytes(b, v.Bytes())
Damien Neilc37adef2019-04-01 13:49:56 -07005589 }
5590 return b, nil
5591}
5592
Damien Neil68b81c32019-08-22 11:41:32 -07005593// consumeBytesSliceValue wire decodes a [][]byte value as a repeated Bytes.
Joe Tsai41134b72020-10-19 20:51:03 -07005594func consumeBytesSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) {
Damien Neil68b81c32019-08-22 11:41:32 -07005595 list := listv.List()
Joe Tsaicd108d02020-02-14 18:08:02 -08005596 if wtyp != protowire.BytesType {
Damien Neilf0831e82020-01-21 14:25:12 -08005597 return protoreflect.Value{}, out, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07005598 }
Joe Tsaicd108d02020-02-14 18:08:02 -08005599 v, n := protowire.ConsumeBytes(b)
Damien Neile91877d2019-06-27 10:54:42 -07005600 if n < 0 {
Damien Neilb5523e32020-07-22 09:10:20 -07005601 return protoreflect.Value{}, out, errDecode
Damien Neile91877d2019-06-27 10:54:42 -07005602 }
Damien Neil5366f822019-12-05 14:54:35 -08005603 list.Append(protoreflect.ValueOfBytes(append(emptyBuf[:], v...)))
Damien Neilf0831e82020-01-21 14:25:12 -08005604 out.n = n
5605 return listv, out, nil
Damien Neile91877d2019-06-27 10:54:42 -07005606}
5607
Damien Neil68b81c32019-08-22 11:41:32 -07005608var coderBytesSliceValue = valueCoderFuncs{
5609 size: sizeBytesSliceValue,
5610 marshal: appendBytesSliceValue,
5611 unmarshal: consumeBytesSliceValue,
Damien Neile8e88752020-02-11 11:25:16 -08005612 merge: mergeBytesListValue,
Damien Neilc37adef2019-04-01 13:49:56 -07005613}
5614
Damien Neil8003f082019-08-02 15:13:00 -07005615// We append to an empty array rather than a nil []byte to get non-nil zero-length byte slices.
5616var emptyBuf [0]byte
5617
Joe Tsaicd108d02020-02-14 18:08:02 -08005618var wireTypes = map[protoreflect.Kind]protowire.Type{
5619 protoreflect.BoolKind: protowire.VarintType,
5620 protoreflect.EnumKind: protowire.VarintType,
5621 protoreflect.Int32Kind: protowire.VarintType,
5622 protoreflect.Sint32Kind: protowire.VarintType,
5623 protoreflect.Uint32Kind: protowire.VarintType,
5624 protoreflect.Int64Kind: protowire.VarintType,
5625 protoreflect.Sint64Kind: protowire.VarintType,
5626 protoreflect.Uint64Kind: protowire.VarintType,
5627 protoreflect.Sfixed32Kind: protowire.Fixed32Type,
5628 protoreflect.Fixed32Kind: protowire.Fixed32Type,
5629 protoreflect.FloatKind: protowire.Fixed32Type,
5630 protoreflect.Sfixed64Kind: protowire.Fixed64Type,
5631 protoreflect.Fixed64Kind: protowire.Fixed64Type,
5632 protoreflect.DoubleKind: protowire.Fixed64Type,
5633 protoreflect.StringKind: protowire.BytesType,
5634 protoreflect.BytesKind: protowire.BytesType,
5635 protoreflect.MessageKind: protowire.BytesType,
5636 protoreflect.GroupKind: protowire.StartGroupType,
Damien Neilc37adef2019-04-01 13:49:56 -07005637}