blob: 060d5bd8d52761f874f30f90f197aceb0caa07ac [file] [log] [blame]
Damien Neilc37adef2019-04-01 13:49:56 -07001// Copyright 2018 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style.
3// 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
13 "google.golang.org/protobuf/internal/encoding/wire"
14 "google.golang.org/protobuf/reflect/protoreflect"
15)
16
17// sizeBool returns the size of wire encoding a bool pointer as a Bool.
18func sizeBool(p pointer, tagsize int, _ marshalOptions) (size int) {
19 v := *p.Bool()
20 return tagsize + wire.SizeVarint(wire.EncodeBool(v))
21}
22
23// appendBool wire encodes a bool pointer as a Bool.
24func appendBool(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
25 v := *p.Bool()
26 b = wire.AppendVarint(b, wiretag)
27 b = wire.AppendVarint(b, wire.EncodeBool(v))
28 return b, nil
29}
30
Damien Neile91877d2019-06-27 10:54:42 -070031// consumeBool wire decodes a bool pointer as a Bool.
32func consumeBool(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
33 if wtyp != wire.VarintType {
34 return 0, errUnknown
35 }
36 v, n := wire.ConsumeVarint(b)
37 if n < 0 {
38 return 0, wire.ParseError(n)
39 }
40 *p.Bool() = wire.DecodeBool(v)
41 return n, nil
42}
43
Damien Neilc37adef2019-04-01 13:49:56 -070044var coderBool = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -070045 size: sizeBool,
46 marshal: appendBool,
47 unmarshal: consumeBool,
Damien Neilc37adef2019-04-01 13:49:56 -070048}
49
Joe Tsaic51e2e02019-07-13 00:44:41 -070050// sizeBoolNoZero returns the size of wire encoding a bool pointer as a Bool.
Damien Neilc37adef2019-04-01 13:49:56 -070051// The zero value is not encoded.
52func sizeBoolNoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
53 v := *p.Bool()
54 if v == false {
55 return 0
56 }
57 return tagsize + wire.SizeVarint(wire.EncodeBool(v))
58}
59
Joe Tsaic51e2e02019-07-13 00:44:41 -070060// appendBoolNoZero wire encodes a bool pointer as a Bool.
Damien Neilc37adef2019-04-01 13:49:56 -070061// The zero value is not encoded.
62func appendBoolNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
63 v := *p.Bool()
64 if v == false {
65 return b, nil
66 }
67 b = wire.AppendVarint(b, wiretag)
68 b = wire.AppendVarint(b, wire.EncodeBool(v))
69 return b, nil
70}
71
72var coderBoolNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -070073 size: sizeBoolNoZero,
74 marshal: appendBoolNoZero,
75 unmarshal: consumeBool,
Damien Neilc37adef2019-04-01 13:49:56 -070076}
77
78// sizeBoolPtr returns the size of wire encoding a *bool pointer as a Bool.
79// It panics if the pointer is nil.
80func sizeBoolPtr(p pointer, tagsize int, _ marshalOptions) (size int) {
81 v := **p.BoolPtr()
82 return tagsize + wire.SizeVarint(wire.EncodeBool(v))
83}
84
Damien Neile91877d2019-06-27 10:54:42 -070085// appendBoolPtr wire encodes a *bool pointer as a Bool.
Damien Neilc37adef2019-04-01 13:49:56 -070086// It panics if the pointer is nil.
87func appendBoolPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
88 v := **p.BoolPtr()
89 b = wire.AppendVarint(b, wiretag)
90 b = wire.AppendVarint(b, wire.EncodeBool(v))
91 return b, nil
92}
93
Damien Neile91877d2019-06-27 10:54:42 -070094// consumeBoolPtr wire decodes a *bool pointer as a Bool.
95func consumeBoolPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
96 if wtyp != wire.VarintType {
97 return 0, errUnknown
98 }
99 v, n := wire.ConsumeVarint(b)
100 if n < 0 {
101 return 0, wire.ParseError(n)
102 }
103 vp := p.BoolPtr()
104 if *vp == nil {
105 *vp = new(bool)
106 }
107 **vp = wire.DecodeBool(v)
108 return n, nil
109}
110
Damien Neilc37adef2019-04-01 13:49:56 -0700111var coderBoolPtr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700112 size: sizeBoolPtr,
113 marshal: appendBoolPtr,
114 unmarshal: consumeBoolPtr,
Damien Neilc37adef2019-04-01 13:49:56 -0700115}
116
117// sizeBoolSlice returns the size of wire encoding a []bool pointer as a repeated Bool.
118func sizeBoolSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
119 s := *p.BoolSlice()
120 for _, v := range s {
121 size += tagsize + wire.SizeVarint(wire.EncodeBool(v))
122 }
123 return size
124}
125
126// appendBoolSlice encodes a []bool pointer as a repeated Bool.
127func appendBoolSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
128 s := *p.BoolSlice()
129 for _, v := range s {
130 b = wire.AppendVarint(b, wiretag)
131 b = wire.AppendVarint(b, wire.EncodeBool(v))
132 }
133 return b, nil
134}
135
Damien Neile91877d2019-06-27 10:54:42 -0700136// consumeBoolSlice wire decodes a []bool pointer as a repeated Bool.
137func consumeBoolSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
138 sp := p.BoolSlice()
139 if wtyp == wire.BytesType {
140 s := *sp
141 b, n = wire.ConsumeBytes(b)
142 if n < 0 {
143 return 0, wire.ParseError(n)
144 }
145 for len(b) > 0 {
146 v, n := wire.ConsumeVarint(b)
147 if n < 0 {
148 return 0, wire.ParseError(n)
149 }
150 s = append(s, wire.DecodeBool(v))
151 b = b[n:]
152 }
153 *sp = s
154 return n, nil
155 }
156 if wtyp != wire.VarintType {
157 return 0, errUnknown
158 }
159 v, n := wire.ConsumeVarint(b)
160 if n < 0 {
161 return 0, wire.ParseError(n)
162 }
163 *sp = append(*sp, wire.DecodeBool(v))
164 return n, nil
165}
166
Damien Neilc37adef2019-04-01 13:49:56 -0700167var coderBoolSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700168 size: sizeBoolSlice,
169 marshal: appendBoolSlice,
170 unmarshal: consumeBoolSlice,
Damien Neilc37adef2019-04-01 13:49:56 -0700171}
172
173// sizeBoolPackedSlice returns the size of wire encoding a []bool pointer as a packed repeated Bool.
174func sizeBoolPackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
175 s := *p.BoolSlice()
176 if len(s) == 0 {
177 return 0
178 }
179 n := 0
180 for _, v := range s {
181 n += wire.SizeVarint(wire.EncodeBool(v))
182 }
183 return tagsize + wire.SizeBytes(n)
184}
185
186// appendBoolPackedSlice encodes a []bool pointer as a packed repeated Bool.
187func appendBoolPackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
188 s := *p.BoolSlice()
189 if len(s) == 0 {
190 return b, nil
191 }
192 b = wire.AppendVarint(b, wiretag)
193 n := 0
194 for _, v := range s {
195 n += wire.SizeVarint(wire.EncodeBool(v))
196 }
197 b = wire.AppendVarint(b, uint64(n))
198 for _, v := range s {
199 b = wire.AppendVarint(b, wire.EncodeBool(v))
200 }
201 return b, nil
202}
203
204var coderBoolPackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700205 size: sizeBoolPackedSlice,
206 marshal: appendBoolPackedSlice,
207 unmarshal: consumeBoolSlice,
Damien Neilc37adef2019-04-01 13:49:56 -0700208}
209
Damien Neil68b81c32019-08-22 11:41:32 -0700210// sizeBoolValue returns the size of wire encoding a bool value as a Bool.
211func sizeBoolValue(v protoreflect.Value, tagsize int, _ marshalOptions) int {
212 return tagsize + wire.SizeVarint(wire.EncodeBool(v.Bool()))
Damien Neilc37adef2019-04-01 13:49:56 -0700213}
214
Damien Neil68b81c32019-08-22 11:41:32 -0700215// appendBoolValue encodes a bool value as a Bool.
216func appendBoolValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700217 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -0700218 b = wire.AppendVarint(b, wire.EncodeBool(v.Bool()))
Damien Neilc37adef2019-04-01 13:49:56 -0700219 return b, nil
220}
221
Damien Neil68b81c32019-08-22 11:41:32 -0700222// consumeBoolValue decodes a bool value as a Bool.
223func consumeBoolValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -0700224 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -0700225 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700226 }
227 v, n := wire.ConsumeVarint(b)
228 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700229 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700230 }
Damien Neil68b81c32019-08-22 11:41:32 -0700231 return protoreflect.ValueOfBool(wire.DecodeBool(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -0700232}
233
Damien Neil68b81c32019-08-22 11:41:32 -0700234var coderBoolValue = valueCoderFuncs{
235 size: sizeBoolValue,
236 marshal: appendBoolValue,
237 unmarshal: consumeBoolValue,
Damien Neilc37adef2019-04-01 13:49:56 -0700238}
239
Damien Neil68b81c32019-08-22 11:41:32 -0700240// sizeBoolSliceValue returns the size of wire encoding a []bool value as a repeated Bool.
241func sizeBoolSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
242 list := listv.List()
243 for i, llen := 0, list.Len(); i < llen; i++ {
244 v := list.Get(i)
245 size += tagsize + wire.SizeVarint(wire.EncodeBool(v.Bool()))
Damien Neilc37adef2019-04-01 13:49:56 -0700246 }
247 return size
248}
249
Damien Neil68b81c32019-08-22 11:41:32 -0700250// appendBoolSliceValue encodes a []bool value as a repeated Bool.
251func appendBoolSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
252 list := listv.List()
253 for i, llen := 0, list.Len(); i < llen; i++ {
254 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -0700255 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -0700256 b = wire.AppendVarint(b, wire.EncodeBool(v.Bool()))
Damien Neilc37adef2019-04-01 13:49:56 -0700257 }
258 return b, nil
259}
260
Damien Neil68b81c32019-08-22 11:41:32 -0700261// consumeBoolSliceValue wire decodes a []bool value as a repeated Bool.
262func consumeBoolSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
263 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -0700264 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -0700265 b, n = wire.ConsumeBytes(b)
266 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700267 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700268 }
269 for len(b) > 0 {
270 v, n := wire.ConsumeVarint(b)
271 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700272 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700273 }
Damien Neil68b81c32019-08-22 11:41:32 -0700274 list.Append(protoreflect.ValueOfBool(wire.DecodeBool(v)))
Damien Neile91877d2019-06-27 10:54:42 -0700275 b = b[n:]
276 }
Damien Neil68b81c32019-08-22 11:41:32 -0700277 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -0700278 }
279 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -0700280 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700281 }
282 v, n := wire.ConsumeVarint(b)
283 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700284 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700285 }
Damien Neil68b81c32019-08-22 11:41:32 -0700286 list.Append(protoreflect.ValueOfBool(wire.DecodeBool(v)))
287 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -0700288}
289
Damien Neil68b81c32019-08-22 11:41:32 -0700290var coderBoolSliceValue = valueCoderFuncs{
291 size: sizeBoolSliceValue,
292 marshal: appendBoolSliceValue,
293 unmarshal: consumeBoolSliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -0700294}
295
Damien Neil68b81c32019-08-22 11:41:32 -0700296// sizeBoolPackedSliceValue returns the size of wire encoding a []bool value as a packed repeated Bool.
297func sizeBoolPackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
298 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -0800299 llen := list.Len()
300 if llen == 0 {
301 return 0
302 }
Damien Neil7492a092019-07-10 15:23:29 -0700303 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -0800304 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -0700305 v := list.Get(i)
306 n += wire.SizeVarint(wire.EncodeBool(v.Bool()))
Damien Neil7492a092019-07-10 15:23:29 -0700307 }
308 return tagsize + wire.SizeBytes(n)
309}
310
Damien Neil68b81c32019-08-22 11:41:32 -0700311// appendBoolPackedSliceValue encodes a []bool value as a packed repeated Bool.
312func appendBoolPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
313 list := listv.List()
314 llen := list.Len()
315 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -0700316 return b, nil
317 }
318 b = wire.AppendVarint(b, wiretag)
319 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -0700320 for i := 0; i < llen; i++ {
321 v := list.Get(i)
322 n += wire.SizeVarint(wire.EncodeBool(v.Bool()))
Damien Neil7492a092019-07-10 15:23:29 -0700323 }
324 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -0700325 for i := 0; i < llen; i++ {
326 v := list.Get(i)
327 b = wire.AppendVarint(b, wire.EncodeBool(v.Bool()))
Damien Neil7492a092019-07-10 15:23:29 -0700328 }
329 return b, nil
330}
331
Damien Neil68b81c32019-08-22 11:41:32 -0700332var coderBoolPackedSliceValue = valueCoderFuncs{
333 size: sizeBoolPackedSliceValue,
334 marshal: appendBoolPackedSliceValue,
335 unmarshal: consumeBoolSliceValue,
336}
337
338// sizeEnumValue returns the size of wire encoding a value as a Enum.
339func sizeEnumValue(v protoreflect.Value, tagsize int, _ marshalOptions) int {
340 return tagsize + wire.SizeVarint(uint64(v.Enum()))
341}
342
343// appendEnumValue encodes a value as a Enum.
344func appendEnumValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
345 b = wire.AppendVarint(b, wiretag)
346 b = wire.AppendVarint(b, uint64(v.Enum()))
347 return b, nil
348}
349
350// consumeEnumValue decodes a value as a Enum.
351func consumeEnumValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
352 if wtyp != wire.VarintType {
353 return protoreflect.Value{}, 0, errUnknown
354 }
355 v, n := wire.ConsumeVarint(b)
356 if n < 0 {
357 return protoreflect.Value{}, 0, wire.ParseError(n)
358 }
359 return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), n, nil
360}
361
362var coderEnumValue = valueCoderFuncs{
363 size: sizeEnumValue,
364 marshal: appendEnumValue,
365 unmarshal: consumeEnumValue,
366}
367
368// sizeEnumSliceValue returns the size of wire encoding a [] value as a repeated Enum.
369func sizeEnumSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
370 list := listv.List()
371 for i, llen := 0, list.Len(); i < llen; i++ {
372 v := list.Get(i)
373 size += tagsize + wire.SizeVarint(uint64(v.Enum()))
374 }
375 return size
376}
377
378// appendEnumSliceValue encodes a [] value as a repeated Enum.
379func appendEnumSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
380 list := listv.List()
381 for i, llen := 0, list.Len(); i < llen; i++ {
382 v := list.Get(i)
383 b = wire.AppendVarint(b, wiretag)
384 b = wire.AppendVarint(b, uint64(v.Enum()))
385 }
386 return b, nil
387}
388
389// consumeEnumSliceValue wire decodes a [] value as a repeated Enum.
390func consumeEnumSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
391 list := listv.List()
392 if wtyp == wire.BytesType {
393 b, n = wire.ConsumeBytes(b)
394 if n < 0 {
395 return protoreflect.Value{}, 0, wire.ParseError(n)
396 }
397 for len(b) > 0 {
398 v, n := wire.ConsumeVarint(b)
399 if n < 0 {
400 return protoreflect.Value{}, 0, wire.ParseError(n)
401 }
402 list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
403 b = b[n:]
404 }
405 return listv, n, nil
406 }
407 if wtyp != wire.VarintType {
408 return protoreflect.Value{}, 0, errUnknown
409 }
410 v, n := wire.ConsumeVarint(b)
411 if n < 0 {
412 return protoreflect.Value{}, 0, wire.ParseError(n)
413 }
414 list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
415 return listv, n, nil
416}
417
418var coderEnumSliceValue = valueCoderFuncs{
419 size: sizeEnumSliceValue,
420 marshal: appendEnumSliceValue,
421 unmarshal: consumeEnumSliceValue,
422}
423
424// sizeEnumPackedSliceValue returns the size of wire encoding a [] value as a packed repeated Enum.
425func sizeEnumPackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
426 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -0800427 llen := list.Len()
428 if llen == 0 {
429 return 0
430 }
Damien Neil68b81c32019-08-22 11:41:32 -0700431 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -0800432 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -0700433 v := list.Get(i)
434 n += wire.SizeVarint(uint64(v.Enum()))
435 }
436 return tagsize + wire.SizeBytes(n)
437}
438
439// appendEnumPackedSliceValue encodes a [] value as a packed repeated Enum.
440func appendEnumPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
441 list := listv.List()
442 llen := list.Len()
443 if llen == 0 {
444 return b, nil
445 }
446 b = wire.AppendVarint(b, wiretag)
447 n := 0
448 for i := 0; i < llen; i++ {
449 v := list.Get(i)
450 n += wire.SizeVarint(uint64(v.Enum()))
451 }
452 b = wire.AppendVarint(b, uint64(n))
453 for i := 0; i < llen; i++ {
454 v := list.Get(i)
455 b = wire.AppendVarint(b, uint64(v.Enum()))
456 }
457 return b, nil
458}
459
460var coderEnumPackedSliceValue = valueCoderFuncs{
461 size: sizeEnumPackedSliceValue,
462 marshal: appendEnumPackedSliceValue,
463 unmarshal: consumeEnumSliceValue,
Damien Neil7492a092019-07-10 15:23:29 -0700464}
465
Damien Neilc37adef2019-04-01 13:49:56 -0700466// sizeInt32 returns the size of wire encoding a int32 pointer as a Int32.
467func sizeInt32(p pointer, tagsize int, _ marshalOptions) (size int) {
468 v := *p.Int32()
469 return tagsize + wire.SizeVarint(uint64(v))
470}
471
472// appendInt32 wire encodes a int32 pointer as a Int32.
473func appendInt32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
474 v := *p.Int32()
475 b = wire.AppendVarint(b, wiretag)
476 b = wire.AppendVarint(b, uint64(v))
477 return b, nil
478}
479
Damien Neile91877d2019-06-27 10:54:42 -0700480// consumeInt32 wire decodes a int32 pointer as a Int32.
481func consumeInt32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
482 if wtyp != wire.VarintType {
483 return 0, errUnknown
484 }
485 v, n := wire.ConsumeVarint(b)
486 if n < 0 {
487 return 0, wire.ParseError(n)
488 }
489 *p.Int32() = int32(v)
490 return n, nil
491}
492
Damien Neilc37adef2019-04-01 13:49:56 -0700493var coderInt32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700494 size: sizeInt32,
495 marshal: appendInt32,
496 unmarshal: consumeInt32,
Damien Neilc37adef2019-04-01 13:49:56 -0700497}
498
Joe Tsaic51e2e02019-07-13 00:44:41 -0700499// sizeInt32NoZero returns the size of wire encoding a int32 pointer as a Int32.
Damien Neilc37adef2019-04-01 13:49:56 -0700500// The zero value is not encoded.
501func sizeInt32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
502 v := *p.Int32()
503 if v == 0 {
504 return 0
505 }
506 return tagsize + wire.SizeVarint(uint64(v))
507}
508
Joe Tsaic51e2e02019-07-13 00:44:41 -0700509// appendInt32NoZero wire encodes a int32 pointer as a Int32.
Damien Neilc37adef2019-04-01 13:49:56 -0700510// The zero value is not encoded.
511func appendInt32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
512 v := *p.Int32()
513 if v == 0 {
514 return b, nil
515 }
516 b = wire.AppendVarint(b, wiretag)
517 b = wire.AppendVarint(b, uint64(v))
518 return b, nil
519}
520
521var coderInt32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700522 size: sizeInt32NoZero,
523 marshal: appendInt32NoZero,
524 unmarshal: consumeInt32,
Damien Neilc37adef2019-04-01 13:49:56 -0700525}
526
527// sizeInt32Ptr returns the size of wire encoding a *int32 pointer as a Int32.
528// It panics if the pointer is nil.
529func sizeInt32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
530 v := **p.Int32Ptr()
531 return tagsize + wire.SizeVarint(uint64(v))
532}
533
Damien Neile91877d2019-06-27 10:54:42 -0700534// appendInt32Ptr wire encodes a *int32 pointer as a Int32.
Damien Neilc37adef2019-04-01 13:49:56 -0700535// It panics if the pointer is nil.
536func appendInt32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
537 v := **p.Int32Ptr()
538 b = wire.AppendVarint(b, wiretag)
539 b = wire.AppendVarint(b, uint64(v))
540 return b, nil
541}
542
Damien Neile91877d2019-06-27 10:54:42 -0700543// consumeInt32Ptr wire decodes a *int32 pointer as a Int32.
544func consumeInt32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
545 if wtyp != wire.VarintType {
546 return 0, errUnknown
547 }
548 v, n := wire.ConsumeVarint(b)
549 if n < 0 {
550 return 0, wire.ParseError(n)
551 }
552 vp := p.Int32Ptr()
553 if *vp == nil {
554 *vp = new(int32)
555 }
556 **vp = int32(v)
557 return n, nil
558}
559
Damien Neilc37adef2019-04-01 13:49:56 -0700560var coderInt32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700561 size: sizeInt32Ptr,
562 marshal: appendInt32Ptr,
563 unmarshal: consumeInt32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -0700564}
565
566// sizeInt32Slice returns the size of wire encoding a []int32 pointer as a repeated Int32.
567func sizeInt32Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
568 s := *p.Int32Slice()
569 for _, v := range s {
570 size += tagsize + wire.SizeVarint(uint64(v))
571 }
572 return size
573}
574
575// appendInt32Slice encodes a []int32 pointer as a repeated Int32.
576func appendInt32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
577 s := *p.Int32Slice()
578 for _, v := range s {
579 b = wire.AppendVarint(b, wiretag)
580 b = wire.AppendVarint(b, uint64(v))
581 }
582 return b, nil
583}
584
Damien Neile91877d2019-06-27 10:54:42 -0700585// consumeInt32Slice wire decodes a []int32 pointer as a repeated Int32.
586func consumeInt32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
587 sp := p.Int32Slice()
588 if wtyp == wire.BytesType {
589 s := *sp
590 b, n = wire.ConsumeBytes(b)
591 if n < 0 {
592 return 0, wire.ParseError(n)
593 }
594 for len(b) > 0 {
595 v, n := wire.ConsumeVarint(b)
596 if n < 0 {
597 return 0, wire.ParseError(n)
598 }
599 s = append(s, int32(v))
600 b = b[n:]
601 }
602 *sp = s
603 return n, nil
604 }
605 if wtyp != wire.VarintType {
606 return 0, errUnknown
607 }
608 v, n := wire.ConsumeVarint(b)
609 if n < 0 {
610 return 0, wire.ParseError(n)
611 }
612 *sp = append(*sp, int32(v))
613 return n, nil
614}
615
Damien Neilc37adef2019-04-01 13:49:56 -0700616var coderInt32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700617 size: sizeInt32Slice,
618 marshal: appendInt32Slice,
619 unmarshal: consumeInt32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -0700620}
621
622// sizeInt32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Int32.
623func sizeInt32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
624 s := *p.Int32Slice()
625 if len(s) == 0 {
626 return 0
627 }
628 n := 0
629 for _, v := range s {
630 n += wire.SizeVarint(uint64(v))
631 }
632 return tagsize + wire.SizeBytes(n)
633}
634
635// appendInt32PackedSlice encodes a []int32 pointer as a packed repeated Int32.
636func appendInt32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
637 s := *p.Int32Slice()
638 if len(s) == 0 {
639 return b, nil
640 }
641 b = wire.AppendVarint(b, wiretag)
642 n := 0
643 for _, v := range s {
644 n += wire.SizeVarint(uint64(v))
645 }
646 b = wire.AppendVarint(b, uint64(n))
647 for _, v := range s {
648 b = wire.AppendVarint(b, uint64(v))
649 }
650 return b, nil
651}
652
653var coderInt32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700654 size: sizeInt32PackedSlice,
655 marshal: appendInt32PackedSlice,
656 unmarshal: consumeInt32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -0700657}
658
Damien Neil68b81c32019-08-22 11:41:32 -0700659// sizeInt32Value returns the size of wire encoding a int32 value as a Int32.
660func sizeInt32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
661 return tagsize + wire.SizeVarint(uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700662}
663
Damien Neil68b81c32019-08-22 11:41:32 -0700664// appendInt32Value encodes a int32 value as a Int32.
665func appendInt32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700666 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -0700667 b = wire.AppendVarint(b, uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700668 return b, nil
669}
670
Damien Neil68b81c32019-08-22 11:41:32 -0700671// consumeInt32Value decodes a int32 value as a Int32.
672func consumeInt32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -0700673 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -0700674 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700675 }
676 v, n := wire.ConsumeVarint(b)
677 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700678 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700679 }
Damien Neil68b81c32019-08-22 11:41:32 -0700680 return protoreflect.ValueOfInt32(int32(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -0700681}
682
Damien Neil68b81c32019-08-22 11:41:32 -0700683var coderInt32Value = valueCoderFuncs{
684 size: sizeInt32Value,
685 marshal: appendInt32Value,
686 unmarshal: consumeInt32Value,
Damien Neilc37adef2019-04-01 13:49:56 -0700687}
688
Damien Neil68b81c32019-08-22 11:41:32 -0700689// sizeInt32SliceValue returns the size of wire encoding a []int32 value as a repeated Int32.
690func sizeInt32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
691 list := listv.List()
692 for i, llen := 0, list.Len(); i < llen; i++ {
693 v := list.Get(i)
694 size += tagsize + wire.SizeVarint(uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700695 }
696 return size
697}
698
Damien Neil68b81c32019-08-22 11:41:32 -0700699// appendInt32SliceValue encodes a []int32 value as a repeated Int32.
700func appendInt32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
701 list := listv.List()
702 for i, llen := 0, list.Len(); i < llen; i++ {
703 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -0700704 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -0700705 b = wire.AppendVarint(b, uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700706 }
707 return b, nil
708}
709
Damien Neil68b81c32019-08-22 11:41:32 -0700710// consumeInt32SliceValue wire decodes a []int32 value as a repeated Int32.
711func consumeInt32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
712 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -0700713 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -0700714 b, n = wire.ConsumeBytes(b)
715 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700716 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700717 }
718 for len(b) > 0 {
719 v, n := wire.ConsumeVarint(b)
720 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700721 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700722 }
Damien Neil68b81c32019-08-22 11:41:32 -0700723 list.Append(protoreflect.ValueOfInt32(int32(v)))
Damien Neile91877d2019-06-27 10:54:42 -0700724 b = b[n:]
725 }
Damien Neil68b81c32019-08-22 11:41:32 -0700726 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -0700727 }
728 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -0700729 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700730 }
731 v, n := wire.ConsumeVarint(b)
732 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700733 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700734 }
Damien Neil68b81c32019-08-22 11:41:32 -0700735 list.Append(protoreflect.ValueOfInt32(int32(v)))
736 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -0700737}
738
Damien Neil68b81c32019-08-22 11:41:32 -0700739var coderInt32SliceValue = valueCoderFuncs{
740 size: sizeInt32SliceValue,
741 marshal: appendInt32SliceValue,
742 unmarshal: consumeInt32SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -0700743}
744
Damien Neil68b81c32019-08-22 11:41:32 -0700745// sizeInt32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Int32.
746func sizeInt32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
747 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -0800748 llen := list.Len()
749 if llen == 0 {
750 return 0
751 }
Damien Neil7492a092019-07-10 15:23:29 -0700752 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -0800753 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -0700754 v := list.Get(i)
755 n += wire.SizeVarint(uint64(int32(v.Int())))
Damien Neil7492a092019-07-10 15:23:29 -0700756 }
757 return tagsize + wire.SizeBytes(n)
758}
759
Damien Neil68b81c32019-08-22 11:41:32 -0700760// appendInt32PackedSliceValue encodes a []int32 value as a packed repeated Int32.
761func appendInt32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
762 list := listv.List()
763 llen := list.Len()
764 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -0700765 return b, nil
766 }
767 b = wire.AppendVarint(b, wiretag)
768 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -0700769 for i := 0; i < llen; i++ {
770 v := list.Get(i)
771 n += wire.SizeVarint(uint64(int32(v.Int())))
Damien Neil7492a092019-07-10 15:23:29 -0700772 }
773 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -0700774 for i := 0; i < llen; i++ {
775 v := list.Get(i)
776 b = wire.AppendVarint(b, uint64(int32(v.Int())))
Damien Neil7492a092019-07-10 15:23:29 -0700777 }
778 return b, nil
779}
780
Damien Neil68b81c32019-08-22 11:41:32 -0700781var coderInt32PackedSliceValue = valueCoderFuncs{
782 size: sizeInt32PackedSliceValue,
783 marshal: appendInt32PackedSliceValue,
784 unmarshal: consumeInt32SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -0700785}
786
Damien Neilc37adef2019-04-01 13:49:56 -0700787// sizeSint32 returns the size of wire encoding a int32 pointer as a Sint32.
788func sizeSint32(p pointer, tagsize int, _ marshalOptions) (size int) {
789 v := *p.Int32()
790 return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v)))
791}
792
793// appendSint32 wire encodes a int32 pointer as a Sint32.
794func appendSint32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
795 v := *p.Int32()
796 b = wire.AppendVarint(b, wiretag)
797 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v)))
798 return b, nil
799}
800
Damien Neile91877d2019-06-27 10:54:42 -0700801// consumeSint32 wire decodes a int32 pointer as a Sint32.
802func consumeSint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
803 if wtyp != wire.VarintType {
804 return 0, errUnknown
805 }
806 v, n := wire.ConsumeVarint(b)
807 if n < 0 {
808 return 0, wire.ParseError(n)
809 }
810 *p.Int32() = int32(wire.DecodeZigZag(v & math.MaxUint32))
811 return n, nil
812}
813
Damien Neilc37adef2019-04-01 13:49:56 -0700814var coderSint32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700815 size: sizeSint32,
816 marshal: appendSint32,
817 unmarshal: consumeSint32,
Damien Neilc37adef2019-04-01 13:49:56 -0700818}
819
Joe Tsaic51e2e02019-07-13 00:44:41 -0700820// sizeSint32NoZero returns the size of wire encoding a int32 pointer as a Sint32.
Damien Neilc37adef2019-04-01 13:49:56 -0700821// The zero value is not encoded.
822func sizeSint32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
823 v := *p.Int32()
824 if v == 0 {
825 return 0
826 }
827 return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v)))
828}
829
Joe Tsaic51e2e02019-07-13 00:44:41 -0700830// appendSint32NoZero wire encodes a int32 pointer as a Sint32.
Damien Neilc37adef2019-04-01 13:49:56 -0700831// The zero value is not encoded.
832func appendSint32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
833 v := *p.Int32()
834 if v == 0 {
835 return b, nil
836 }
837 b = wire.AppendVarint(b, wiretag)
838 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v)))
839 return b, nil
840}
841
842var coderSint32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700843 size: sizeSint32NoZero,
844 marshal: appendSint32NoZero,
845 unmarshal: consumeSint32,
Damien Neilc37adef2019-04-01 13:49:56 -0700846}
847
848// sizeSint32Ptr returns the size of wire encoding a *int32 pointer as a Sint32.
849// It panics if the pointer is nil.
850func sizeSint32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
851 v := **p.Int32Ptr()
852 return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v)))
853}
854
Damien Neile91877d2019-06-27 10:54:42 -0700855// appendSint32Ptr wire encodes a *int32 pointer as a Sint32.
Damien Neilc37adef2019-04-01 13:49:56 -0700856// It panics if the pointer is nil.
857func appendSint32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
858 v := **p.Int32Ptr()
859 b = wire.AppendVarint(b, wiretag)
860 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v)))
861 return b, nil
862}
863
Damien Neile91877d2019-06-27 10:54:42 -0700864// consumeSint32Ptr wire decodes a *int32 pointer as a Sint32.
865func consumeSint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
866 if wtyp != wire.VarintType {
867 return 0, errUnknown
868 }
869 v, n := wire.ConsumeVarint(b)
870 if n < 0 {
871 return 0, wire.ParseError(n)
872 }
873 vp := p.Int32Ptr()
874 if *vp == nil {
875 *vp = new(int32)
876 }
877 **vp = int32(wire.DecodeZigZag(v & math.MaxUint32))
878 return n, nil
879}
880
Damien Neilc37adef2019-04-01 13:49:56 -0700881var coderSint32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700882 size: sizeSint32Ptr,
883 marshal: appendSint32Ptr,
884 unmarshal: consumeSint32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -0700885}
886
887// sizeSint32Slice returns the size of wire encoding a []int32 pointer as a repeated Sint32.
888func sizeSint32Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
889 s := *p.Int32Slice()
890 for _, v := range s {
891 size += tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v)))
892 }
893 return size
894}
895
896// appendSint32Slice encodes a []int32 pointer as a repeated Sint32.
897func appendSint32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
898 s := *p.Int32Slice()
899 for _, v := range s {
900 b = wire.AppendVarint(b, wiretag)
901 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v)))
902 }
903 return b, nil
904}
905
Damien Neile91877d2019-06-27 10:54:42 -0700906// consumeSint32Slice wire decodes a []int32 pointer as a repeated Sint32.
907func consumeSint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
908 sp := p.Int32Slice()
909 if wtyp == wire.BytesType {
910 s := *sp
911 b, n = wire.ConsumeBytes(b)
912 if n < 0 {
913 return 0, wire.ParseError(n)
914 }
915 for len(b) > 0 {
916 v, n := wire.ConsumeVarint(b)
917 if n < 0 {
918 return 0, wire.ParseError(n)
919 }
920 s = append(s, int32(wire.DecodeZigZag(v&math.MaxUint32)))
921 b = b[n:]
922 }
923 *sp = s
924 return n, nil
925 }
926 if wtyp != wire.VarintType {
927 return 0, errUnknown
928 }
929 v, n := wire.ConsumeVarint(b)
930 if n < 0 {
931 return 0, wire.ParseError(n)
932 }
933 *sp = append(*sp, int32(wire.DecodeZigZag(v&math.MaxUint32)))
934 return n, nil
935}
936
Damien Neilc37adef2019-04-01 13:49:56 -0700937var coderSint32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700938 size: sizeSint32Slice,
939 marshal: appendSint32Slice,
940 unmarshal: consumeSint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -0700941}
942
943// sizeSint32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sint32.
944func sizeSint32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
945 s := *p.Int32Slice()
946 if len(s) == 0 {
947 return 0
948 }
949 n := 0
950 for _, v := range s {
951 n += wire.SizeVarint(wire.EncodeZigZag(int64(v)))
952 }
953 return tagsize + wire.SizeBytes(n)
954}
955
956// appendSint32PackedSlice encodes a []int32 pointer as a packed repeated Sint32.
957func appendSint32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
958 s := *p.Int32Slice()
959 if len(s) == 0 {
960 return b, nil
961 }
962 b = wire.AppendVarint(b, wiretag)
963 n := 0
964 for _, v := range s {
965 n += wire.SizeVarint(wire.EncodeZigZag(int64(v)))
966 }
967 b = wire.AppendVarint(b, uint64(n))
968 for _, v := range s {
969 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v)))
970 }
971 return b, nil
972}
973
974var coderSint32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700975 size: sizeSint32PackedSlice,
976 marshal: appendSint32PackedSlice,
977 unmarshal: consumeSint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -0700978}
979
Damien Neil68b81c32019-08-22 11:41:32 -0700980// sizeSint32Value returns the size of wire encoding a int32 value as a Sint32.
981func sizeSint32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
982 return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -0700983}
984
Damien Neil68b81c32019-08-22 11:41:32 -0700985// appendSint32Value encodes a int32 value as a Sint32.
986func appendSint32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700987 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -0700988 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -0700989 return b, nil
990}
991
Damien Neil68b81c32019-08-22 11:41:32 -0700992// consumeSint32Value decodes a int32 value as a Sint32.
993func consumeSint32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -0700994 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -0700995 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700996 }
997 v, n := wire.ConsumeVarint(b)
998 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700999 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001000 }
Damien Neil68b81c32019-08-22 11:41:32 -07001001 return protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32))), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001002}
1003
Damien Neil68b81c32019-08-22 11:41:32 -07001004var coderSint32Value = valueCoderFuncs{
1005 size: sizeSint32Value,
1006 marshal: appendSint32Value,
1007 unmarshal: consumeSint32Value,
Damien Neilc37adef2019-04-01 13:49:56 -07001008}
1009
Damien Neil68b81c32019-08-22 11:41:32 -07001010// sizeSint32SliceValue returns the size of wire encoding a []int32 value as a repeated Sint32.
1011func sizeSint32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1012 list := listv.List()
1013 for i, llen := 0, list.Len(); i < llen; i++ {
1014 v := list.Get(i)
1015 size += tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -07001016 }
1017 return size
1018}
1019
Damien Neil68b81c32019-08-22 11:41:32 -07001020// appendSint32SliceValue encodes a []int32 value as a repeated Sint32.
1021func appendSint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1022 list := listv.List()
1023 for i, llen := 0, list.Len(); i < llen; i++ {
1024 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07001025 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001026 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -07001027 }
1028 return b, nil
1029}
1030
Damien Neil68b81c32019-08-22 11:41:32 -07001031// consumeSint32SliceValue wire decodes a []int32 value as a repeated Sint32.
1032func consumeSint32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
1033 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07001034 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07001035 b, n = wire.ConsumeBytes(b)
1036 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001037 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001038 }
1039 for len(b) > 0 {
1040 v, n := wire.ConsumeVarint(b)
1041 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001042 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001043 }
Damien Neil68b81c32019-08-22 11:41:32 -07001044 list.Append(protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32))))
Damien Neile91877d2019-06-27 10:54:42 -07001045 b = b[n:]
1046 }
Damien Neil68b81c32019-08-22 11:41:32 -07001047 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001048 }
1049 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001050 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001051 }
1052 v, n := wire.ConsumeVarint(b)
1053 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001054 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001055 }
Damien Neil68b81c32019-08-22 11:41:32 -07001056 list.Append(protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32))))
1057 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001058}
1059
Damien Neil68b81c32019-08-22 11:41:32 -07001060var coderSint32SliceValue = valueCoderFuncs{
1061 size: sizeSint32SliceValue,
1062 marshal: appendSint32SliceValue,
1063 unmarshal: consumeSint32SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07001064}
1065
Damien Neil68b81c32019-08-22 11:41:32 -07001066// sizeSint32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sint32.
1067func sizeSint32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1068 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08001069 llen := list.Len()
1070 if llen == 0 {
1071 return 0
1072 }
Damien Neil7492a092019-07-10 15:23:29 -07001073 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -08001074 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -07001075 v := list.Get(i)
1076 n += wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neil7492a092019-07-10 15:23:29 -07001077 }
1078 return tagsize + wire.SizeBytes(n)
1079}
1080
Damien Neil68b81c32019-08-22 11:41:32 -07001081// appendSint32PackedSliceValue encodes a []int32 value as a packed repeated Sint32.
1082func appendSint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1083 list := listv.List()
1084 llen := list.Len()
1085 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07001086 return b, nil
1087 }
1088 b = wire.AppendVarint(b, wiretag)
1089 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07001090 for i := 0; i < llen; i++ {
1091 v := list.Get(i)
1092 n += wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neil7492a092019-07-10 15:23:29 -07001093 }
1094 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07001095 for i := 0; i < llen; i++ {
1096 v := list.Get(i)
1097 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neil7492a092019-07-10 15:23:29 -07001098 }
1099 return b, nil
1100}
1101
Damien Neil68b81c32019-08-22 11:41:32 -07001102var coderSint32PackedSliceValue = valueCoderFuncs{
1103 size: sizeSint32PackedSliceValue,
1104 marshal: appendSint32PackedSliceValue,
1105 unmarshal: consumeSint32SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07001106}
1107
Damien Neilc37adef2019-04-01 13:49:56 -07001108// sizeUint32 returns the size of wire encoding a uint32 pointer as a Uint32.
1109func sizeUint32(p pointer, tagsize int, _ marshalOptions) (size int) {
1110 v := *p.Uint32()
1111 return tagsize + wire.SizeVarint(uint64(v))
1112}
1113
1114// appendUint32 wire encodes a uint32 pointer as a Uint32.
1115func appendUint32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1116 v := *p.Uint32()
1117 b = wire.AppendVarint(b, wiretag)
1118 b = wire.AppendVarint(b, uint64(v))
1119 return b, nil
1120}
1121
Damien Neile91877d2019-06-27 10:54:42 -07001122// consumeUint32 wire decodes a uint32 pointer as a Uint32.
1123func consumeUint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1124 if wtyp != wire.VarintType {
1125 return 0, errUnknown
1126 }
1127 v, n := wire.ConsumeVarint(b)
1128 if n < 0 {
1129 return 0, wire.ParseError(n)
1130 }
1131 *p.Uint32() = uint32(v)
1132 return n, nil
1133}
1134
Damien Neilc37adef2019-04-01 13:49:56 -07001135var coderUint32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001136 size: sizeUint32,
1137 marshal: appendUint32,
1138 unmarshal: consumeUint32,
Damien Neilc37adef2019-04-01 13:49:56 -07001139}
1140
Joe Tsaic51e2e02019-07-13 00:44:41 -07001141// sizeUint32NoZero returns the size of wire encoding a uint32 pointer as a Uint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001142// The zero value is not encoded.
1143func sizeUint32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
1144 v := *p.Uint32()
1145 if v == 0 {
1146 return 0
1147 }
1148 return tagsize + wire.SizeVarint(uint64(v))
1149}
1150
Joe Tsaic51e2e02019-07-13 00:44:41 -07001151// appendUint32NoZero wire encodes a uint32 pointer as a Uint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001152// The zero value is not encoded.
1153func appendUint32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1154 v := *p.Uint32()
1155 if v == 0 {
1156 return b, nil
1157 }
1158 b = wire.AppendVarint(b, wiretag)
1159 b = wire.AppendVarint(b, uint64(v))
1160 return b, nil
1161}
1162
1163var coderUint32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001164 size: sizeUint32NoZero,
1165 marshal: appendUint32NoZero,
1166 unmarshal: consumeUint32,
Damien Neilc37adef2019-04-01 13:49:56 -07001167}
1168
1169// sizeUint32Ptr returns the size of wire encoding a *uint32 pointer as a Uint32.
1170// It panics if the pointer is nil.
1171func sizeUint32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
1172 v := **p.Uint32Ptr()
1173 return tagsize + wire.SizeVarint(uint64(v))
1174}
1175
Damien Neile91877d2019-06-27 10:54:42 -07001176// appendUint32Ptr wire encodes a *uint32 pointer as a Uint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001177// It panics if the pointer is nil.
1178func appendUint32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1179 v := **p.Uint32Ptr()
1180 b = wire.AppendVarint(b, wiretag)
1181 b = wire.AppendVarint(b, uint64(v))
1182 return b, nil
1183}
1184
Damien Neile91877d2019-06-27 10:54:42 -07001185// consumeUint32Ptr wire decodes a *uint32 pointer as a Uint32.
1186func consumeUint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1187 if wtyp != wire.VarintType {
1188 return 0, errUnknown
1189 }
1190 v, n := wire.ConsumeVarint(b)
1191 if n < 0 {
1192 return 0, wire.ParseError(n)
1193 }
1194 vp := p.Uint32Ptr()
1195 if *vp == nil {
1196 *vp = new(uint32)
1197 }
1198 **vp = uint32(v)
1199 return n, nil
1200}
1201
Damien Neilc37adef2019-04-01 13:49:56 -07001202var coderUint32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001203 size: sizeUint32Ptr,
1204 marshal: appendUint32Ptr,
1205 unmarshal: consumeUint32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07001206}
1207
1208// sizeUint32Slice returns the size of wire encoding a []uint32 pointer as a repeated Uint32.
1209func sizeUint32Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
1210 s := *p.Uint32Slice()
1211 for _, v := range s {
1212 size += tagsize + wire.SizeVarint(uint64(v))
1213 }
1214 return size
1215}
1216
1217// appendUint32Slice encodes a []uint32 pointer as a repeated Uint32.
1218func appendUint32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1219 s := *p.Uint32Slice()
1220 for _, v := range s {
1221 b = wire.AppendVarint(b, wiretag)
1222 b = wire.AppendVarint(b, uint64(v))
1223 }
1224 return b, nil
1225}
1226
Damien Neile91877d2019-06-27 10:54:42 -07001227// consumeUint32Slice wire decodes a []uint32 pointer as a repeated Uint32.
1228func consumeUint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1229 sp := p.Uint32Slice()
1230 if wtyp == wire.BytesType {
1231 s := *sp
1232 b, n = wire.ConsumeBytes(b)
1233 if n < 0 {
1234 return 0, wire.ParseError(n)
1235 }
1236 for len(b) > 0 {
1237 v, n := wire.ConsumeVarint(b)
1238 if n < 0 {
1239 return 0, wire.ParseError(n)
1240 }
1241 s = append(s, uint32(v))
1242 b = b[n:]
1243 }
1244 *sp = s
1245 return n, nil
1246 }
1247 if wtyp != wire.VarintType {
1248 return 0, errUnknown
1249 }
1250 v, n := wire.ConsumeVarint(b)
1251 if n < 0 {
1252 return 0, wire.ParseError(n)
1253 }
1254 *sp = append(*sp, uint32(v))
1255 return n, nil
1256}
1257
Damien Neilc37adef2019-04-01 13:49:56 -07001258var coderUint32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001259 size: sizeUint32Slice,
1260 marshal: appendUint32Slice,
1261 unmarshal: consumeUint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001262}
1263
1264// sizeUint32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Uint32.
1265func sizeUint32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
1266 s := *p.Uint32Slice()
1267 if len(s) == 0 {
1268 return 0
1269 }
1270 n := 0
1271 for _, v := range s {
1272 n += wire.SizeVarint(uint64(v))
1273 }
1274 return tagsize + wire.SizeBytes(n)
1275}
1276
1277// appendUint32PackedSlice encodes a []uint32 pointer as a packed repeated Uint32.
1278func appendUint32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1279 s := *p.Uint32Slice()
1280 if len(s) == 0 {
1281 return b, nil
1282 }
1283 b = wire.AppendVarint(b, wiretag)
1284 n := 0
1285 for _, v := range s {
1286 n += wire.SizeVarint(uint64(v))
1287 }
1288 b = wire.AppendVarint(b, uint64(n))
1289 for _, v := range s {
1290 b = wire.AppendVarint(b, uint64(v))
1291 }
1292 return b, nil
1293}
1294
1295var coderUint32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001296 size: sizeUint32PackedSlice,
1297 marshal: appendUint32PackedSlice,
1298 unmarshal: consumeUint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001299}
1300
Damien Neil68b81c32019-08-22 11:41:32 -07001301// sizeUint32Value returns the size of wire encoding a uint32 value as a Uint32.
1302func sizeUint32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
1303 return tagsize + wire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001304}
1305
Damien Neil68b81c32019-08-22 11:41:32 -07001306// appendUint32Value encodes a uint32 value as a Uint32.
1307func appendUint32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001308 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001309 b = wire.AppendVarint(b, uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001310 return b, nil
1311}
1312
Damien Neil68b81c32019-08-22 11:41:32 -07001313// consumeUint32Value decodes a uint32 value as a Uint32.
1314func consumeUint32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07001315 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001316 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001317 }
1318 v, n := wire.ConsumeVarint(b)
1319 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001320 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001321 }
Damien Neil68b81c32019-08-22 11:41:32 -07001322 return protoreflect.ValueOfUint32(uint32(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001323}
1324
Damien Neil68b81c32019-08-22 11:41:32 -07001325var coderUint32Value = valueCoderFuncs{
1326 size: sizeUint32Value,
1327 marshal: appendUint32Value,
1328 unmarshal: consumeUint32Value,
Damien Neilc37adef2019-04-01 13:49:56 -07001329}
1330
Damien Neil68b81c32019-08-22 11:41:32 -07001331// sizeUint32SliceValue returns the size of wire encoding a []uint32 value as a repeated Uint32.
1332func sizeUint32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1333 list := listv.List()
1334 for i, llen := 0, list.Len(); i < llen; i++ {
1335 v := list.Get(i)
1336 size += tagsize + wire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001337 }
1338 return size
1339}
1340
Damien Neil68b81c32019-08-22 11:41:32 -07001341// appendUint32SliceValue encodes a []uint32 value as a repeated Uint32.
1342func appendUint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1343 list := listv.List()
1344 for i, llen := 0, list.Len(); i < llen; i++ {
1345 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07001346 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001347 b = wire.AppendVarint(b, uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001348 }
1349 return b, nil
1350}
1351
Damien Neil68b81c32019-08-22 11:41:32 -07001352// consumeUint32SliceValue wire decodes a []uint32 value as a repeated Uint32.
1353func consumeUint32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
1354 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07001355 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07001356 b, n = wire.ConsumeBytes(b)
1357 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001358 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001359 }
1360 for len(b) > 0 {
1361 v, n := wire.ConsumeVarint(b)
1362 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001363 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001364 }
Damien Neil68b81c32019-08-22 11:41:32 -07001365 list.Append(protoreflect.ValueOfUint32(uint32(v)))
Damien Neile91877d2019-06-27 10:54:42 -07001366 b = b[n:]
1367 }
Damien Neil68b81c32019-08-22 11:41:32 -07001368 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001369 }
1370 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001371 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001372 }
1373 v, n := wire.ConsumeVarint(b)
1374 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001375 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001376 }
Damien Neil68b81c32019-08-22 11:41:32 -07001377 list.Append(protoreflect.ValueOfUint32(uint32(v)))
1378 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001379}
1380
Damien Neil68b81c32019-08-22 11:41:32 -07001381var coderUint32SliceValue = valueCoderFuncs{
1382 size: sizeUint32SliceValue,
1383 marshal: appendUint32SliceValue,
1384 unmarshal: consumeUint32SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07001385}
1386
Damien Neil68b81c32019-08-22 11:41:32 -07001387// sizeUint32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Uint32.
1388func sizeUint32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1389 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08001390 llen := list.Len()
1391 if llen == 0 {
1392 return 0
1393 }
Damien Neil7492a092019-07-10 15:23:29 -07001394 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -08001395 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -07001396 v := list.Get(i)
1397 n += wire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neil7492a092019-07-10 15:23:29 -07001398 }
1399 return tagsize + wire.SizeBytes(n)
1400}
1401
Damien Neil68b81c32019-08-22 11:41:32 -07001402// appendUint32PackedSliceValue encodes a []uint32 value as a packed repeated Uint32.
1403func appendUint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1404 list := listv.List()
1405 llen := list.Len()
1406 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07001407 return b, nil
1408 }
1409 b = wire.AppendVarint(b, wiretag)
1410 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07001411 for i := 0; i < llen; i++ {
1412 v := list.Get(i)
1413 n += wire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neil7492a092019-07-10 15:23:29 -07001414 }
1415 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07001416 for i := 0; i < llen; i++ {
1417 v := list.Get(i)
1418 b = wire.AppendVarint(b, uint64(uint32(v.Uint())))
Damien Neil7492a092019-07-10 15:23:29 -07001419 }
1420 return b, nil
1421}
1422
Damien Neil68b81c32019-08-22 11:41:32 -07001423var coderUint32PackedSliceValue = valueCoderFuncs{
1424 size: sizeUint32PackedSliceValue,
1425 marshal: appendUint32PackedSliceValue,
1426 unmarshal: consumeUint32SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07001427}
1428
Damien Neilc37adef2019-04-01 13:49:56 -07001429// sizeInt64 returns the size of wire encoding a int64 pointer as a Int64.
1430func sizeInt64(p pointer, tagsize int, _ marshalOptions) (size int) {
1431 v := *p.Int64()
1432 return tagsize + wire.SizeVarint(uint64(v))
1433}
1434
1435// appendInt64 wire encodes a int64 pointer as a Int64.
1436func appendInt64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1437 v := *p.Int64()
1438 b = wire.AppendVarint(b, wiretag)
1439 b = wire.AppendVarint(b, uint64(v))
1440 return b, nil
1441}
1442
Damien Neile91877d2019-06-27 10:54:42 -07001443// consumeInt64 wire decodes a int64 pointer as a Int64.
1444func consumeInt64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1445 if wtyp != wire.VarintType {
1446 return 0, errUnknown
1447 }
1448 v, n := wire.ConsumeVarint(b)
1449 if n < 0 {
1450 return 0, wire.ParseError(n)
1451 }
1452 *p.Int64() = int64(v)
1453 return n, nil
1454}
1455
Damien Neilc37adef2019-04-01 13:49:56 -07001456var coderInt64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001457 size: sizeInt64,
1458 marshal: appendInt64,
1459 unmarshal: consumeInt64,
Damien Neilc37adef2019-04-01 13:49:56 -07001460}
1461
Joe Tsaic51e2e02019-07-13 00:44:41 -07001462// sizeInt64NoZero returns the size of wire encoding a int64 pointer as a Int64.
Damien Neilc37adef2019-04-01 13:49:56 -07001463// The zero value is not encoded.
1464func sizeInt64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
1465 v := *p.Int64()
1466 if v == 0 {
1467 return 0
1468 }
1469 return tagsize + wire.SizeVarint(uint64(v))
1470}
1471
Joe Tsaic51e2e02019-07-13 00:44:41 -07001472// appendInt64NoZero wire encodes a int64 pointer as a Int64.
Damien Neilc37adef2019-04-01 13:49:56 -07001473// The zero value is not encoded.
1474func appendInt64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1475 v := *p.Int64()
1476 if v == 0 {
1477 return b, nil
1478 }
1479 b = wire.AppendVarint(b, wiretag)
1480 b = wire.AppendVarint(b, uint64(v))
1481 return b, nil
1482}
1483
1484var coderInt64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001485 size: sizeInt64NoZero,
1486 marshal: appendInt64NoZero,
1487 unmarshal: consumeInt64,
Damien Neilc37adef2019-04-01 13:49:56 -07001488}
1489
1490// sizeInt64Ptr returns the size of wire encoding a *int64 pointer as a Int64.
1491// It panics if the pointer is nil.
1492func sizeInt64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
1493 v := **p.Int64Ptr()
1494 return tagsize + wire.SizeVarint(uint64(v))
1495}
1496
Damien Neile91877d2019-06-27 10:54:42 -07001497// appendInt64Ptr wire encodes a *int64 pointer as a Int64.
Damien Neilc37adef2019-04-01 13:49:56 -07001498// It panics if the pointer is nil.
1499func appendInt64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1500 v := **p.Int64Ptr()
1501 b = wire.AppendVarint(b, wiretag)
1502 b = wire.AppendVarint(b, uint64(v))
1503 return b, nil
1504}
1505
Damien Neile91877d2019-06-27 10:54:42 -07001506// consumeInt64Ptr wire decodes a *int64 pointer as a Int64.
1507func consumeInt64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1508 if wtyp != wire.VarintType {
1509 return 0, errUnknown
1510 }
1511 v, n := wire.ConsumeVarint(b)
1512 if n < 0 {
1513 return 0, wire.ParseError(n)
1514 }
1515 vp := p.Int64Ptr()
1516 if *vp == nil {
1517 *vp = new(int64)
1518 }
1519 **vp = int64(v)
1520 return n, nil
1521}
1522
Damien Neilc37adef2019-04-01 13:49:56 -07001523var coderInt64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001524 size: sizeInt64Ptr,
1525 marshal: appendInt64Ptr,
1526 unmarshal: consumeInt64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07001527}
1528
1529// sizeInt64Slice returns the size of wire encoding a []int64 pointer as a repeated Int64.
1530func sizeInt64Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
1531 s := *p.Int64Slice()
1532 for _, v := range s {
1533 size += tagsize + wire.SizeVarint(uint64(v))
1534 }
1535 return size
1536}
1537
1538// appendInt64Slice encodes a []int64 pointer as a repeated Int64.
1539func appendInt64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1540 s := *p.Int64Slice()
1541 for _, v := range s {
1542 b = wire.AppendVarint(b, wiretag)
1543 b = wire.AppendVarint(b, uint64(v))
1544 }
1545 return b, nil
1546}
1547
Damien Neile91877d2019-06-27 10:54:42 -07001548// consumeInt64Slice wire decodes a []int64 pointer as a repeated Int64.
1549func consumeInt64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1550 sp := p.Int64Slice()
1551 if wtyp == wire.BytesType {
1552 s := *sp
1553 b, n = wire.ConsumeBytes(b)
1554 if n < 0 {
1555 return 0, wire.ParseError(n)
1556 }
1557 for len(b) > 0 {
1558 v, n := wire.ConsumeVarint(b)
1559 if n < 0 {
1560 return 0, wire.ParseError(n)
1561 }
1562 s = append(s, int64(v))
1563 b = b[n:]
1564 }
1565 *sp = s
1566 return n, nil
1567 }
1568 if wtyp != wire.VarintType {
1569 return 0, errUnknown
1570 }
1571 v, n := wire.ConsumeVarint(b)
1572 if n < 0 {
1573 return 0, wire.ParseError(n)
1574 }
1575 *sp = append(*sp, int64(v))
1576 return n, nil
1577}
1578
Damien Neilc37adef2019-04-01 13:49:56 -07001579var coderInt64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001580 size: sizeInt64Slice,
1581 marshal: appendInt64Slice,
1582 unmarshal: consumeInt64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001583}
1584
1585// sizeInt64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Int64.
1586func sizeInt64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
1587 s := *p.Int64Slice()
1588 if len(s) == 0 {
1589 return 0
1590 }
1591 n := 0
1592 for _, v := range s {
1593 n += wire.SizeVarint(uint64(v))
1594 }
1595 return tagsize + wire.SizeBytes(n)
1596}
1597
1598// appendInt64PackedSlice encodes a []int64 pointer as a packed repeated Int64.
1599func appendInt64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1600 s := *p.Int64Slice()
1601 if len(s) == 0 {
1602 return b, nil
1603 }
1604 b = wire.AppendVarint(b, wiretag)
1605 n := 0
1606 for _, v := range s {
1607 n += wire.SizeVarint(uint64(v))
1608 }
1609 b = wire.AppendVarint(b, uint64(n))
1610 for _, v := range s {
1611 b = wire.AppendVarint(b, uint64(v))
1612 }
1613 return b, nil
1614}
1615
1616var coderInt64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001617 size: sizeInt64PackedSlice,
1618 marshal: appendInt64PackedSlice,
1619 unmarshal: consumeInt64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001620}
1621
Damien Neil68b81c32019-08-22 11:41:32 -07001622// sizeInt64Value returns the size of wire encoding a int64 value as a Int64.
1623func sizeInt64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
1624 return tagsize + wire.SizeVarint(uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001625}
1626
Damien Neil68b81c32019-08-22 11:41:32 -07001627// appendInt64Value encodes a int64 value as a Int64.
1628func appendInt64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001629 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001630 b = wire.AppendVarint(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001631 return b, nil
1632}
1633
Damien Neil68b81c32019-08-22 11:41:32 -07001634// consumeInt64Value decodes a int64 value as a Int64.
1635func consumeInt64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07001636 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001637 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001638 }
1639 v, n := wire.ConsumeVarint(b)
1640 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001641 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001642 }
Damien Neil68b81c32019-08-22 11:41:32 -07001643 return protoreflect.ValueOfInt64(int64(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001644}
1645
Damien Neil68b81c32019-08-22 11:41:32 -07001646var coderInt64Value = valueCoderFuncs{
1647 size: sizeInt64Value,
1648 marshal: appendInt64Value,
1649 unmarshal: consumeInt64Value,
Damien Neilc37adef2019-04-01 13:49:56 -07001650}
1651
Damien Neil68b81c32019-08-22 11:41:32 -07001652// sizeInt64SliceValue returns the size of wire encoding a []int64 value as a repeated Int64.
1653func sizeInt64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1654 list := listv.List()
1655 for i, llen := 0, list.Len(); i < llen; i++ {
1656 v := list.Get(i)
1657 size += tagsize + wire.SizeVarint(uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001658 }
1659 return size
1660}
1661
Damien Neil68b81c32019-08-22 11:41:32 -07001662// appendInt64SliceValue encodes a []int64 value as a repeated Int64.
1663func appendInt64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1664 list := listv.List()
1665 for i, llen := 0, list.Len(); i < llen; i++ {
1666 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07001667 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001668 b = wire.AppendVarint(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001669 }
1670 return b, nil
1671}
1672
Damien Neil68b81c32019-08-22 11:41:32 -07001673// consumeInt64SliceValue wire decodes a []int64 value as a repeated Int64.
1674func consumeInt64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
1675 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07001676 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07001677 b, n = wire.ConsumeBytes(b)
1678 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001679 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001680 }
1681 for len(b) > 0 {
1682 v, n := wire.ConsumeVarint(b)
1683 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001684 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001685 }
Damien Neil68b81c32019-08-22 11:41:32 -07001686 list.Append(protoreflect.ValueOfInt64(int64(v)))
Damien Neile91877d2019-06-27 10:54:42 -07001687 b = b[n:]
1688 }
Damien Neil68b81c32019-08-22 11:41:32 -07001689 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001690 }
1691 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001692 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001693 }
1694 v, n := wire.ConsumeVarint(b)
1695 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001696 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001697 }
Damien Neil68b81c32019-08-22 11:41:32 -07001698 list.Append(protoreflect.ValueOfInt64(int64(v)))
1699 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001700}
1701
Damien Neil68b81c32019-08-22 11:41:32 -07001702var coderInt64SliceValue = valueCoderFuncs{
1703 size: sizeInt64SliceValue,
1704 marshal: appendInt64SliceValue,
1705 unmarshal: consumeInt64SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07001706}
1707
Damien Neil68b81c32019-08-22 11:41:32 -07001708// sizeInt64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Int64.
1709func sizeInt64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1710 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08001711 llen := list.Len()
1712 if llen == 0 {
1713 return 0
1714 }
Damien Neil7492a092019-07-10 15:23:29 -07001715 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -08001716 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -07001717 v := list.Get(i)
1718 n += wire.SizeVarint(uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07001719 }
1720 return tagsize + wire.SizeBytes(n)
1721}
1722
Damien Neil68b81c32019-08-22 11:41:32 -07001723// appendInt64PackedSliceValue encodes a []int64 value as a packed repeated Int64.
1724func appendInt64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1725 list := listv.List()
1726 llen := list.Len()
1727 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07001728 return b, nil
1729 }
1730 b = wire.AppendVarint(b, wiretag)
1731 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07001732 for i := 0; i < llen; i++ {
1733 v := list.Get(i)
1734 n += wire.SizeVarint(uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07001735 }
1736 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07001737 for i := 0; i < llen; i++ {
1738 v := list.Get(i)
1739 b = wire.AppendVarint(b, uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07001740 }
1741 return b, nil
1742}
1743
Damien Neil68b81c32019-08-22 11:41:32 -07001744var coderInt64PackedSliceValue = valueCoderFuncs{
1745 size: sizeInt64PackedSliceValue,
1746 marshal: appendInt64PackedSliceValue,
1747 unmarshal: consumeInt64SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07001748}
1749
Damien Neilc37adef2019-04-01 13:49:56 -07001750// sizeSint64 returns the size of wire encoding a int64 pointer as a Sint64.
1751func sizeSint64(p pointer, tagsize int, _ marshalOptions) (size int) {
1752 v := *p.Int64()
1753 return tagsize + wire.SizeVarint(wire.EncodeZigZag(v))
1754}
1755
1756// appendSint64 wire encodes a int64 pointer as a Sint64.
1757func appendSint64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1758 v := *p.Int64()
1759 b = wire.AppendVarint(b, wiretag)
1760 b = wire.AppendVarint(b, wire.EncodeZigZag(v))
1761 return b, nil
1762}
1763
Damien Neile91877d2019-06-27 10:54:42 -07001764// consumeSint64 wire decodes a int64 pointer as a Sint64.
1765func consumeSint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1766 if wtyp != wire.VarintType {
1767 return 0, errUnknown
1768 }
1769 v, n := wire.ConsumeVarint(b)
1770 if n < 0 {
1771 return 0, wire.ParseError(n)
1772 }
1773 *p.Int64() = wire.DecodeZigZag(v)
1774 return n, nil
1775}
1776
Damien Neilc37adef2019-04-01 13:49:56 -07001777var coderSint64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001778 size: sizeSint64,
1779 marshal: appendSint64,
1780 unmarshal: consumeSint64,
Damien Neilc37adef2019-04-01 13:49:56 -07001781}
1782
Joe Tsaic51e2e02019-07-13 00:44:41 -07001783// sizeSint64NoZero returns the size of wire encoding a int64 pointer as a Sint64.
Damien Neilc37adef2019-04-01 13:49:56 -07001784// The zero value is not encoded.
1785func sizeSint64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
1786 v := *p.Int64()
1787 if v == 0 {
1788 return 0
1789 }
1790 return tagsize + wire.SizeVarint(wire.EncodeZigZag(v))
1791}
1792
Joe Tsaic51e2e02019-07-13 00:44:41 -07001793// appendSint64NoZero wire encodes a int64 pointer as a Sint64.
Damien Neilc37adef2019-04-01 13:49:56 -07001794// The zero value is not encoded.
1795func appendSint64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1796 v := *p.Int64()
1797 if v == 0 {
1798 return b, nil
1799 }
1800 b = wire.AppendVarint(b, wiretag)
1801 b = wire.AppendVarint(b, wire.EncodeZigZag(v))
1802 return b, nil
1803}
1804
1805var coderSint64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001806 size: sizeSint64NoZero,
1807 marshal: appendSint64NoZero,
1808 unmarshal: consumeSint64,
Damien Neilc37adef2019-04-01 13:49:56 -07001809}
1810
1811// sizeSint64Ptr returns the size of wire encoding a *int64 pointer as a Sint64.
1812// It panics if the pointer is nil.
1813func sizeSint64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
1814 v := **p.Int64Ptr()
1815 return tagsize + wire.SizeVarint(wire.EncodeZigZag(v))
1816}
1817
Damien Neile91877d2019-06-27 10:54:42 -07001818// appendSint64Ptr wire encodes a *int64 pointer as a Sint64.
Damien Neilc37adef2019-04-01 13:49:56 -07001819// It panics if the pointer is nil.
1820func appendSint64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1821 v := **p.Int64Ptr()
1822 b = wire.AppendVarint(b, wiretag)
1823 b = wire.AppendVarint(b, wire.EncodeZigZag(v))
1824 return b, nil
1825}
1826
Damien Neile91877d2019-06-27 10:54:42 -07001827// consumeSint64Ptr wire decodes a *int64 pointer as a Sint64.
1828func consumeSint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1829 if wtyp != wire.VarintType {
1830 return 0, errUnknown
1831 }
1832 v, n := wire.ConsumeVarint(b)
1833 if n < 0 {
1834 return 0, wire.ParseError(n)
1835 }
1836 vp := p.Int64Ptr()
1837 if *vp == nil {
1838 *vp = new(int64)
1839 }
1840 **vp = wire.DecodeZigZag(v)
1841 return n, nil
1842}
1843
Damien Neilc37adef2019-04-01 13:49:56 -07001844var coderSint64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001845 size: sizeSint64Ptr,
1846 marshal: appendSint64Ptr,
1847 unmarshal: consumeSint64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07001848}
1849
1850// sizeSint64Slice returns the size of wire encoding a []int64 pointer as a repeated Sint64.
1851func sizeSint64Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
1852 s := *p.Int64Slice()
1853 for _, v := range s {
1854 size += tagsize + wire.SizeVarint(wire.EncodeZigZag(v))
1855 }
1856 return size
1857}
1858
1859// appendSint64Slice encodes a []int64 pointer as a repeated Sint64.
1860func appendSint64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1861 s := *p.Int64Slice()
1862 for _, v := range s {
1863 b = wire.AppendVarint(b, wiretag)
1864 b = wire.AppendVarint(b, wire.EncodeZigZag(v))
1865 }
1866 return b, nil
1867}
1868
Damien Neile91877d2019-06-27 10:54:42 -07001869// consumeSint64Slice wire decodes a []int64 pointer as a repeated Sint64.
1870func consumeSint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1871 sp := p.Int64Slice()
1872 if wtyp == wire.BytesType {
1873 s := *sp
1874 b, n = wire.ConsumeBytes(b)
1875 if n < 0 {
1876 return 0, wire.ParseError(n)
1877 }
1878 for len(b) > 0 {
1879 v, n := wire.ConsumeVarint(b)
1880 if n < 0 {
1881 return 0, wire.ParseError(n)
1882 }
1883 s = append(s, wire.DecodeZigZag(v))
1884 b = b[n:]
1885 }
1886 *sp = s
1887 return n, nil
1888 }
1889 if wtyp != wire.VarintType {
1890 return 0, errUnknown
1891 }
1892 v, n := wire.ConsumeVarint(b)
1893 if n < 0 {
1894 return 0, wire.ParseError(n)
1895 }
1896 *sp = append(*sp, wire.DecodeZigZag(v))
1897 return n, nil
1898}
1899
Damien Neilc37adef2019-04-01 13:49:56 -07001900var coderSint64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001901 size: sizeSint64Slice,
1902 marshal: appendSint64Slice,
1903 unmarshal: consumeSint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001904}
1905
1906// sizeSint64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sint64.
1907func sizeSint64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
1908 s := *p.Int64Slice()
1909 if len(s) == 0 {
1910 return 0
1911 }
1912 n := 0
1913 for _, v := range s {
1914 n += wire.SizeVarint(wire.EncodeZigZag(v))
1915 }
1916 return tagsize + wire.SizeBytes(n)
1917}
1918
1919// appendSint64PackedSlice encodes a []int64 pointer as a packed repeated Sint64.
1920func appendSint64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1921 s := *p.Int64Slice()
1922 if len(s) == 0 {
1923 return b, nil
1924 }
1925 b = wire.AppendVarint(b, wiretag)
1926 n := 0
1927 for _, v := range s {
1928 n += wire.SizeVarint(wire.EncodeZigZag(v))
1929 }
1930 b = wire.AppendVarint(b, uint64(n))
1931 for _, v := range s {
1932 b = wire.AppendVarint(b, wire.EncodeZigZag(v))
1933 }
1934 return b, nil
1935}
1936
1937var coderSint64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001938 size: sizeSint64PackedSlice,
1939 marshal: appendSint64PackedSlice,
1940 unmarshal: consumeSint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001941}
1942
Damien Neil68b81c32019-08-22 11:41:32 -07001943// sizeSint64Value returns the size of wire encoding a int64 value as a Sint64.
1944func sizeSint64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
1945 return tagsize + wire.SizeVarint(wire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001946}
1947
Damien Neil68b81c32019-08-22 11:41:32 -07001948// appendSint64Value encodes a int64 value as a Sint64.
1949func appendSint64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001950 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001951 b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001952 return b, nil
1953}
1954
Damien Neil68b81c32019-08-22 11:41:32 -07001955// consumeSint64Value decodes a int64 value as a Sint64.
1956func consumeSint64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07001957 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001958 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001959 }
1960 v, n := wire.ConsumeVarint(b)
1961 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001962 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001963 }
Damien Neil68b81c32019-08-22 11:41:32 -07001964 return protoreflect.ValueOfInt64(wire.DecodeZigZag(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001965}
1966
Damien Neil68b81c32019-08-22 11:41:32 -07001967var coderSint64Value = valueCoderFuncs{
1968 size: sizeSint64Value,
1969 marshal: appendSint64Value,
1970 unmarshal: consumeSint64Value,
Damien Neilc37adef2019-04-01 13:49:56 -07001971}
1972
Damien Neil68b81c32019-08-22 11:41:32 -07001973// sizeSint64SliceValue returns the size of wire encoding a []int64 value as a repeated Sint64.
1974func sizeSint64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1975 list := listv.List()
1976 for i, llen := 0, list.Len(); i < llen; i++ {
1977 v := list.Get(i)
1978 size += tagsize + wire.SizeVarint(wire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001979 }
1980 return size
1981}
1982
Damien Neil68b81c32019-08-22 11:41:32 -07001983// appendSint64SliceValue encodes a []int64 value as a repeated Sint64.
1984func appendSint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1985 list := listv.List()
1986 for i, llen := 0, list.Len(); i < llen; i++ {
1987 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07001988 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001989 b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001990 }
1991 return b, nil
1992}
1993
Damien Neil68b81c32019-08-22 11:41:32 -07001994// consumeSint64SliceValue wire decodes a []int64 value as a repeated Sint64.
1995func consumeSint64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
1996 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07001997 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07001998 b, n = wire.ConsumeBytes(b)
1999 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002000 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002001 }
2002 for len(b) > 0 {
2003 v, n := wire.ConsumeVarint(b)
2004 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002005 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002006 }
Damien Neil68b81c32019-08-22 11:41:32 -07002007 list.Append(protoreflect.ValueOfInt64(wire.DecodeZigZag(v)))
Damien Neile91877d2019-06-27 10:54:42 -07002008 b = b[n:]
2009 }
Damien Neil68b81c32019-08-22 11:41:32 -07002010 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002011 }
2012 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07002013 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002014 }
2015 v, n := wire.ConsumeVarint(b)
2016 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002017 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002018 }
Damien Neil68b81c32019-08-22 11:41:32 -07002019 list.Append(protoreflect.ValueOfInt64(wire.DecodeZigZag(v)))
2020 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002021}
2022
Damien Neil68b81c32019-08-22 11:41:32 -07002023var coderSint64SliceValue = valueCoderFuncs{
2024 size: sizeSint64SliceValue,
2025 marshal: appendSint64SliceValue,
2026 unmarshal: consumeSint64SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002027}
2028
Damien Neil68b81c32019-08-22 11:41:32 -07002029// sizeSint64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sint64.
2030func sizeSint64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2031 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08002032 llen := list.Len()
2033 if llen == 0 {
2034 return 0
2035 }
Damien Neil7492a092019-07-10 15:23:29 -07002036 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -08002037 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -07002038 v := list.Get(i)
2039 n += wire.SizeVarint(wire.EncodeZigZag(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002040 }
2041 return tagsize + wire.SizeBytes(n)
2042}
2043
Damien Neil68b81c32019-08-22 11:41:32 -07002044// appendSint64PackedSliceValue encodes a []int64 value as a packed repeated Sint64.
2045func appendSint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2046 list := listv.List()
2047 llen := list.Len()
2048 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07002049 return b, nil
2050 }
2051 b = wire.AppendVarint(b, wiretag)
2052 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07002053 for i := 0; i < llen; i++ {
2054 v := list.Get(i)
2055 n += wire.SizeVarint(wire.EncodeZigZag(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002056 }
2057 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07002058 for i := 0; i < llen; i++ {
2059 v := list.Get(i)
2060 b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002061 }
2062 return b, nil
2063}
2064
Damien Neil68b81c32019-08-22 11:41:32 -07002065var coderSint64PackedSliceValue = valueCoderFuncs{
2066 size: sizeSint64PackedSliceValue,
2067 marshal: appendSint64PackedSliceValue,
2068 unmarshal: consumeSint64SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07002069}
2070
Damien Neilc37adef2019-04-01 13:49:56 -07002071// sizeUint64 returns the size of wire encoding a uint64 pointer as a Uint64.
2072func sizeUint64(p pointer, tagsize int, _ marshalOptions) (size int) {
2073 v := *p.Uint64()
2074 return tagsize + wire.SizeVarint(v)
2075}
2076
2077// appendUint64 wire encodes a uint64 pointer as a Uint64.
2078func appendUint64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2079 v := *p.Uint64()
2080 b = wire.AppendVarint(b, wiretag)
2081 b = wire.AppendVarint(b, v)
2082 return b, nil
2083}
2084
Damien Neile91877d2019-06-27 10:54:42 -07002085// consumeUint64 wire decodes a uint64 pointer as a Uint64.
2086func consumeUint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2087 if wtyp != wire.VarintType {
2088 return 0, errUnknown
2089 }
2090 v, n := wire.ConsumeVarint(b)
2091 if n < 0 {
2092 return 0, wire.ParseError(n)
2093 }
2094 *p.Uint64() = v
2095 return n, nil
2096}
2097
Damien Neilc37adef2019-04-01 13:49:56 -07002098var coderUint64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002099 size: sizeUint64,
2100 marshal: appendUint64,
2101 unmarshal: consumeUint64,
Damien Neilc37adef2019-04-01 13:49:56 -07002102}
2103
Joe Tsaic51e2e02019-07-13 00:44:41 -07002104// sizeUint64NoZero returns the size of wire encoding a uint64 pointer as a Uint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002105// The zero value is not encoded.
2106func sizeUint64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
2107 v := *p.Uint64()
2108 if v == 0 {
2109 return 0
2110 }
2111 return tagsize + wire.SizeVarint(v)
2112}
2113
Joe Tsaic51e2e02019-07-13 00:44:41 -07002114// appendUint64NoZero wire encodes a uint64 pointer as a Uint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002115// The zero value is not encoded.
2116func appendUint64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2117 v := *p.Uint64()
2118 if v == 0 {
2119 return b, nil
2120 }
2121 b = wire.AppendVarint(b, wiretag)
2122 b = wire.AppendVarint(b, v)
2123 return b, nil
2124}
2125
2126var coderUint64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002127 size: sizeUint64NoZero,
2128 marshal: appendUint64NoZero,
2129 unmarshal: consumeUint64,
Damien Neilc37adef2019-04-01 13:49:56 -07002130}
2131
2132// sizeUint64Ptr returns the size of wire encoding a *uint64 pointer as a Uint64.
2133// It panics if the pointer is nil.
2134func sizeUint64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
2135 v := **p.Uint64Ptr()
2136 return tagsize + wire.SizeVarint(v)
2137}
2138
Damien Neile91877d2019-06-27 10:54:42 -07002139// appendUint64Ptr wire encodes a *uint64 pointer as a Uint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002140// It panics if the pointer is nil.
2141func appendUint64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2142 v := **p.Uint64Ptr()
2143 b = wire.AppendVarint(b, wiretag)
2144 b = wire.AppendVarint(b, v)
2145 return b, nil
2146}
2147
Damien Neile91877d2019-06-27 10:54:42 -07002148// consumeUint64Ptr wire decodes a *uint64 pointer as a Uint64.
2149func consumeUint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2150 if wtyp != wire.VarintType {
2151 return 0, errUnknown
2152 }
2153 v, n := wire.ConsumeVarint(b)
2154 if n < 0 {
2155 return 0, wire.ParseError(n)
2156 }
2157 vp := p.Uint64Ptr()
2158 if *vp == nil {
2159 *vp = new(uint64)
2160 }
2161 **vp = v
2162 return n, nil
2163}
2164
Damien Neilc37adef2019-04-01 13:49:56 -07002165var coderUint64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002166 size: sizeUint64Ptr,
2167 marshal: appendUint64Ptr,
2168 unmarshal: consumeUint64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07002169}
2170
2171// sizeUint64Slice returns the size of wire encoding a []uint64 pointer as a repeated Uint64.
2172func sizeUint64Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
2173 s := *p.Uint64Slice()
2174 for _, v := range s {
2175 size += tagsize + wire.SizeVarint(v)
2176 }
2177 return size
2178}
2179
2180// appendUint64Slice encodes a []uint64 pointer as a repeated Uint64.
2181func appendUint64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2182 s := *p.Uint64Slice()
2183 for _, v := range s {
2184 b = wire.AppendVarint(b, wiretag)
2185 b = wire.AppendVarint(b, v)
2186 }
2187 return b, nil
2188}
2189
Damien Neile91877d2019-06-27 10:54:42 -07002190// consumeUint64Slice wire decodes a []uint64 pointer as a repeated Uint64.
2191func consumeUint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2192 sp := p.Uint64Slice()
2193 if wtyp == wire.BytesType {
2194 s := *sp
2195 b, n = wire.ConsumeBytes(b)
2196 if n < 0 {
2197 return 0, wire.ParseError(n)
2198 }
2199 for len(b) > 0 {
2200 v, n := wire.ConsumeVarint(b)
2201 if n < 0 {
2202 return 0, wire.ParseError(n)
2203 }
2204 s = append(s, v)
2205 b = b[n:]
2206 }
2207 *sp = s
2208 return n, nil
2209 }
2210 if wtyp != wire.VarintType {
2211 return 0, errUnknown
2212 }
2213 v, n := wire.ConsumeVarint(b)
2214 if n < 0 {
2215 return 0, wire.ParseError(n)
2216 }
2217 *sp = append(*sp, v)
2218 return n, nil
2219}
2220
Damien Neilc37adef2019-04-01 13:49:56 -07002221var coderUint64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002222 size: sizeUint64Slice,
2223 marshal: appendUint64Slice,
2224 unmarshal: consumeUint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002225}
2226
2227// sizeUint64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Uint64.
2228func sizeUint64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
2229 s := *p.Uint64Slice()
2230 if len(s) == 0 {
2231 return 0
2232 }
2233 n := 0
2234 for _, v := range s {
2235 n += wire.SizeVarint(v)
2236 }
2237 return tagsize + wire.SizeBytes(n)
2238}
2239
2240// appendUint64PackedSlice encodes a []uint64 pointer as a packed repeated Uint64.
2241func appendUint64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2242 s := *p.Uint64Slice()
2243 if len(s) == 0 {
2244 return b, nil
2245 }
2246 b = wire.AppendVarint(b, wiretag)
2247 n := 0
2248 for _, v := range s {
2249 n += wire.SizeVarint(v)
2250 }
2251 b = wire.AppendVarint(b, uint64(n))
2252 for _, v := range s {
2253 b = wire.AppendVarint(b, v)
2254 }
2255 return b, nil
2256}
2257
2258var coderUint64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002259 size: sizeUint64PackedSlice,
2260 marshal: appendUint64PackedSlice,
2261 unmarshal: consumeUint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002262}
2263
Damien Neil68b81c32019-08-22 11:41:32 -07002264// sizeUint64Value returns the size of wire encoding a uint64 value as a Uint64.
2265func sizeUint64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
2266 return tagsize + wire.SizeVarint(v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002267}
2268
Damien Neil68b81c32019-08-22 11:41:32 -07002269// appendUint64Value encodes a uint64 value as a Uint64.
2270func appendUint64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002271 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002272 b = wire.AppendVarint(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002273 return b, nil
2274}
2275
Damien Neil68b81c32019-08-22 11:41:32 -07002276// consumeUint64Value decodes a uint64 value as a Uint64.
2277func consumeUint64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07002278 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07002279 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002280 }
2281 v, n := wire.ConsumeVarint(b)
2282 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002283 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002284 }
Damien Neil68b81c32019-08-22 11:41:32 -07002285 return protoreflect.ValueOfUint64(v), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002286}
2287
Damien Neil68b81c32019-08-22 11:41:32 -07002288var coderUint64Value = valueCoderFuncs{
2289 size: sizeUint64Value,
2290 marshal: appendUint64Value,
2291 unmarshal: consumeUint64Value,
Damien Neilc37adef2019-04-01 13:49:56 -07002292}
2293
Damien Neil68b81c32019-08-22 11:41:32 -07002294// sizeUint64SliceValue returns the size of wire encoding a []uint64 value as a repeated Uint64.
2295func sizeUint64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2296 list := listv.List()
2297 for i, llen := 0, list.Len(); i < llen; i++ {
2298 v := list.Get(i)
2299 size += tagsize + wire.SizeVarint(v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002300 }
2301 return size
2302}
2303
Damien Neil68b81c32019-08-22 11:41:32 -07002304// appendUint64SliceValue encodes a []uint64 value as a repeated Uint64.
2305func appendUint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2306 list := listv.List()
2307 for i, llen := 0, list.Len(); i < llen; i++ {
2308 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07002309 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002310 b = wire.AppendVarint(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002311 }
2312 return b, nil
2313}
2314
Damien Neil68b81c32019-08-22 11:41:32 -07002315// consumeUint64SliceValue wire decodes a []uint64 value as a repeated Uint64.
2316func consumeUint64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
2317 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07002318 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07002319 b, n = wire.ConsumeBytes(b)
2320 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002321 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002322 }
2323 for len(b) > 0 {
2324 v, n := wire.ConsumeVarint(b)
2325 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002326 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002327 }
Damien Neil68b81c32019-08-22 11:41:32 -07002328 list.Append(protoreflect.ValueOfUint64(v))
Damien Neile91877d2019-06-27 10:54:42 -07002329 b = b[n:]
2330 }
Damien Neil68b81c32019-08-22 11:41:32 -07002331 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002332 }
2333 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07002334 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002335 }
2336 v, n := wire.ConsumeVarint(b)
2337 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002338 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002339 }
Damien Neil68b81c32019-08-22 11:41:32 -07002340 list.Append(protoreflect.ValueOfUint64(v))
2341 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002342}
2343
Damien Neil68b81c32019-08-22 11:41:32 -07002344var coderUint64SliceValue = valueCoderFuncs{
2345 size: sizeUint64SliceValue,
2346 marshal: appendUint64SliceValue,
2347 unmarshal: consumeUint64SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002348}
2349
Damien Neil68b81c32019-08-22 11:41:32 -07002350// sizeUint64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Uint64.
2351func sizeUint64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2352 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08002353 llen := list.Len()
2354 if llen == 0 {
2355 return 0
2356 }
Damien Neil7492a092019-07-10 15:23:29 -07002357 n := 0
Damien Neil2c0824b2019-12-20 12:21:25 -08002358 for i, llen := 0, llen; i < llen; i++ {
Damien Neil68b81c32019-08-22 11:41:32 -07002359 v := list.Get(i)
2360 n += wire.SizeVarint(v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07002361 }
2362 return tagsize + wire.SizeBytes(n)
2363}
2364
Damien Neil68b81c32019-08-22 11:41:32 -07002365// appendUint64PackedSliceValue encodes a []uint64 value as a packed repeated Uint64.
2366func appendUint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2367 list := listv.List()
2368 llen := list.Len()
2369 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07002370 return b, nil
2371 }
2372 b = wire.AppendVarint(b, wiretag)
2373 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07002374 for i := 0; i < llen; i++ {
2375 v := list.Get(i)
2376 n += wire.SizeVarint(v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07002377 }
2378 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07002379 for i := 0; i < llen; i++ {
2380 v := list.Get(i)
2381 b = wire.AppendVarint(b, v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07002382 }
2383 return b, nil
2384}
2385
Damien Neil68b81c32019-08-22 11:41:32 -07002386var coderUint64PackedSliceValue = valueCoderFuncs{
2387 size: sizeUint64PackedSliceValue,
2388 marshal: appendUint64PackedSliceValue,
2389 unmarshal: consumeUint64SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07002390}
2391
Damien Neilc37adef2019-04-01 13:49:56 -07002392// sizeSfixed32 returns the size of wire encoding a int32 pointer as a Sfixed32.
2393func sizeSfixed32(p pointer, tagsize int, _ marshalOptions) (size int) {
2394
2395 return tagsize + wire.SizeFixed32()
2396}
2397
2398// appendSfixed32 wire encodes a int32 pointer as a Sfixed32.
2399func appendSfixed32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2400 v := *p.Int32()
2401 b = wire.AppendVarint(b, wiretag)
2402 b = wire.AppendFixed32(b, uint32(v))
2403 return b, nil
2404}
2405
Damien Neile91877d2019-06-27 10:54:42 -07002406// consumeSfixed32 wire decodes a int32 pointer as a Sfixed32.
2407func consumeSfixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2408 if wtyp != wire.Fixed32Type {
2409 return 0, errUnknown
2410 }
2411 v, n := wire.ConsumeFixed32(b)
2412 if n < 0 {
2413 return 0, wire.ParseError(n)
2414 }
2415 *p.Int32() = int32(v)
2416 return n, nil
2417}
2418
Damien Neilc37adef2019-04-01 13:49:56 -07002419var coderSfixed32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002420 size: sizeSfixed32,
2421 marshal: appendSfixed32,
2422 unmarshal: consumeSfixed32,
Damien Neilc37adef2019-04-01 13:49:56 -07002423}
2424
Joe Tsaic51e2e02019-07-13 00:44:41 -07002425// sizeSfixed32NoZero returns the size of wire encoding a int32 pointer as a Sfixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002426// The zero value is not encoded.
2427func sizeSfixed32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
2428 v := *p.Int32()
2429 if v == 0 {
2430 return 0
2431 }
2432 return tagsize + wire.SizeFixed32()
2433}
2434
Joe Tsaic51e2e02019-07-13 00:44:41 -07002435// appendSfixed32NoZero wire encodes a int32 pointer as a Sfixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002436// The zero value is not encoded.
2437func appendSfixed32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2438 v := *p.Int32()
2439 if v == 0 {
2440 return b, nil
2441 }
2442 b = wire.AppendVarint(b, wiretag)
2443 b = wire.AppendFixed32(b, uint32(v))
2444 return b, nil
2445}
2446
2447var coderSfixed32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002448 size: sizeSfixed32NoZero,
2449 marshal: appendSfixed32NoZero,
2450 unmarshal: consumeSfixed32,
Damien Neilc37adef2019-04-01 13:49:56 -07002451}
2452
2453// sizeSfixed32Ptr returns the size of wire encoding a *int32 pointer as a Sfixed32.
2454// It panics if the pointer is nil.
2455func sizeSfixed32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
2456 return tagsize + wire.SizeFixed32()
2457}
2458
Damien Neile91877d2019-06-27 10:54:42 -07002459// appendSfixed32Ptr wire encodes a *int32 pointer as a Sfixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002460// It panics if the pointer is nil.
2461func appendSfixed32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2462 v := **p.Int32Ptr()
2463 b = wire.AppendVarint(b, wiretag)
2464 b = wire.AppendFixed32(b, uint32(v))
2465 return b, nil
2466}
2467
Damien Neile91877d2019-06-27 10:54:42 -07002468// consumeSfixed32Ptr wire decodes a *int32 pointer as a Sfixed32.
2469func consumeSfixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2470 if wtyp != wire.Fixed32Type {
2471 return 0, errUnknown
2472 }
2473 v, n := wire.ConsumeFixed32(b)
2474 if n < 0 {
2475 return 0, wire.ParseError(n)
2476 }
2477 vp := p.Int32Ptr()
2478 if *vp == nil {
2479 *vp = new(int32)
2480 }
2481 **vp = int32(v)
2482 return n, nil
2483}
2484
Damien Neilc37adef2019-04-01 13:49:56 -07002485var coderSfixed32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002486 size: sizeSfixed32Ptr,
2487 marshal: appendSfixed32Ptr,
2488 unmarshal: consumeSfixed32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07002489}
2490
2491// sizeSfixed32Slice returns the size of wire encoding a []int32 pointer as a repeated Sfixed32.
2492func sizeSfixed32Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
2493 s := *p.Int32Slice()
2494 size = len(s) * (tagsize + wire.SizeFixed32())
2495 return size
2496}
2497
2498// appendSfixed32Slice encodes a []int32 pointer as a repeated Sfixed32.
2499func appendSfixed32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2500 s := *p.Int32Slice()
2501 for _, v := range s {
2502 b = wire.AppendVarint(b, wiretag)
2503 b = wire.AppendFixed32(b, uint32(v))
2504 }
2505 return b, nil
2506}
2507
Damien Neile91877d2019-06-27 10:54:42 -07002508// consumeSfixed32Slice wire decodes a []int32 pointer as a repeated Sfixed32.
2509func consumeSfixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2510 sp := p.Int32Slice()
2511 if wtyp == wire.BytesType {
2512 s := *sp
2513 b, n = wire.ConsumeBytes(b)
2514 if n < 0 {
2515 return 0, wire.ParseError(n)
2516 }
2517 for len(b) > 0 {
2518 v, n := wire.ConsumeFixed32(b)
2519 if n < 0 {
2520 return 0, wire.ParseError(n)
2521 }
2522 s = append(s, int32(v))
2523 b = b[n:]
2524 }
2525 *sp = s
2526 return n, nil
2527 }
2528 if wtyp != wire.Fixed32Type {
2529 return 0, errUnknown
2530 }
2531 v, n := wire.ConsumeFixed32(b)
2532 if n < 0 {
2533 return 0, wire.ParseError(n)
2534 }
2535 *sp = append(*sp, int32(v))
2536 return n, nil
2537}
2538
Damien Neilc37adef2019-04-01 13:49:56 -07002539var coderSfixed32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002540 size: sizeSfixed32Slice,
2541 marshal: appendSfixed32Slice,
2542 unmarshal: consumeSfixed32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002543}
2544
2545// sizeSfixed32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sfixed32.
2546func sizeSfixed32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
2547 s := *p.Int32Slice()
2548 if len(s) == 0 {
2549 return 0
2550 }
2551 n := len(s) * wire.SizeFixed32()
2552 return tagsize + wire.SizeBytes(n)
2553}
2554
2555// appendSfixed32PackedSlice encodes a []int32 pointer as a packed repeated Sfixed32.
2556func appendSfixed32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2557 s := *p.Int32Slice()
2558 if len(s) == 0 {
2559 return b, nil
2560 }
2561 b = wire.AppendVarint(b, wiretag)
2562 n := len(s) * wire.SizeFixed32()
2563 b = wire.AppendVarint(b, uint64(n))
2564 for _, v := range s {
2565 b = wire.AppendFixed32(b, uint32(v))
2566 }
2567 return b, nil
2568}
2569
2570var coderSfixed32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002571 size: sizeSfixed32PackedSlice,
2572 marshal: appendSfixed32PackedSlice,
2573 unmarshal: consumeSfixed32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002574}
2575
Damien Neil68b81c32019-08-22 11:41:32 -07002576// sizeSfixed32Value returns the size of wire encoding a int32 value as a Sfixed32.
2577func sizeSfixed32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07002578 return tagsize + wire.SizeFixed32()
2579}
2580
Damien Neil68b81c32019-08-22 11:41:32 -07002581// appendSfixed32Value encodes a int32 value as a Sfixed32.
2582func appendSfixed32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002583 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002584 b = wire.AppendFixed32(b, uint32(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002585 return b, nil
2586}
2587
Damien Neil68b81c32019-08-22 11:41:32 -07002588// consumeSfixed32Value decodes a int32 value as a Sfixed32.
2589func consumeSfixed32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07002590 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07002591 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002592 }
2593 v, n := wire.ConsumeFixed32(b)
2594 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002595 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002596 }
Damien Neil68b81c32019-08-22 11:41:32 -07002597 return protoreflect.ValueOfInt32(int32(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002598}
2599
Damien Neil68b81c32019-08-22 11:41:32 -07002600var coderSfixed32Value = valueCoderFuncs{
2601 size: sizeSfixed32Value,
2602 marshal: appendSfixed32Value,
2603 unmarshal: consumeSfixed32Value,
Damien Neilc37adef2019-04-01 13:49:56 -07002604}
2605
Damien Neil68b81c32019-08-22 11:41:32 -07002606// sizeSfixed32SliceValue returns the size of wire encoding a []int32 value as a repeated Sfixed32.
2607func sizeSfixed32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2608 list := listv.List()
2609 size = list.Len() * (tagsize + wire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07002610 return size
2611}
2612
Damien Neil68b81c32019-08-22 11:41:32 -07002613// appendSfixed32SliceValue encodes a []int32 value as a repeated Sfixed32.
2614func appendSfixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2615 list := listv.List()
2616 for i, llen := 0, list.Len(); i < llen; i++ {
2617 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07002618 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002619 b = wire.AppendFixed32(b, uint32(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002620 }
2621 return b, nil
2622}
2623
Damien Neil68b81c32019-08-22 11:41:32 -07002624// consumeSfixed32SliceValue wire decodes a []int32 value as a repeated Sfixed32.
2625func consumeSfixed32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
2626 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07002627 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07002628 b, n = wire.ConsumeBytes(b)
2629 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002630 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002631 }
2632 for len(b) > 0 {
2633 v, n := wire.ConsumeFixed32(b)
2634 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002635 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002636 }
Damien Neil68b81c32019-08-22 11:41:32 -07002637 list.Append(protoreflect.ValueOfInt32(int32(v)))
Damien Neile91877d2019-06-27 10:54:42 -07002638 b = b[n:]
2639 }
Damien Neil68b81c32019-08-22 11:41:32 -07002640 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002641 }
2642 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07002643 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002644 }
2645 v, n := wire.ConsumeFixed32(b)
2646 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002647 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002648 }
Damien Neil68b81c32019-08-22 11:41:32 -07002649 list.Append(protoreflect.ValueOfInt32(int32(v)))
2650 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002651}
2652
Damien Neil68b81c32019-08-22 11:41:32 -07002653var coderSfixed32SliceValue = valueCoderFuncs{
2654 size: sizeSfixed32SliceValue,
2655 marshal: appendSfixed32SliceValue,
2656 unmarshal: consumeSfixed32SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002657}
2658
Damien Neil68b81c32019-08-22 11:41:32 -07002659// sizeSfixed32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sfixed32.
2660func sizeSfixed32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2661 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08002662 llen := list.Len()
2663 if llen == 0 {
2664 return 0
2665 }
2666 n := llen * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07002667 return tagsize + wire.SizeBytes(n)
2668}
2669
Damien Neil68b81c32019-08-22 11:41:32 -07002670// appendSfixed32PackedSliceValue encodes a []int32 value as a packed repeated Sfixed32.
2671func appendSfixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2672 list := listv.List()
2673 llen := list.Len()
2674 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07002675 return b, nil
2676 }
2677 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002678 n := llen * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07002679 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07002680 for i := 0; i < llen; i++ {
2681 v := list.Get(i)
2682 b = wire.AppendFixed32(b, uint32(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002683 }
2684 return b, nil
2685}
2686
Damien Neil68b81c32019-08-22 11:41:32 -07002687var coderSfixed32PackedSliceValue = valueCoderFuncs{
2688 size: sizeSfixed32PackedSliceValue,
2689 marshal: appendSfixed32PackedSliceValue,
2690 unmarshal: consumeSfixed32SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07002691}
2692
Damien Neilc37adef2019-04-01 13:49:56 -07002693// sizeFixed32 returns the size of wire encoding a uint32 pointer as a Fixed32.
2694func sizeFixed32(p pointer, tagsize int, _ marshalOptions) (size int) {
2695
2696 return tagsize + wire.SizeFixed32()
2697}
2698
2699// appendFixed32 wire encodes a uint32 pointer as a Fixed32.
2700func appendFixed32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2701 v := *p.Uint32()
2702 b = wire.AppendVarint(b, wiretag)
2703 b = wire.AppendFixed32(b, v)
2704 return b, nil
2705}
2706
Damien Neile91877d2019-06-27 10:54:42 -07002707// consumeFixed32 wire decodes a uint32 pointer as a Fixed32.
2708func consumeFixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2709 if wtyp != wire.Fixed32Type {
2710 return 0, errUnknown
2711 }
2712 v, n := wire.ConsumeFixed32(b)
2713 if n < 0 {
2714 return 0, wire.ParseError(n)
2715 }
2716 *p.Uint32() = v
2717 return n, nil
2718}
2719
Damien Neilc37adef2019-04-01 13:49:56 -07002720var coderFixed32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002721 size: sizeFixed32,
2722 marshal: appendFixed32,
2723 unmarshal: consumeFixed32,
Damien Neilc37adef2019-04-01 13:49:56 -07002724}
2725
Joe Tsaic51e2e02019-07-13 00:44:41 -07002726// sizeFixed32NoZero returns the size of wire encoding a uint32 pointer as a Fixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002727// The zero value is not encoded.
2728func sizeFixed32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
2729 v := *p.Uint32()
2730 if v == 0 {
2731 return 0
2732 }
2733 return tagsize + wire.SizeFixed32()
2734}
2735
Joe Tsaic51e2e02019-07-13 00:44:41 -07002736// appendFixed32NoZero wire encodes a uint32 pointer as a Fixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002737// The zero value is not encoded.
2738func appendFixed32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2739 v := *p.Uint32()
2740 if v == 0 {
2741 return b, nil
2742 }
2743 b = wire.AppendVarint(b, wiretag)
2744 b = wire.AppendFixed32(b, v)
2745 return b, nil
2746}
2747
2748var coderFixed32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002749 size: sizeFixed32NoZero,
2750 marshal: appendFixed32NoZero,
2751 unmarshal: consumeFixed32,
Damien Neilc37adef2019-04-01 13:49:56 -07002752}
2753
2754// sizeFixed32Ptr returns the size of wire encoding a *uint32 pointer as a Fixed32.
2755// It panics if the pointer is nil.
2756func sizeFixed32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
2757 return tagsize + wire.SizeFixed32()
2758}
2759
Damien Neile91877d2019-06-27 10:54:42 -07002760// appendFixed32Ptr wire encodes a *uint32 pointer as a Fixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002761// It panics if the pointer is nil.
2762func appendFixed32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2763 v := **p.Uint32Ptr()
2764 b = wire.AppendVarint(b, wiretag)
2765 b = wire.AppendFixed32(b, v)
2766 return b, nil
2767}
2768
Damien Neile91877d2019-06-27 10:54:42 -07002769// consumeFixed32Ptr wire decodes a *uint32 pointer as a Fixed32.
2770func consumeFixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2771 if wtyp != wire.Fixed32Type {
2772 return 0, errUnknown
2773 }
2774 v, n := wire.ConsumeFixed32(b)
2775 if n < 0 {
2776 return 0, wire.ParseError(n)
2777 }
2778 vp := p.Uint32Ptr()
2779 if *vp == nil {
2780 *vp = new(uint32)
2781 }
2782 **vp = v
2783 return n, nil
2784}
2785
Damien Neilc37adef2019-04-01 13:49:56 -07002786var coderFixed32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002787 size: sizeFixed32Ptr,
2788 marshal: appendFixed32Ptr,
2789 unmarshal: consumeFixed32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07002790}
2791
2792// sizeFixed32Slice returns the size of wire encoding a []uint32 pointer as a repeated Fixed32.
2793func sizeFixed32Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
2794 s := *p.Uint32Slice()
2795 size = len(s) * (tagsize + wire.SizeFixed32())
2796 return size
2797}
2798
2799// appendFixed32Slice encodes a []uint32 pointer as a repeated Fixed32.
2800func appendFixed32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2801 s := *p.Uint32Slice()
2802 for _, v := range s {
2803 b = wire.AppendVarint(b, wiretag)
2804 b = wire.AppendFixed32(b, v)
2805 }
2806 return b, nil
2807}
2808
Damien Neile91877d2019-06-27 10:54:42 -07002809// consumeFixed32Slice wire decodes a []uint32 pointer as a repeated Fixed32.
2810func consumeFixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2811 sp := p.Uint32Slice()
2812 if wtyp == wire.BytesType {
2813 s := *sp
2814 b, n = wire.ConsumeBytes(b)
2815 if n < 0 {
2816 return 0, wire.ParseError(n)
2817 }
2818 for len(b) > 0 {
2819 v, n := wire.ConsumeFixed32(b)
2820 if n < 0 {
2821 return 0, wire.ParseError(n)
2822 }
2823 s = append(s, v)
2824 b = b[n:]
2825 }
2826 *sp = s
2827 return n, nil
2828 }
2829 if wtyp != wire.Fixed32Type {
2830 return 0, errUnknown
2831 }
2832 v, n := wire.ConsumeFixed32(b)
2833 if n < 0 {
2834 return 0, wire.ParseError(n)
2835 }
2836 *sp = append(*sp, v)
2837 return n, nil
2838}
2839
Damien Neilc37adef2019-04-01 13:49:56 -07002840var coderFixed32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002841 size: sizeFixed32Slice,
2842 marshal: appendFixed32Slice,
2843 unmarshal: consumeFixed32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002844}
2845
2846// sizeFixed32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Fixed32.
2847func sizeFixed32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
2848 s := *p.Uint32Slice()
2849 if len(s) == 0 {
2850 return 0
2851 }
2852 n := len(s) * wire.SizeFixed32()
2853 return tagsize + wire.SizeBytes(n)
2854}
2855
2856// appendFixed32PackedSlice encodes a []uint32 pointer as a packed repeated Fixed32.
2857func appendFixed32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2858 s := *p.Uint32Slice()
2859 if len(s) == 0 {
2860 return b, nil
2861 }
2862 b = wire.AppendVarint(b, wiretag)
2863 n := len(s) * wire.SizeFixed32()
2864 b = wire.AppendVarint(b, uint64(n))
2865 for _, v := range s {
2866 b = wire.AppendFixed32(b, v)
2867 }
2868 return b, nil
2869}
2870
2871var coderFixed32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002872 size: sizeFixed32PackedSlice,
2873 marshal: appendFixed32PackedSlice,
2874 unmarshal: consumeFixed32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002875}
2876
Damien Neil68b81c32019-08-22 11:41:32 -07002877// sizeFixed32Value returns the size of wire encoding a uint32 value as a Fixed32.
2878func sizeFixed32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07002879 return tagsize + wire.SizeFixed32()
2880}
2881
Damien Neil68b81c32019-08-22 11:41:32 -07002882// appendFixed32Value encodes a uint32 value as a Fixed32.
2883func appendFixed32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002884 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002885 b = wire.AppendFixed32(b, uint32(v.Uint()))
Damien Neilc37adef2019-04-01 13:49:56 -07002886 return b, nil
2887}
2888
Damien Neil68b81c32019-08-22 11:41:32 -07002889// consumeFixed32Value decodes a uint32 value as a Fixed32.
2890func consumeFixed32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07002891 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07002892 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002893 }
2894 v, n := wire.ConsumeFixed32(b)
2895 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002896 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002897 }
Damien Neil68b81c32019-08-22 11:41:32 -07002898 return protoreflect.ValueOfUint32(uint32(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002899}
2900
Damien Neil68b81c32019-08-22 11:41:32 -07002901var coderFixed32Value = valueCoderFuncs{
2902 size: sizeFixed32Value,
2903 marshal: appendFixed32Value,
2904 unmarshal: consumeFixed32Value,
Damien Neilc37adef2019-04-01 13:49:56 -07002905}
2906
Damien Neil68b81c32019-08-22 11:41:32 -07002907// sizeFixed32SliceValue returns the size of wire encoding a []uint32 value as a repeated Fixed32.
2908func sizeFixed32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2909 list := listv.List()
2910 size = list.Len() * (tagsize + wire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07002911 return size
2912}
2913
Damien Neil68b81c32019-08-22 11:41:32 -07002914// appendFixed32SliceValue encodes a []uint32 value as a repeated Fixed32.
2915func appendFixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2916 list := listv.List()
2917 for i, llen := 0, list.Len(); i < llen; i++ {
2918 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07002919 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002920 b = wire.AppendFixed32(b, uint32(v.Uint()))
Damien Neilc37adef2019-04-01 13:49:56 -07002921 }
2922 return b, nil
2923}
2924
Damien Neil68b81c32019-08-22 11:41:32 -07002925// consumeFixed32SliceValue wire decodes a []uint32 value as a repeated Fixed32.
2926func consumeFixed32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
2927 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07002928 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07002929 b, n = wire.ConsumeBytes(b)
2930 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002931 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002932 }
2933 for len(b) > 0 {
2934 v, n := wire.ConsumeFixed32(b)
2935 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002936 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002937 }
Damien Neil68b81c32019-08-22 11:41:32 -07002938 list.Append(protoreflect.ValueOfUint32(uint32(v)))
Damien Neile91877d2019-06-27 10:54:42 -07002939 b = b[n:]
2940 }
Damien Neil68b81c32019-08-22 11:41:32 -07002941 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002942 }
2943 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07002944 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002945 }
2946 v, n := wire.ConsumeFixed32(b)
2947 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002948 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002949 }
Damien Neil68b81c32019-08-22 11:41:32 -07002950 list.Append(protoreflect.ValueOfUint32(uint32(v)))
2951 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002952}
2953
Damien Neil68b81c32019-08-22 11:41:32 -07002954var coderFixed32SliceValue = valueCoderFuncs{
2955 size: sizeFixed32SliceValue,
2956 marshal: appendFixed32SliceValue,
2957 unmarshal: consumeFixed32SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002958}
2959
Damien Neil68b81c32019-08-22 11:41:32 -07002960// sizeFixed32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Fixed32.
2961func sizeFixed32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2962 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08002963 llen := list.Len()
2964 if llen == 0 {
2965 return 0
2966 }
2967 n := llen * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07002968 return tagsize + wire.SizeBytes(n)
2969}
2970
Damien Neil68b81c32019-08-22 11:41:32 -07002971// appendFixed32PackedSliceValue encodes a []uint32 value as a packed repeated Fixed32.
2972func appendFixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2973 list := listv.List()
2974 llen := list.Len()
2975 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07002976 return b, nil
2977 }
2978 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002979 n := llen * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07002980 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07002981 for i := 0; i < llen; i++ {
2982 v := list.Get(i)
2983 b = wire.AppendFixed32(b, uint32(v.Uint()))
Damien Neil7492a092019-07-10 15:23:29 -07002984 }
2985 return b, nil
2986}
2987
Damien Neil68b81c32019-08-22 11:41:32 -07002988var coderFixed32PackedSliceValue = valueCoderFuncs{
2989 size: sizeFixed32PackedSliceValue,
2990 marshal: appendFixed32PackedSliceValue,
2991 unmarshal: consumeFixed32SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07002992}
2993
Damien Neilc37adef2019-04-01 13:49:56 -07002994// sizeFloat returns the size of wire encoding a float32 pointer as a Float.
2995func sizeFloat(p pointer, tagsize int, _ marshalOptions) (size int) {
2996
2997 return tagsize + wire.SizeFixed32()
2998}
2999
3000// appendFloat wire encodes a float32 pointer as a Float.
3001func appendFloat(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3002 v := *p.Float32()
3003 b = wire.AppendVarint(b, wiretag)
3004 b = wire.AppendFixed32(b, math.Float32bits(v))
3005 return b, nil
3006}
3007
Damien Neile91877d2019-06-27 10:54:42 -07003008// consumeFloat wire decodes a float32 pointer as a Float.
3009func consumeFloat(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3010 if wtyp != wire.Fixed32Type {
3011 return 0, errUnknown
3012 }
3013 v, n := wire.ConsumeFixed32(b)
3014 if n < 0 {
3015 return 0, wire.ParseError(n)
3016 }
3017 *p.Float32() = math.Float32frombits(v)
3018 return n, nil
3019}
3020
Damien Neilc37adef2019-04-01 13:49:56 -07003021var coderFloat = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003022 size: sizeFloat,
3023 marshal: appendFloat,
3024 unmarshal: consumeFloat,
Damien Neilc37adef2019-04-01 13:49:56 -07003025}
3026
Joe Tsaic51e2e02019-07-13 00:44:41 -07003027// sizeFloatNoZero returns the size of wire encoding a float32 pointer as a Float.
Damien Neilc37adef2019-04-01 13:49:56 -07003028// The zero value is not encoded.
3029func sizeFloatNoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
3030 v := *p.Float32()
3031 if v == 0 && !math.Signbit(float64(v)) {
3032 return 0
3033 }
3034 return tagsize + wire.SizeFixed32()
3035}
3036
Joe Tsaic51e2e02019-07-13 00:44:41 -07003037// appendFloatNoZero wire encodes a float32 pointer as a Float.
Damien Neilc37adef2019-04-01 13:49:56 -07003038// The zero value is not encoded.
3039func appendFloatNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3040 v := *p.Float32()
3041 if v == 0 && !math.Signbit(float64(v)) {
3042 return b, nil
3043 }
3044 b = wire.AppendVarint(b, wiretag)
3045 b = wire.AppendFixed32(b, math.Float32bits(v))
3046 return b, nil
3047}
3048
3049var coderFloatNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003050 size: sizeFloatNoZero,
3051 marshal: appendFloatNoZero,
3052 unmarshal: consumeFloat,
Damien Neilc37adef2019-04-01 13:49:56 -07003053}
3054
3055// sizeFloatPtr returns the size of wire encoding a *float32 pointer as a Float.
3056// It panics if the pointer is nil.
3057func sizeFloatPtr(p pointer, tagsize int, _ marshalOptions) (size int) {
3058 return tagsize + wire.SizeFixed32()
3059}
3060
Damien Neile91877d2019-06-27 10:54:42 -07003061// appendFloatPtr wire encodes a *float32 pointer as a Float.
Damien Neilc37adef2019-04-01 13:49:56 -07003062// It panics if the pointer is nil.
3063func appendFloatPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3064 v := **p.Float32Ptr()
3065 b = wire.AppendVarint(b, wiretag)
3066 b = wire.AppendFixed32(b, math.Float32bits(v))
3067 return b, nil
3068}
3069
Damien Neile91877d2019-06-27 10:54:42 -07003070// consumeFloatPtr wire decodes a *float32 pointer as a Float.
3071func consumeFloatPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3072 if wtyp != wire.Fixed32Type {
3073 return 0, errUnknown
3074 }
3075 v, n := wire.ConsumeFixed32(b)
3076 if n < 0 {
3077 return 0, wire.ParseError(n)
3078 }
3079 vp := p.Float32Ptr()
3080 if *vp == nil {
3081 *vp = new(float32)
3082 }
3083 **vp = math.Float32frombits(v)
3084 return n, nil
3085}
3086
Damien Neilc37adef2019-04-01 13:49:56 -07003087var coderFloatPtr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003088 size: sizeFloatPtr,
3089 marshal: appendFloatPtr,
3090 unmarshal: consumeFloatPtr,
Damien Neilc37adef2019-04-01 13:49:56 -07003091}
3092
3093// sizeFloatSlice returns the size of wire encoding a []float32 pointer as a repeated Float.
3094func sizeFloatSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
3095 s := *p.Float32Slice()
3096 size = len(s) * (tagsize + wire.SizeFixed32())
3097 return size
3098}
3099
3100// appendFloatSlice encodes a []float32 pointer as a repeated Float.
3101func appendFloatSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3102 s := *p.Float32Slice()
3103 for _, v := range s {
3104 b = wire.AppendVarint(b, wiretag)
3105 b = wire.AppendFixed32(b, math.Float32bits(v))
3106 }
3107 return b, nil
3108}
3109
Damien Neile91877d2019-06-27 10:54:42 -07003110// consumeFloatSlice wire decodes a []float32 pointer as a repeated Float.
3111func consumeFloatSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3112 sp := p.Float32Slice()
3113 if wtyp == wire.BytesType {
3114 s := *sp
3115 b, n = wire.ConsumeBytes(b)
3116 if n < 0 {
3117 return 0, wire.ParseError(n)
3118 }
3119 for len(b) > 0 {
3120 v, n := wire.ConsumeFixed32(b)
3121 if n < 0 {
3122 return 0, wire.ParseError(n)
3123 }
3124 s = append(s, math.Float32frombits(v))
3125 b = b[n:]
3126 }
3127 *sp = s
3128 return n, nil
3129 }
3130 if wtyp != wire.Fixed32Type {
3131 return 0, errUnknown
3132 }
3133 v, n := wire.ConsumeFixed32(b)
3134 if n < 0 {
3135 return 0, wire.ParseError(n)
3136 }
3137 *sp = append(*sp, math.Float32frombits(v))
3138 return n, nil
3139}
3140
Damien Neilc37adef2019-04-01 13:49:56 -07003141var coderFloatSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003142 size: sizeFloatSlice,
3143 marshal: appendFloatSlice,
3144 unmarshal: consumeFloatSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07003145}
3146
3147// sizeFloatPackedSlice returns the size of wire encoding a []float32 pointer as a packed repeated Float.
3148func sizeFloatPackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
3149 s := *p.Float32Slice()
3150 if len(s) == 0 {
3151 return 0
3152 }
3153 n := len(s) * wire.SizeFixed32()
3154 return tagsize + wire.SizeBytes(n)
3155}
3156
3157// appendFloatPackedSlice encodes a []float32 pointer as a packed repeated Float.
3158func appendFloatPackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3159 s := *p.Float32Slice()
3160 if len(s) == 0 {
3161 return b, nil
3162 }
3163 b = wire.AppendVarint(b, wiretag)
3164 n := len(s) * wire.SizeFixed32()
3165 b = wire.AppendVarint(b, uint64(n))
3166 for _, v := range s {
3167 b = wire.AppendFixed32(b, math.Float32bits(v))
3168 }
3169 return b, nil
3170}
3171
3172var coderFloatPackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003173 size: sizeFloatPackedSlice,
3174 marshal: appendFloatPackedSlice,
3175 unmarshal: consumeFloatSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07003176}
3177
Damien Neil68b81c32019-08-22 11:41:32 -07003178// sizeFloatValue returns the size of wire encoding a float32 value as a Float.
3179func sizeFloatValue(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07003180 return tagsize + wire.SizeFixed32()
3181}
3182
Damien Neil68b81c32019-08-22 11:41:32 -07003183// appendFloatValue encodes a float32 value as a Float.
3184func appendFloatValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003185 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003186 b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
Damien Neilc37adef2019-04-01 13:49:56 -07003187 return b, nil
3188}
3189
Damien Neil68b81c32019-08-22 11:41:32 -07003190// consumeFloatValue decodes a float32 value as a Float.
3191func consumeFloatValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07003192 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003193 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003194 }
3195 v, n := wire.ConsumeFixed32(b)
3196 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003197 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003198 }
Damien Neil68b81c32019-08-22 11:41:32 -07003199 return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003200}
3201
Damien Neil68b81c32019-08-22 11:41:32 -07003202var coderFloatValue = valueCoderFuncs{
3203 size: sizeFloatValue,
3204 marshal: appendFloatValue,
3205 unmarshal: consumeFloatValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003206}
3207
Damien Neil68b81c32019-08-22 11:41:32 -07003208// sizeFloatSliceValue returns the size of wire encoding a []float32 value as a repeated Float.
3209func sizeFloatSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3210 list := listv.List()
3211 size = list.Len() * (tagsize + wire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07003212 return size
3213}
3214
Damien Neil68b81c32019-08-22 11:41:32 -07003215// appendFloatSliceValue encodes a []float32 value as a repeated Float.
3216func appendFloatSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3217 list := listv.List()
3218 for i, llen := 0, list.Len(); i < llen; i++ {
3219 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07003220 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003221 b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
Damien Neilc37adef2019-04-01 13:49:56 -07003222 }
3223 return b, nil
3224}
3225
Damien Neil68b81c32019-08-22 11:41:32 -07003226// consumeFloatSliceValue wire decodes a []float32 value as a repeated Float.
3227func consumeFloatSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
3228 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07003229 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07003230 b, n = wire.ConsumeBytes(b)
3231 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003232 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003233 }
3234 for len(b) > 0 {
3235 v, n := wire.ConsumeFixed32(b)
3236 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003237 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003238 }
Damien Neil68b81c32019-08-22 11:41:32 -07003239 list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
Damien Neile91877d2019-06-27 10:54:42 -07003240 b = b[n:]
3241 }
Damien Neil68b81c32019-08-22 11:41:32 -07003242 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003243 }
3244 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003245 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003246 }
3247 v, n := wire.ConsumeFixed32(b)
3248 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003249 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003250 }
Damien Neil68b81c32019-08-22 11:41:32 -07003251 list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
3252 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003253}
3254
Damien Neil68b81c32019-08-22 11:41:32 -07003255var coderFloatSliceValue = valueCoderFuncs{
3256 size: sizeFloatSliceValue,
3257 marshal: appendFloatSliceValue,
3258 unmarshal: consumeFloatSliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003259}
3260
Damien Neil68b81c32019-08-22 11:41:32 -07003261// sizeFloatPackedSliceValue returns the size of wire encoding a []float32 value as a packed repeated Float.
3262func sizeFloatPackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3263 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08003264 llen := list.Len()
3265 if llen == 0 {
3266 return 0
3267 }
3268 n := llen * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07003269 return tagsize + wire.SizeBytes(n)
3270}
3271
Damien Neil68b81c32019-08-22 11:41:32 -07003272// appendFloatPackedSliceValue encodes a []float32 value as a packed repeated Float.
3273func appendFloatPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3274 list := listv.List()
3275 llen := list.Len()
3276 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07003277 return b, nil
3278 }
3279 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003280 n := llen * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07003281 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07003282 for i := 0; i < llen; i++ {
3283 v := list.Get(i)
3284 b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
Damien Neil7492a092019-07-10 15:23:29 -07003285 }
3286 return b, nil
3287}
3288
Damien Neil68b81c32019-08-22 11:41:32 -07003289var coderFloatPackedSliceValue = valueCoderFuncs{
3290 size: sizeFloatPackedSliceValue,
3291 marshal: appendFloatPackedSliceValue,
3292 unmarshal: consumeFloatSliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07003293}
3294
Damien Neilc37adef2019-04-01 13:49:56 -07003295// sizeSfixed64 returns the size of wire encoding a int64 pointer as a Sfixed64.
3296func sizeSfixed64(p pointer, tagsize int, _ marshalOptions) (size int) {
3297
3298 return tagsize + wire.SizeFixed64()
3299}
3300
3301// appendSfixed64 wire encodes a int64 pointer as a Sfixed64.
3302func appendSfixed64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3303 v := *p.Int64()
3304 b = wire.AppendVarint(b, wiretag)
3305 b = wire.AppendFixed64(b, uint64(v))
3306 return b, nil
3307}
3308
Damien Neile91877d2019-06-27 10:54:42 -07003309// consumeSfixed64 wire decodes a int64 pointer as a Sfixed64.
3310func consumeSfixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3311 if wtyp != wire.Fixed64Type {
3312 return 0, errUnknown
3313 }
3314 v, n := wire.ConsumeFixed64(b)
3315 if n < 0 {
3316 return 0, wire.ParseError(n)
3317 }
3318 *p.Int64() = int64(v)
3319 return n, nil
3320}
3321
Damien Neilc37adef2019-04-01 13:49:56 -07003322var coderSfixed64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003323 size: sizeSfixed64,
3324 marshal: appendSfixed64,
3325 unmarshal: consumeSfixed64,
Damien Neilc37adef2019-04-01 13:49:56 -07003326}
3327
Joe Tsaic51e2e02019-07-13 00:44:41 -07003328// sizeSfixed64NoZero returns the size of wire encoding a int64 pointer as a Sfixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003329// The zero value is not encoded.
3330func sizeSfixed64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
3331 v := *p.Int64()
3332 if v == 0 {
3333 return 0
3334 }
3335 return tagsize + wire.SizeFixed64()
3336}
3337
Joe Tsaic51e2e02019-07-13 00:44:41 -07003338// appendSfixed64NoZero wire encodes a int64 pointer as a Sfixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003339// The zero value is not encoded.
3340func appendSfixed64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3341 v := *p.Int64()
3342 if v == 0 {
3343 return b, nil
3344 }
3345 b = wire.AppendVarint(b, wiretag)
3346 b = wire.AppendFixed64(b, uint64(v))
3347 return b, nil
3348}
3349
3350var coderSfixed64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003351 size: sizeSfixed64NoZero,
3352 marshal: appendSfixed64NoZero,
3353 unmarshal: consumeSfixed64,
Damien Neilc37adef2019-04-01 13:49:56 -07003354}
3355
3356// sizeSfixed64Ptr returns the size of wire encoding a *int64 pointer as a Sfixed64.
3357// It panics if the pointer is nil.
3358func sizeSfixed64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
3359 return tagsize + wire.SizeFixed64()
3360}
3361
Damien Neile91877d2019-06-27 10:54:42 -07003362// appendSfixed64Ptr wire encodes a *int64 pointer as a Sfixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003363// It panics if the pointer is nil.
3364func appendSfixed64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3365 v := **p.Int64Ptr()
3366 b = wire.AppendVarint(b, wiretag)
3367 b = wire.AppendFixed64(b, uint64(v))
3368 return b, nil
3369}
3370
Damien Neile91877d2019-06-27 10:54:42 -07003371// consumeSfixed64Ptr wire decodes a *int64 pointer as a Sfixed64.
3372func consumeSfixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3373 if wtyp != wire.Fixed64Type {
3374 return 0, errUnknown
3375 }
3376 v, n := wire.ConsumeFixed64(b)
3377 if n < 0 {
3378 return 0, wire.ParseError(n)
3379 }
3380 vp := p.Int64Ptr()
3381 if *vp == nil {
3382 *vp = new(int64)
3383 }
3384 **vp = int64(v)
3385 return n, nil
3386}
3387
Damien Neilc37adef2019-04-01 13:49:56 -07003388var coderSfixed64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003389 size: sizeSfixed64Ptr,
3390 marshal: appendSfixed64Ptr,
3391 unmarshal: consumeSfixed64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07003392}
3393
3394// sizeSfixed64Slice returns the size of wire encoding a []int64 pointer as a repeated Sfixed64.
3395func sizeSfixed64Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
3396 s := *p.Int64Slice()
3397 size = len(s) * (tagsize + wire.SizeFixed64())
3398 return size
3399}
3400
3401// appendSfixed64Slice encodes a []int64 pointer as a repeated Sfixed64.
3402func appendSfixed64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3403 s := *p.Int64Slice()
3404 for _, v := range s {
3405 b = wire.AppendVarint(b, wiretag)
3406 b = wire.AppendFixed64(b, uint64(v))
3407 }
3408 return b, nil
3409}
3410
Damien Neile91877d2019-06-27 10:54:42 -07003411// consumeSfixed64Slice wire decodes a []int64 pointer as a repeated Sfixed64.
3412func consumeSfixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3413 sp := p.Int64Slice()
3414 if wtyp == wire.BytesType {
3415 s := *sp
3416 b, n = wire.ConsumeBytes(b)
3417 if n < 0 {
3418 return 0, wire.ParseError(n)
3419 }
3420 for len(b) > 0 {
3421 v, n := wire.ConsumeFixed64(b)
3422 if n < 0 {
3423 return 0, wire.ParseError(n)
3424 }
3425 s = append(s, int64(v))
3426 b = b[n:]
3427 }
3428 *sp = s
3429 return n, nil
3430 }
3431 if wtyp != wire.Fixed64Type {
3432 return 0, errUnknown
3433 }
3434 v, n := wire.ConsumeFixed64(b)
3435 if n < 0 {
3436 return 0, wire.ParseError(n)
3437 }
3438 *sp = append(*sp, int64(v))
3439 return n, nil
3440}
3441
Damien Neilc37adef2019-04-01 13:49:56 -07003442var coderSfixed64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003443 size: sizeSfixed64Slice,
3444 marshal: appendSfixed64Slice,
3445 unmarshal: consumeSfixed64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003446}
3447
3448// sizeSfixed64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sfixed64.
3449func sizeSfixed64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
3450 s := *p.Int64Slice()
3451 if len(s) == 0 {
3452 return 0
3453 }
3454 n := len(s) * wire.SizeFixed64()
3455 return tagsize + wire.SizeBytes(n)
3456}
3457
3458// appendSfixed64PackedSlice encodes a []int64 pointer as a packed repeated Sfixed64.
3459func appendSfixed64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3460 s := *p.Int64Slice()
3461 if len(s) == 0 {
3462 return b, nil
3463 }
3464 b = wire.AppendVarint(b, wiretag)
3465 n := len(s) * wire.SizeFixed64()
3466 b = wire.AppendVarint(b, uint64(n))
3467 for _, v := range s {
3468 b = wire.AppendFixed64(b, uint64(v))
3469 }
3470 return b, nil
3471}
3472
3473var coderSfixed64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003474 size: sizeSfixed64PackedSlice,
3475 marshal: appendSfixed64PackedSlice,
3476 unmarshal: consumeSfixed64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003477}
3478
Damien Neil68b81c32019-08-22 11:41:32 -07003479// sizeSfixed64Value returns the size of wire encoding a int64 value as a Sfixed64.
3480func sizeSfixed64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07003481 return tagsize + wire.SizeFixed64()
3482}
3483
Damien Neil68b81c32019-08-22 11:41:32 -07003484// appendSfixed64Value encodes a int64 value as a Sfixed64.
3485func appendSfixed64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003486 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003487 b = wire.AppendFixed64(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07003488 return b, nil
3489}
3490
Damien Neil68b81c32019-08-22 11:41:32 -07003491// consumeSfixed64Value decodes a int64 value as a Sfixed64.
3492func consumeSfixed64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07003493 if wtyp != wire.Fixed64Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003494 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003495 }
3496 v, n := wire.ConsumeFixed64(b)
3497 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003498 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003499 }
Damien Neil68b81c32019-08-22 11:41:32 -07003500 return protoreflect.ValueOfInt64(int64(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003501}
3502
Damien Neil68b81c32019-08-22 11:41:32 -07003503var coderSfixed64Value = valueCoderFuncs{
3504 size: sizeSfixed64Value,
3505 marshal: appendSfixed64Value,
3506 unmarshal: consumeSfixed64Value,
Damien Neilc37adef2019-04-01 13:49:56 -07003507}
3508
Damien Neil68b81c32019-08-22 11:41:32 -07003509// sizeSfixed64SliceValue returns the size of wire encoding a []int64 value as a repeated Sfixed64.
3510func sizeSfixed64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3511 list := listv.List()
3512 size = list.Len() * (tagsize + wire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07003513 return size
3514}
3515
Damien Neil68b81c32019-08-22 11:41:32 -07003516// appendSfixed64SliceValue encodes a []int64 value as a repeated Sfixed64.
3517func appendSfixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3518 list := listv.List()
3519 for i, llen := 0, list.Len(); i < llen; i++ {
3520 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07003521 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003522 b = wire.AppendFixed64(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07003523 }
3524 return b, nil
3525}
3526
Damien Neil68b81c32019-08-22 11:41:32 -07003527// consumeSfixed64SliceValue wire decodes a []int64 value as a repeated Sfixed64.
3528func consumeSfixed64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
3529 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07003530 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07003531 b, n = wire.ConsumeBytes(b)
3532 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003533 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003534 }
3535 for len(b) > 0 {
3536 v, n := wire.ConsumeFixed64(b)
3537 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003538 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003539 }
Damien Neil68b81c32019-08-22 11:41:32 -07003540 list.Append(protoreflect.ValueOfInt64(int64(v)))
Damien Neile91877d2019-06-27 10:54:42 -07003541 b = b[n:]
3542 }
Damien Neil68b81c32019-08-22 11:41:32 -07003543 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003544 }
3545 if wtyp != wire.Fixed64Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003546 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003547 }
3548 v, n := wire.ConsumeFixed64(b)
3549 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003550 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003551 }
Damien Neil68b81c32019-08-22 11:41:32 -07003552 list.Append(protoreflect.ValueOfInt64(int64(v)))
3553 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003554}
3555
Damien Neil68b81c32019-08-22 11:41:32 -07003556var coderSfixed64SliceValue = valueCoderFuncs{
3557 size: sizeSfixed64SliceValue,
3558 marshal: appendSfixed64SliceValue,
3559 unmarshal: consumeSfixed64SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003560}
3561
Damien Neil68b81c32019-08-22 11:41:32 -07003562// sizeSfixed64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sfixed64.
3563func sizeSfixed64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3564 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08003565 llen := list.Len()
3566 if llen == 0 {
3567 return 0
3568 }
3569 n := llen * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07003570 return tagsize + wire.SizeBytes(n)
3571}
3572
Damien Neil68b81c32019-08-22 11:41:32 -07003573// appendSfixed64PackedSliceValue encodes a []int64 value as a packed repeated Sfixed64.
3574func appendSfixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3575 list := listv.List()
3576 llen := list.Len()
3577 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07003578 return b, nil
3579 }
3580 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003581 n := llen * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07003582 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07003583 for i := 0; i < llen; i++ {
3584 v := list.Get(i)
3585 b = wire.AppendFixed64(b, uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07003586 }
3587 return b, nil
3588}
3589
Damien Neil68b81c32019-08-22 11:41:32 -07003590var coderSfixed64PackedSliceValue = valueCoderFuncs{
3591 size: sizeSfixed64PackedSliceValue,
3592 marshal: appendSfixed64PackedSliceValue,
3593 unmarshal: consumeSfixed64SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07003594}
3595
Damien Neilc37adef2019-04-01 13:49:56 -07003596// sizeFixed64 returns the size of wire encoding a uint64 pointer as a Fixed64.
3597func sizeFixed64(p pointer, tagsize int, _ marshalOptions) (size int) {
3598
3599 return tagsize + wire.SizeFixed64()
3600}
3601
3602// appendFixed64 wire encodes a uint64 pointer as a Fixed64.
3603func appendFixed64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3604 v := *p.Uint64()
3605 b = wire.AppendVarint(b, wiretag)
3606 b = wire.AppendFixed64(b, v)
3607 return b, nil
3608}
3609
Damien Neile91877d2019-06-27 10:54:42 -07003610// consumeFixed64 wire decodes a uint64 pointer as a Fixed64.
3611func consumeFixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3612 if wtyp != wire.Fixed64Type {
3613 return 0, errUnknown
3614 }
3615 v, n := wire.ConsumeFixed64(b)
3616 if n < 0 {
3617 return 0, wire.ParseError(n)
3618 }
3619 *p.Uint64() = v
3620 return n, nil
3621}
3622
Damien Neilc37adef2019-04-01 13:49:56 -07003623var coderFixed64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003624 size: sizeFixed64,
3625 marshal: appendFixed64,
3626 unmarshal: consumeFixed64,
Damien Neilc37adef2019-04-01 13:49:56 -07003627}
3628
Joe Tsaic51e2e02019-07-13 00:44:41 -07003629// sizeFixed64NoZero returns the size of wire encoding a uint64 pointer as a Fixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003630// The zero value is not encoded.
3631func sizeFixed64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
3632 v := *p.Uint64()
3633 if v == 0 {
3634 return 0
3635 }
3636 return tagsize + wire.SizeFixed64()
3637}
3638
Joe Tsaic51e2e02019-07-13 00:44:41 -07003639// appendFixed64NoZero wire encodes a uint64 pointer as a Fixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003640// The zero value is not encoded.
3641func appendFixed64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3642 v := *p.Uint64()
3643 if v == 0 {
3644 return b, nil
3645 }
3646 b = wire.AppendVarint(b, wiretag)
3647 b = wire.AppendFixed64(b, v)
3648 return b, nil
3649}
3650
3651var coderFixed64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003652 size: sizeFixed64NoZero,
3653 marshal: appendFixed64NoZero,
3654 unmarshal: consumeFixed64,
Damien Neilc37adef2019-04-01 13:49:56 -07003655}
3656
3657// sizeFixed64Ptr returns the size of wire encoding a *uint64 pointer as a Fixed64.
3658// It panics if the pointer is nil.
3659func sizeFixed64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
3660 return tagsize + wire.SizeFixed64()
3661}
3662
Damien Neile91877d2019-06-27 10:54:42 -07003663// appendFixed64Ptr wire encodes a *uint64 pointer as a Fixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003664// It panics if the pointer is nil.
3665func appendFixed64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3666 v := **p.Uint64Ptr()
3667 b = wire.AppendVarint(b, wiretag)
3668 b = wire.AppendFixed64(b, v)
3669 return b, nil
3670}
3671
Damien Neile91877d2019-06-27 10:54:42 -07003672// consumeFixed64Ptr wire decodes a *uint64 pointer as a Fixed64.
3673func consumeFixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3674 if wtyp != wire.Fixed64Type {
3675 return 0, errUnknown
3676 }
3677 v, n := wire.ConsumeFixed64(b)
3678 if n < 0 {
3679 return 0, wire.ParseError(n)
3680 }
3681 vp := p.Uint64Ptr()
3682 if *vp == nil {
3683 *vp = new(uint64)
3684 }
3685 **vp = v
3686 return n, nil
3687}
3688
Damien Neilc37adef2019-04-01 13:49:56 -07003689var coderFixed64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003690 size: sizeFixed64Ptr,
3691 marshal: appendFixed64Ptr,
3692 unmarshal: consumeFixed64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07003693}
3694
3695// sizeFixed64Slice returns the size of wire encoding a []uint64 pointer as a repeated Fixed64.
3696func sizeFixed64Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
3697 s := *p.Uint64Slice()
3698 size = len(s) * (tagsize + wire.SizeFixed64())
3699 return size
3700}
3701
3702// appendFixed64Slice encodes a []uint64 pointer as a repeated Fixed64.
3703func appendFixed64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3704 s := *p.Uint64Slice()
3705 for _, v := range s {
3706 b = wire.AppendVarint(b, wiretag)
3707 b = wire.AppendFixed64(b, v)
3708 }
3709 return b, nil
3710}
3711
Damien Neile91877d2019-06-27 10:54:42 -07003712// consumeFixed64Slice wire decodes a []uint64 pointer as a repeated Fixed64.
3713func consumeFixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3714 sp := p.Uint64Slice()
3715 if wtyp == wire.BytesType {
3716 s := *sp
3717 b, n = wire.ConsumeBytes(b)
3718 if n < 0 {
3719 return 0, wire.ParseError(n)
3720 }
3721 for len(b) > 0 {
3722 v, n := wire.ConsumeFixed64(b)
3723 if n < 0 {
3724 return 0, wire.ParseError(n)
3725 }
3726 s = append(s, v)
3727 b = b[n:]
3728 }
3729 *sp = s
3730 return n, nil
3731 }
3732 if wtyp != wire.Fixed64Type {
3733 return 0, errUnknown
3734 }
3735 v, n := wire.ConsumeFixed64(b)
3736 if n < 0 {
3737 return 0, wire.ParseError(n)
3738 }
3739 *sp = append(*sp, v)
3740 return n, nil
3741}
3742
Damien Neilc37adef2019-04-01 13:49:56 -07003743var coderFixed64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003744 size: sizeFixed64Slice,
3745 marshal: appendFixed64Slice,
3746 unmarshal: consumeFixed64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003747}
3748
3749// sizeFixed64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Fixed64.
3750func sizeFixed64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
3751 s := *p.Uint64Slice()
3752 if len(s) == 0 {
3753 return 0
3754 }
3755 n := len(s) * wire.SizeFixed64()
3756 return tagsize + wire.SizeBytes(n)
3757}
3758
3759// appendFixed64PackedSlice encodes a []uint64 pointer as a packed repeated Fixed64.
3760func appendFixed64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3761 s := *p.Uint64Slice()
3762 if len(s) == 0 {
3763 return b, nil
3764 }
3765 b = wire.AppendVarint(b, wiretag)
3766 n := len(s) * wire.SizeFixed64()
3767 b = wire.AppendVarint(b, uint64(n))
3768 for _, v := range s {
3769 b = wire.AppendFixed64(b, v)
3770 }
3771 return b, nil
3772}
3773
3774var coderFixed64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003775 size: sizeFixed64PackedSlice,
3776 marshal: appendFixed64PackedSlice,
3777 unmarshal: consumeFixed64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003778}
3779
Damien Neil68b81c32019-08-22 11:41:32 -07003780// sizeFixed64Value returns the size of wire encoding a uint64 value as a Fixed64.
3781func sizeFixed64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07003782 return tagsize + wire.SizeFixed64()
3783}
3784
Damien Neil68b81c32019-08-22 11:41:32 -07003785// appendFixed64Value encodes a uint64 value as a Fixed64.
3786func appendFixed64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003787 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003788 b = wire.AppendFixed64(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07003789 return b, nil
3790}
3791
Damien Neil68b81c32019-08-22 11:41:32 -07003792// consumeFixed64Value decodes a uint64 value as a Fixed64.
3793func consumeFixed64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07003794 if wtyp != wire.Fixed64Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003795 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003796 }
3797 v, n := wire.ConsumeFixed64(b)
3798 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003799 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003800 }
Damien Neil68b81c32019-08-22 11:41:32 -07003801 return protoreflect.ValueOfUint64(v), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003802}
3803
Damien Neil68b81c32019-08-22 11:41:32 -07003804var coderFixed64Value = valueCoderFuncs{
3805 size: sizeFixed64Value,
3806 marshal: appendFixed64Value,
3807 unmarshal: consumeFixed64Value,
Damien Neilc37adef2019-04-01 13:49:56 -07003808}
3809
Damien Neil68b81c32019-08-22 11:41:32 -07003810// sizeFixed64SliceValue returns the size of wire encoding a []uint64 value as a repeated Fixed64.
3811func sizeFixed64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3812 list := listv.List()
3813 size = list.Len() * (tagsize + wire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07003814 return size
3815}
3816
Damien Neil68b81c32019-08-22 11:41:32 -07003817// appendFixed64SliceValue encodes a []uint64 value as a repeated Fixed64.
3818func appendFixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3819 list := listv.List()
3820 for i, llen := 0, list.Len(); i < llen; i++ {
3821 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07003822 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003823 b = wire.AppendFixed64(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07003824 }
3825 return b, nil
3826}
3827
Damien Neil68b81c32019-08-22 11:41:32 -07003828// consumeFixed64SliceValue wire decodes a []uint64 value as a repeated Fixed64.
3829func consumeFixed64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
3830 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07003831 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07003832 b, n = wire.ConsumeBytes(b)
3833 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003834 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003835 }
3836 for len(b) > 0 {
3837 v, n := wire.ConsumeFixed64(b)
3838 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003839 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003840 }
Damien Neil68b81c32019-08-22 11:41:32 -07003841 list.Append(protoreflect.ValueOfUint64(v))
Damien Neile91877d2019-06-27 10:54:42 -07003842 b = b[n:]
3843 }
Damien Neil68b81c32019-08-22 11:41:32 -07003844 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003845 }
3846 if wtyp != wire.Fixed64Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003847 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003848 }
3849 v, n := wire.ConsumeFixed64(b)
3850 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003851 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003852 }
Damien Neil68b81c32019-08-22 11:41:32 -07003853 list.Append(protoreflect.ValueOfUint64(v))
3854 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003855}
3856
Damien Neil68b81c32019-08-22 11:41:32 -07003857var coderFixed64SliceValue = valueCoderFuncs{
3858 size: sizeFixed64SliceValue,
3859 marshal: appendFixed64SliceValue,
3860 unmarshal: consumeFixed64SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003861}
3862
Damien Neil68b81c32019-08-22 11:41:32 -07003863// sizeFixed64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Fixed64.
3864func sizeFixed64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3865 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08003866 llen := list.Len()
3867 if llen == 0 {
3868 return 0
3869 }
3870 n := llen * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07003871 return tagsize + wire.SizeBytes(n)
3872}
3873
Damien Neil68b81c32019-08-22 11:41:32 -07003874// appendFixed64PackedSliceValue encodes a []uint64 value as a packed repeated Fixed64.
3875func appendFixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3876 list := listv.List()
3877 llen := list.Len()
3878 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07003879 return b, nil
3880 }
3881 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003882 n := llen * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07003883 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07003884 for i := 0; i < llen; i++ {
3885 v := list.Get(i)
3886 b = wire.AppendFixed64(b, v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07003887 }
3888 return b, nil
3889}
3890
Damien Neil68b81c32019-08-22 11:41:32 -07003891var coderFixed64PackedSliceValue = valueCoderFuncs{
3892 size: sizeFixed64PackedSliceValue,
3893 marshal: appendFixed64PackedSliceValue,
3894 unmarshal: consumeFixed64SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07003895}
3896
Damien Neilc37adef2019-04-01 13:49:56 -07003897// sizeDouble returns the size of wire encoding a float64 pointer as a Double.
3898func sizeDouble(p pointer, tagsize int, _ marshalOptions) (size int) {
3899
3900 return tagsize + wire.SizeFixed64()
3901}
3902
3903// appendDouble wire encodes a float64 pointer as a Double.
3904func appendDouble(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3905 v := *p.Float64()
3906 b = wire.AppendVarint(b, wiretag)
3907 b = wire.AppendFixed64(b, math.Float64bits(v))
3908 return b, nil
3909}
3910
Damien Neile91877d2019-06-27 10:54:42 -07003911// consumeDouble wire decodes a float64 pointer as a Double.
3912func consumeDouble(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3913 if wtyp != wire.Fixed64Type {
3914 return 0, errUnknown
3915 }
3916 v, n := wire.ConsumeFixed64(b)
3917 if n < 0 {
3918 return 0, wire.ParseError(n)
3919 }
3920 *p.Float64() = math.Float64frombits(v)
3921 return n, nil
3922}
3923
Damien Neilc37adef2019-04-01 13:49:56 -07003924var coderDouble = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003925 size: sizeDouble,
3926 marshal: appendDouble,
3927 unmarshal: consumeDouble,
Damien Neilc37adef2019-04-01 13:49:56 -07003928}
3929
Joe Tsaic51e2e02019-07-13 00:44:41 -07003930// sizeDoubleNoZero returns the size of wire encoding a float64 pointer as a Double.
Damien Neilc37adef2019-04-01 13:49:56 -07003931// The zero value is not encoded.
3932func sizeDoubleNoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
3933 v := *p.Float64()
3934 if v == 0 && !math.Signbit(float64(v)) {
3935 return 0
3936 }
3937 return tagsize + wire.SizeFixed64()
3938}
3939
Joe Tsaic51e2e02019-07-13 00:44:41 -07003940// appendDoubleNoZero wire encodes a float64 pointer as a Double.
Damien Neilc37adef2019-04-01 13:49:56 -07003941// The zero value is not encoded.
3942func appendDoubleNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3943 v := *p.Float64()
3944 if v == 0 && !math.Signbit(float64(v)) {
3945 return b, nil
3946 }
3947 b = wire.AppendVarint(b, wiretag)
3948 b = wire.AppendFixed64(b, math.Float64bits(v))
3949 return b, nil
3950}
3951
3952var coderDoubleNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003953 size: sizeDoubleNoZero,
3954 marshal: appendDoubleNoZero,
3955 unmarshal: consumeDouble,
Damien Neilc37adef2019-04-01 13:49:56 -07003956}
3957
3958// sizeDoublePtr returns the size of wire encoding a *float64 pointer as a Double.
3959// It panics if the pointer is nil.
3960func sizeDoublePtr(p pointer, tagsize int, _ marshalOptions) (size int) {
3961 return tagsize + wire.SizeFixed64()
3962}
3963
Damien Neile91877d2019-06-27 10:54:42 -07003964// appendDoublePtr wire encodes a *float64 pointer as a Double.
Damien Neilc37adef2019-04-01 13:49:56 -07003965// It panics if the pointer is nil.
3966func appendDoublePtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3967 v := **p.Float64Ptr()
3968 b = wire.AppendVarint(b, wiretag)
3969 b = wire.AppendFixed64(b, math.Float64bits(v))
3970 return b, nil
3971}
3972
Damien Neile91877d2019-06-27 10:54:42 -07003973// consumeDoublePtr wire decodes a *float64 pointer as a Double.
3974func consumeDoublePtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3975 if wtyp != wire.Fixed64Type {
3976 return 0, errUnknown
3977 }
3978 v, n := wire.ConsumeFixed64(b)
3979 if n < 0 {
3980 return 0, wire.ParseError(n)
3981 }
3982 vp := p.Float64Ptr()
3983 if *vp == nil {
3984 *vp = new(float64)
3985 }
3986 **vp = math.Float64frombits(v)
3987 return n, nil
3988}
3989
Damien Neilc37adef2019-04-01 13:49:56 -07003990var coderDoublePtr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003991 size: sizeDoublePtr,
3992 marshal: appendDoublePtr,
3993 unmarshal: consumeDoublePtr,
Damien Neilc37adef2019-04-01 13:49:56 -07003994}
3995
3996// sizeDoubleSlice returns the size of wire encoding a []float64 pointer as a repeated Double.
3997func sizeDoubleSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
3998 s := *p.Float64Slice()
3999 size = len(s) * (tagsize + wire.SizeFixed64())
4000 return size
4001}
4002
4003// appendDoubleSlice encodes a []float64 pointer as a repeated Double.
4004func appendDoubleSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4005 s := *p.Float64Slice()
4006 for _, v := range s {
4007 b = wire.AppendVarint(b, wiretag)
4008 b = wire.AppendFixed64(b, math.Float64bits(v))
4009 }
4010 return b, nil
4011}
4012
Damien Neile91877d2019-06-27 10:54:42 -07004013// consumeDoubleSlice wire decodes a []float64 pointer as a repeated Double.
4014func consumeDoubleSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4015 sp := p.Float64Slice()
4016 if wtyp == wire.BytesType {
4017 s := *sp
4018 b, n = wire.ConsumeBytes(b)
4019 if n < 0 {
4020 return 0, wire.ParseError(n)
4021 }
4022 for len(b) > 0 {
4023 v, n := wire.ConsumeFixed64(b)
4024 if n < 0 {
4025 return 0, wire.ParseError(n)
4026 }
4027 s = append(s, math.Float64frombits(v))
4028 b = b[n:]
4029 }
4030 *sp = s
4031 return n, nil
4032 }
4033 if wtyp != wire.Fixed64Type {
4034 return 0, errUnknown
4035 }
4036 v, n := wire.ConsumeFixed64(b)
4037 if n < 0 {
4038 return 0, wire.ParseError(n)
4039 }
4040 *sp = append(*sp, math.Float64frombits(v))
4041 return n, nil
4042}
4043
Damien Neilc37adef2019-04-01 13:49:56 -07004044var coderDoubleSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004045 size: sizeDoubleSlice,
4046 marshal: appendDoubleSlice,
4047 unmarshal: consumeDoubleSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07004048}
4049
4050// sizeDoublePackedSlice returns the size of wire encoding a []float64 pointer as a packed repeated Double.
4051func sizeDoublePackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
4052 s := *p.Float64Slice()
4053 if len(s) == 0 {
4054 return 0
4055 }
4056 n := len(s) * wire.SizeFixed64()
4057 return tagsize + wire.SizeBytes(n)
4058}
4059
4060// appendDoublePackedSlice encodes a []float64 pointer as a packed repeated Double.
4061func appendDoublePackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4062 s := *p.Float64Slice()
4063 if len(s) == 0 {
4064 return b, nil
4065 }
4066 b = wire.AppendVarint(b, wiretag)
4067 n := len(s) * wire.SizeFixed64()
4068 b = wire.AppendVarint(b, uint64(n))
4069 for _, v := range s {
4070 b = wire.AppendFixed64(b, math.Float64bits(v))
4071 }
4072 return b, nil
4073}
4074
4075var coderDoublePackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004076 size: sizeDoublePackedSlice,
4077 marshal: appendDoublePackedSlice,
4078 unmarshal: consumeDoubleSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07004079}
4080
Damien Neil68b81c32019-08-22 11:41:32 -07004081// sizeDoubleValue returns the size of wire encoding a float64 value as a Double.
4082func sizeDoubleValue(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07004083 return tagsize + wire.SizeFixed64()
4084}
4085
Damien Neil68b81c32019-08-22 11:41:32 -07004086// appendDoubleValue encodes a float64 value as a Double.
4087func appendDoubleValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004088 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004089 b = wire.AppendFixed64(b, math.Float64bits(v.Float()))
Damien Neilc37adef2019-04-01 13:49:56 -07004090 return b, nil
4091}
4092
Damien Neil68b81c32019-08-22 11:41:32 -07004093// consumeDoubleValue decodes a float64 value as a Double.
4094func consumeDoubleValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07004095 if wtyp != wire.Fixed64Type {
Damien Neil68b81c32019-08-22 11:41:32 -07004096 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004097 }
4098 v, n := wire.ConsumeFixed64(b)
4099 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004100 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004101 }
Damien Neil68b81c32019-08-22 11:41:32 -07004102 return protoreflect.ValueOfFloat64(math.Float64frombits(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004103}
4104
Damien Neil68b81c32019-08-22 11:41:32 -07004105var coderDoubleValue = valueCoderFuncs{
4106 size: sizeDoubleValue,
4107 marshal: appendDoubleValue,
4108 unmarshal: consumeDoubleValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004109}
4110
Damien Neil68b81c32019-08-22 11:41:32 -07004111// sizeDoubleSliceValue returns the size of wire encoding a []float64 value as a repeated Double.
4112func sizeDoubleSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
4113 list := listv.List()
4114 size = list.Len() * (tagsize + wire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07004115 return size
4116}
4117
Damien Neil68b81c32019-08-22 11:41:32 -07004118// appendDoubleSliceValue encodes a []float64 value as a repeated Double.
4119func appendDoubleSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
4120 list := listv.List()
4121 for i, llen := 0, list.Len(); i < llen; i++ {
4122 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07004123 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004124 b = wire.AppendFixed64(b, math.Float64bits(v.Float()))
Damien Neilc37adef2019-04-01 13:49:56 -07004125 }
4126 return b, nil
4127}
4128
Damien Neil68b81c32019-08-22 11:41:32 -07004129// consumeDoubleSliceValue wire decodes a []float64 value as a repeated Double.
4130func consumeDoubleSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
4131 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07004132 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07004133 b, n = wire.ConsumeBytes(b)
4134 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004135 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004136 }
4137 for len(b) > 0 {
4138 v, n := wire.ConsumeFixed64(b)
4139 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004140 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004141 }
Damien Neil68b81c32019-08-22 11:41:32 -07004142 list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
Damien Neile91877d2019-06-27 10:54:42 -07004143 b = b[n:]
4144 }
Damien Neil68b81c32019-08-22 11:41:32 -07004145 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004146 }
4147 if wtyp != wire.Fixed64Type {
Damien Neil68b81c32019-08-22 11:41:32 -07004148 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004149 }
4150 v, n := wire.ConsumeFixed64(b)
4151 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004152 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004153 }
Damien Neil68b81c32019-08-22 11:41:32 -07004154 list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
4155 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004156}
4157
Damien Neil68b81c32019-08-22 11:41:32 -07004158var coderDoubleSliceValue = valueCoderFuncs{
4159 size: sizeDoubleSliceValue,
4160 marshal: appendDoubleSliceValue,
4161 unmarshal: consumeDoubleSliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004162}
4163
Damien Neil68b81c32019-08-22 11:41:32 -07004164// sizeDoublePackedSliceValue returns the size of wire encoding a []float64 value as a packed repeated Double.
4165func sizeDoublePackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
4166 list := listv.List()
Damien Neil2c0824b2019-12-20 12:21:25 -08004167 llen := list.Len()
4168 if llen == 0 {
4169 return 0
4170 }
4171 n := llen * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07004172 return tagsize + wire.SizeBytes(n)
4173}
4174
Damien Neil68b81c32019-08-22 11:41:32 -07004175// appendDoublePackedSliceValue encodes a []float64 value as a packed repeated Double.
4176func appendDoublePackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
4177 list := listv.List()
4178 llen := list.Len()
4179 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07004180 return b, nil
4181 }
4182 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004183 n := llen * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07004184 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07004185 for i := 0; i < llen; i++ {
4186 v := list.Get(i)
4187 b = wire.AppendFixed64(b, math.Float64bits(v.Float()))
Damien Neil7492a092019-07-10 15:23:29 -07004188 }
4189 return b, nil
4190}
4191
Damien Neil68b81c32019-08-22 11:41:32 -07004192var coderDoublePackedSliceValue = valueCoderFuncs{
4193 size: sizeDoublePackedSliceValue,
4194 marshal: appendDoublePackedSliceValue,
4195 unmarshal: consumeDoubleSliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07004196}
4197
Damien Neilc37adef2019-04-01 13:49:56 -07004198// sizeString returns the size of wire encoding a string pointer as a String.
4199func sizeString(p pointer, tagsize int, _ marshalOptions) (size int) {
4200 v := *p.String()
Damien Neilcedb5952019-06-21 12:04:07 -07004201 return tagsize + wire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004202}
4203
4204// appendString wire encodes a string pointer as a String.
4205func appendString(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4206 v := *p.String()
4207 b = wire.AppendVarint(b, wiretag)
Damien Neilcedb5952019-06-21 12:04:07 -07004208 b = wire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004209 return b, nil
4210}
4211
Damien Neile91877d2019-06-27 10:54:42 -07004212// consumeString wire decodes a string pointer as a String.
4213func consumeString(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4214 if wtyp != wire.BytesType {
4215 return 0, errUnknown
4216 }
4217 v, n := wire.ConsumeString(b)
4218 if n < 0 {
4219 return 0, wire.ParseError(n)
4220 }
4221 *p.String() = v
4222 return n, nil
4223}
4224
Damien Neilc37adef2019-04-01 13:49:56 -07004225var coderString = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004226 size: sizeString,
4227 marshal: appendString,
4228 unmarshal: consumeString,
Damien Neilc37adef2019-04-01 13:49:56 -07004229}
4230
Joe Tsaic51e2e02019-07-13 00:44:41 -07004231// appendStringValidateUTF8 wire encodes a string pointer as a String.
4232func appendStringValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4233 v := *p.String()
4234 b = wire.AppendVarint(b, wiretag)
4235 b = wire.AppendString(b, v)
4236 if !utf8.ValidString(v) {
4237 return b, errInvalidUTF8{}
4238 }
4239 return b, nil
4240}
4241
4242// consumeStringValidateUTF8 wire decodes a string pointer as a String.
4243func consumeStringValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4244 if wtyp != wire.BytesType {
4245 return 0, errUnknown
4246 }
4247 v, n := wire.ConsumeString(b)
4248 if n < 0 {
4249 return 0, wire.ParseError(n)
4250 }
4251 if !utf8.ValidString(v) {
4252 return 0, errInvalidUTF8{}
4253 }
4254 *p.String() = v
4255 return n, nil
4256}
4257
4258var coderStringValidateUTF8 = pointerCoderFuncs{
4259 size: sizeString,
4260 marshal: appendStringValidateUTF8,
4261 unmarshal: consumeStringValidateUTF8,
4262}
4263
4264// sizeStringNoZero returns the size of wire encoding a string pointer as a String.
Damien Neilc37adef2019-04-01 13:49:56 -07004265// The zero value is not encoded.
4266func sizeStringNoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
4267 v := *p.String()
4268 if len(v) == 0 {
4269 return 0
4270 }
Damien Neilcedb5952019-06-21 12:04:07 -07004271 return tagsize + wire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004272}
4273
Joe Tsaic51e2e02019-07-13 00:44:41 -07004274// appendStringNoZero wire encodes a string pointer as a String.
Damien Neilc37adef2019-04-01 13:49:56 -07004275// The zero value is not encoded.
4276func appendStringNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4277 v := *p.String()
4278 if len(v) == 0 {
4279 return b, nil
4280 }
4281 b = wire.AppendVarint(b, wiretag)
Damien Neilcedb5952019-06-21 12:04:07 -07004282 b = wire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004283 return b, nil
4284}
4285
4286var coderStringNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004287 size: sizeStringNoZero,
4288 marshal: appendStringNoZero,
4289 unmarshal: consumeString,
Damien Neilc37adef2019-04-01 13:49:56 -07004290}
4291
Joe Tsaic51e2e02019-07-13 00:44:41 -07004292// appendStringNoZeroValidateUTF8 wire encodes a string pointer as a String.
4293// The zero value is not encoded.
4294func appendStringNoZeroValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4295 v := *p.String()
4296 if len(v) == 0 {
4297 return b, nil
4298 }
4299 b = wire.AppendVarint(b, wiretag)
4300 b = wire.AppendString(b, v)
4301 if !utf8.ValidString(v) {
4302 return b, errInvalidUTF8{}
4303 }
4304 return b, nil
4305}
4306
4307var coderStringNoZeroValidateUTF8 = pointerCoderFuncs{
4308 size: sizeStringNoZero,
4309 marshal: appendStringNoZeroValidateUTF8,
4310 unmarshal: consumeStringValidateUTF8,
4311}
4312
Damien Neilc37adef2019-04-01 13:49:56 -07004313// sizeStringPtr returns the size of wire encoding a *string pointer as a String.
4314// It panics if the pointer is nil.
4315func sizeStringPtr(p pointer, tagsize int, _ marshalOptions) (size int) {
4316 v := **p.StringPtr()
Damien Neilcedb5952019-06-21 12:04:07 -07004317 return tagsize + wire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004318}
4319
Damien Neile91877d2019-06-27 10:54:42 -07004320// appendStringPtr wire encodes a *string pointer as a String.
Damien Neilc37adef2019-04-01 13:49:56 -07004321// It panics if the pointer is nil.
4322func appendStringPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4323 v := **p.StringPtr()
4324 b = wire.AppendVarint(b, wiretag)
Damien Neilcedb5952019-06-21 12:04:07 -07004325 b = wire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004326 return b, nil
4327}
4328
Damien Neile91877d2019-06-27 10:54:42 -07004329// consumeStringPtr wire decodes a *string pointer as a String.
4330func consumeStringPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4331 if wtyp != wire.BytesType {
4332 return 0, errUnknown
4333 }
4334 v, n := wire.ConsumeString(b)
4335 if n < 0 {
4336 return 0, wire.ParseError(n)
4337 }
4338 vp := p.StringPtr()
4339 if *vp == nil {
4340 *vp = new(string)
4341 }
4342 **vp = v
4343 return n, nil
4344}
4345
Damien Neilc37adef2019-04-01 13:49:56 -07004346var coderStringPtr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004347 size: sizeStringPtr,
4348 marshal: appendStringPtr,
4349 unmarshal: consumeStringPtr,
Damien Neilc37adef2019-04-01 13:49:56 -07004350}
4351
4352// sizeStringSlice returns the size of wire encoding a []string pointer as a repeated String.
4353func sizeStringSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
4354 s := *p.StringSlice()
4355 for _, v := range s {
Damien Neilcedb5952019-06-21 12:04:07 -07004356 size += tagsize + wire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004357 }
4358 return size
4359}
4360
4361// appendStringSlice encodes a []string pointer as a repeated String.
4362func appendStringSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4363 s := *p.StringSlice()
4364 for _, v := range s {
4365 b = wire.AppendVarint(b, wiretag)
Damien Neilcedb5952019-06-21 12:04:07 -07004366 b = wire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004367 }
4368 return b, nil
4369}
4370
Damien Neile91877d2019-06-27 10:54:42 -07004371// consumeStringSlice wire decodes a []string pointer as a repeated String.
4372func consumeStringSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4373 sp := p.StringSlice()
4374 if wtyp != wire.BytesType {
4375 return 0, errUnknown
4376 }
4377 v, n := wire.ConsumeString(b)
4378 if n < 0 {
4379 return 0, wire.ParseError(n)
4380 }
4381 *sp = append(*sp, v)
4382 return n, nil
4383}
4384
Damien Neilc37adef2019-04-01 13:49:56 -07004385var coderStringSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004386 size: sizeStringSlice,
4387 marshal: appendStringSlice,
4388 unmarshal: consumeStringSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07004389}
4390
Joe Tsaic51e2e02019-07-13 00:44:41 -07004391// appendStringSliceValidateUTF8 encodes a []string pointer as a repeated String.
4392func appendStringSliceValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4393 s := *p.StringSlice()
4394 for _, v := range s {
4395 b = wire.AppendVarint(b, wiretag)
4396 b = wire.AppendString(b, v)
4397 if !utf8.ValidString(v) {
4398 return b, errInvalidUTF8{}
4399 }
4400 }
4401 return b, nil
4402}
4403
4404// consumeStringSliceValidateUTF8 wire decodes a []string pointer as a repeated String.
4405func consumeStringSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4406 sp := p.StringSlice()
4407 if wtyp != wire.BytesType {
4408 return 0, errUnknown
4409 }
4410 v, n := wire.ConsumeString(b)
4411 if n < 0 {
4412 return 0, wire.ParseError(n)
4413 }
4414 if !utf8.ValidString(v) {
4415 return 0, errInvalidUTF8{}
4416 }
4417 *sp = append(*sp, v)
4418 return n, nil
4419}
4420
4421var coderStringSliceValidateUTF8 = pointerCoderFuncs{
4422 size: sizeStringSlice,
4423 marshal: appendStringSliceValidateUTF8,
4424 unmarshal: consumeStringSliceValidateUTF8,
4425}
4426
Damien Neil68b81c32019-08-22 11:41:32 -07004427// sizeStringValue returns the size of wire encoding a string value as a String.
4428func sizeStringValue(v protoreflect.Value, tagsize int, _ marshalOptions) int {
4429 return tagsize + wire.SizeBytes(len(v.String()))
Damien Neilc37adef2019-04-01 13:49:56 -07004430}
4431
Damien Neil68b81c32019-08-22 11:41:32 -07004432// appendStringValue encodes a string value as a String.
4433func appendStringValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004434 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004435 b = wire.AppendString(b, v.String())
Damien Neilc37adef2019-04-01 13:49:56 -07004436 return b, nil
4437}
4438
Damien Neil68b81c32019-08-22 11:41:32 -07004439// consumeStringValue decodes a string value as a String.
4440func consumeStringValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07004441 if wtyp != wire.BytesType {
Damien Neil68b81c32019-08-22 11:41:32 -07004442 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004443 }
4444 v, n := wire.ConsumeString(b)
4445 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004446 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004447 }
Damien Neil68b81c32019-08-22 11:41:32 -07004448 return protoreflect.ValueOfString(string(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004449}
4450
Damien Neil68b81c32019-08-22 11:41:32 -07004451var coderStringValue = valueCoderFuncs{
4452 size: sizeStringValue,
4453 marshal: appendStringValue,
4454 unmarshal: consumeStringValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004455}
4456
Damien Neil68b81c32019-08-22 11:41:32 -07004457// appendStringValueValidateUTF8 encodes a string value as a String.
4458func appendStringValueValidateUTF8(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07004459 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004460 b = wire.AppendString(b, v.String())
4461 if !utf8.ValidString(v.String()) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07004462 return b, errInvalidUTF8{}
4463 }
4464 return b, nil
4465}
4466
Damien Neil68b81c32019-08-22 11:41:32 -07004467// consumeStringValueValidateUTF8 decodes a string value as a String.
4468func consumeStringValueValidateUTF8(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07004469 if wtyp != wire.BytesType {
Damien Neil68b81c32019-08-22 11:41:32 -07004470 return protoreflect.Value{}, 0, errUnknown
Joe Tsaic51e2e02019-07-13 00:44:41 -07004471 }
4472 v, n := wire.ConsumeString(b)
4473 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004474 return protoreflect.Value{}, 0, wire.ParseError(n)
Joe Tsaic51e2e02019-07-13 00:44:41 -07004475 }
4476 if !utf8.ValidString(v) {
Damien Neil68b81c32019-08-22 11:41:32 -07004477 return protoreflect.Value{}, 0, errInvalidUTF8{}
Joe Tsaic51e2e02019-07-13 00:44:41 -07004478 }
Damien Neil68b81c32019-08-22 11:41:32 -07004479 return protoreflect.ValueOfString(string(v)), n, nil
Joe Tsaic51e2e02019-07-13 00:44:41 -07004480}
4481
Damien Neil68b81c32019-08-22 11:41:32 -07004482var coderStringValueValidateUTF8 = valueCoderFuncs{
4483 size: sizeStringValue,
4484 marshal: appendStringValueValidateUTF8,
4485 unmarshal: consumeStringValueValidateUTF8,
Joe Tsaic51e2e02019-07-13 00:44:41 -07004486}
4487
Damien Neil68b81c32019-08-22 11:41:32 -07004488// sizeStringSliceValue returns the size of wire encoding a []string value as a repeated String.
4489func sizeStringSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
4490 list := listv.List()
4491 for i, llen := 0, list.Len(); i < llen; i++ {
4492 v := list.Get(i)
4493 size += tagsize + wire.SizeBytes(len(v.String()))
Damien Neilc37adef2019-04-01 13:49:56 -07004494 }
4495 return size
4496}
4497
Damien Neil68b81c32019-08-22 11:41:32 -07004498// appendStringSliceValue encodes a []string value as a repeated String.
4499func appendStringSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
4500 list := listv.List()
4501 for i, llen := 0, list.Len(); i < llen; i++ {
4502 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07004503 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004504 b = wire.AppendString(b, v.String())
Damien Neilc37adef2019-04-01 13:49:56 -07004505 }
4506 return b, nil
4507}
4508
Damien Neil68b81c32019-08-22 11:41:32 -07004509// consumeStringSliceValue wire decodes a []string value as a repeated String.
4510func consumeStringSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
4511 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07004512 if wtyp != wire.BytesType {
Damien Neil68b81c32019-08-22 11:41:32 -07004513 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004514 }
4515 v, n := wire.ConsumeString(b)
4516 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004517 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004518 }
Damien Neil68b81c32019-08-22 11:41:32 -07004519 list.Append(protoreflect.ValueOfString(string(v)))
4520 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004521}
4522
Damien Neil68b81c32019-08-22 11:41:32 -07004523var coderStringSliceValue = valueCoderFuncs{
4524 size: sizeStringSliceValue,
4525 marshal: appendStringSliceValue,
4526 unmarshal: consumeStringSliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004527}
4528
4529// sizeBytes returns the size of wire encoding a []byte pointer as a Bytes.
4530func sizeBytes(p pointer, tagsize int, _ marshalOptions) (size int) {
4531 v := *p.Bytes()
4532 return tagsize + wire.SizeBytes(len(v))
4533}
4534
4535// appendBytes wire encodes a []byte pointer as a Bytes.
4536func appendBytes(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4537 v := *p.Bytes()
4538 b = wire.AppendVarint(b, wiretag)
4539 b = wire.AppendBytes(b, v)
4540 return b, nil
4541}
4542
Damien Neile91877d2019-06-27 10:54:42 -07004543// consumeBytes wire decodes a []byte pointer as a Bytes.
4544func consumeBytes(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4545 if wtyp != wire.BytesType {
4546 return 0, errUnknown
4547 }
4548 v, n := wire.ConsumeBytes(b)
4549 if n < 0 {
4550 return 0, wire.ParseError(n)
4551 }
Damien Neil8003f082019-08-02 15:13:00 -07004552 *p.Bytes() = append(emptyBuf[:], v...)
Damien Neile91877d2019-06-27 10:54:42 -07004553 return n, nil
4554}
4555
Damien Neilc37adef2019-04-01 13:49:56 -07004556var coderBytes = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004557 size: sizeBytes,
4558 marshal: appendBytes,
4559 unmarshal: consumeBytes,
Damien Neilc37adef2019-04-01 13:49:56 -07004560}
4561
Joe Tsaic51e2e02019-07-13 00:44:41 -07004562// appendBytesValidateUTF8 wire encodes a []byte pointer as a Bytes.
4563func appendBytesValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4564 v := *p.Bytes()
4565 b = wire.AppendVarint(b, wiretag)
4566 b = wire.AppendBytes(b, v)
4567 if !utf8.Valid(v) {
4568 return b, errInvalidUTF8{}
4569 }
4570 return b, nil
4571}
4572
4573// consumeBytesValidateUTF8 wire decodes a []byte pointer as a Bytes.
4574func consumeBytesValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4575 if wtyp != wire.BytesType {
4576 return 0, errUnknown
4577 }
4578 v, n := wire.ConsumeBytes(b)
4579 if n < 0 {
4580 return 0, wire.ParseError(n)
4581 }
4582 if !utf8.Valid(v) {
4583 return 0, errInvalidUTF8{}
4584 }
Damien Neil8003f082019-08-02 15:13:00 -07004585 *p.Bytes() = append(emptyBuf[:], v...)
Joe Tsaic51e2e02019-07-13 00:44:41 -07004586 return n, nil
4587}
4588
4589var coderBytesValidateUTF8 = pointerCoderFuncs{
4590 size: sizeBytes,
4591 marshal: appendBytesValidateUTF8,
4592 unmarshal: consumeBytesValidateUTF8,
4593}
4594
4595// sizeBytesNoZero returns the size of wire encoding a []byte pointer as a Bytes.
Damien Neilc37adef2019-04-01 13:49:56 -07004596// The zero value is not encoded.
4597func sizeBytesNoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
4598 v := *p.Bytes()
4599 if len(v) == 0 {
4600 return 0
4601 }
4602 return tagsize + wire.SizeBytes(len(v))
4603}
4604
Joe Tsaic51e2e02019-07-13 00:44:41 -07004605// appendBytesNoZero wire encodes a []byte pointer as a Bytes.
Damien Neilc37adef2019-04-01 13:49:56 -07004606// The zero value is not encoded.
4607func appendBytesNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4608 v := *p.Bytes()
4609 if len(v) == 0 {
4610 return b, nil
4611 }
4612 b = wire.AppendVarint(b, wiretag)
4613 b = wire.AppendBytes(b, v)
4614 return b, nil
4615}
4616
Damien Neil8003f082019-08-02 15:13:00 -07004617// consumeBytesNoZero wire decodes a []byte pointer as a Bytes.
4618// The zero value is not decoded.
4619func consumeBytesNoZero(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4620 if wtyp != wire.BytesType {
4621 return 0, errUnknown
4622 }
4623 v, n := wire.ConsumeBytes(b)
4624 if n < 0 {
4625 return 0, wire.ParseError(n)
4626 }
4627 *p.Bytes() = append(([]byte)(nil), v...)
4628 return n, nil
4629}
4630
Damien Neilc37adef2019-04-01 13:49:56 -07004631var coderBytesNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004632 size: sizeBytesNoZero,
4633 marshal: appendBytesNoZero,
Damien Neil8003f082019-08-02 15:13:00 -07004634 unmarshal: consumeBytesNoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07004635}
4636
Joe Tsaic51e2e02019-07-13 00:44:41 -07004637// appendBytesNoZeroValidateUTF8 wire encodes a []byte pointer as a Bytes.
4638// The zero value is not encoded.
4639func appendBytesNoZeroValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4640 v := *p.Bytes()
4641 if len(v) == 0 {
4642 return b, nil
4643 }
4644 b = wire.AppendVarint(b, wiretag)
4645 b = wire.AppendBytes(b, v)
4646 if !utf8.Valid(v) {
4647 return b, errInvalidUTF8{}
4648 }
4649 return b, nil
4650}
4651
Damien Neil8003f082019-08-02 15:13:00 -07004652// consumeBytesNoZeroValidateUTF8 wire decodes a []byte pointer as a Bytes.
4653func consumeBytesNoZeroValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4654 if wtyp != wire.BytesType {
4655 return 0, errUnknown
4656 }
4657 v, n := wire.ConsumeBytes(b)
4658 if n < 0 {
4659 return 0, wire.ParseError(n)
4660 }
4661 if !utf8.Valid(v) {
4662 return 0, errInvalidUTF8{}
4663 }
4664 *p.Bytes() = append(([]byte)(nil), v...)
4665 return n, nil
4666}
4667
Joe Tsaic51e2e02019-07-13 00:44:41 -07004668var coderBytesNoZeroValidateUTF8 = pointerCoderFuncs{
4669 size: sizeBytesNoZero,
4670 marshal: appendBytesNoZeroValidateUTF8,
Damien Neil8003f082019-08-02 15:13:00 -07004671 unmarshal: consumeBytesNoZeroValidateUTF8,
Joe Tsaic51e2e02019-07-13 00:44:41 -07004672}
4673
Damien Neilc37adef2019-04-01 13:49:56 -07004674// sizeBytesSlice returns the size of wire encoding a [][]byte pointer as a repeated Bytes.
4675func sizeBytesSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
4676 s := *p.BytesSlice()
4677 for _, v := range s {
4678 size += tagsize + wire.SizeBytes(len(v))
4679 }
4680 return size
4681}
4682
4683// appendBytesSlice encodes a [][]byte pointer as a repeated Bytes.
4684func appendBytesSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4685 s := *p.BytesSlice()
4686 for _, v := range s {
4687 b = wire.AppendVarint(b, wiretag)
4688 b = wire.AppendBytes(b, v)
4689 }
4690 return b, nil
4691}
4692
Damien Neile91877d2019-06-27 10:54:42 -07004693// consumeBytesSlice wire decodes a [][]byte pointer as a repeated Bytes.
4694func consumeBytesSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4695 sp := p.BytesSlice()
4696 if wtyp != wire.BytesType {
4697 return 0, errUnknown
4698 }
4699 v, n := wire.ConsumeBytes(b)
4700 if n < 0 {
4701 return 0, wire.ParseError(n)
4702 }
Damien Neil8003f082019-08-02 15:13:00 -07004703 *sp = append(*sp, append(emptyBuf[:], v...))
Damien Neile91877d2019-06-27 10:54:42 -07004704 return n, nil
4705}
4706
Damien Neilc37adef2019-04-01 13:49:56 -07004707var coderBytesSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004708 size: sizeBytesSlice,
4709 marshal: appendBytesSlice,
4710 unmarshal: consumeBytesSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07004711}
4712
Joe Tsaic51e2e02019-07-13 00:44:41 -07004713// appendBytesSliceValidateUTF8 encodes a [][]byte pointer as a repeated Bytes.
4714func appendBytesSliceValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4715 s := *p.BytesSlice()
4716 for _, v := range s {
4717 b = wire.AppendVarint(b, wiretag)
4718 b = wire.AppendBytes(b, v)
4719 if !utf8.Valid(v) {
4720 return b, errInvalidUTF8{}
4721 }
4722 }
4723 return b, nil
4724}
4725
4726// consumeBytesSliceValidateUTF8 wire decodes a [][]byte pointer as a repeated Bytes.
4727func consumeBytesSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4728 sp := p.BytesSlice()
4729 if wtyp != wire.BytesType {
4730 return 0, errUnknown
4731 }
4732 v, n := wire.ConsumeBytes(b)
4733 if n < 0 {
4734 return 0, wire.ParseError(n)
4735 }
4736 if !utf8.Valid(v) {
4737 return 0, errInvalidUTF8{}
4738 }
Damien Neil8003f082019-08-02 15:13:00 -07004739 *sp = append(*sp, append(emptyBuf[:], v...))
Joe Tsaic51e2e02019-07-13 00:44:41 -07004740 return n, nil
4741}
4742
4743var coderBytesSliceValidateUTF8 = pointerCoderFuncs{
4744 size: sizeBytesSlice,
4745 marshal: appendBytesSliceValidateUTF8,
4746 unmarshal: consumeBytesSliceValidateUTF8,
4747}
4748
Damien Neil68b81c32019-08-22 11:41:32 -07004749// sizeBytesValue returns the size of wire encoding a []byte value as a Bytes.
4750func sizeBytesValue(v protoreflect.Value, tagsize int, _ marshalOptions) int {
4751 return tagsize + wire.SizeBytes(len(v.Bytes()))
Damien Neilc37adef2019-04-01 13:49:56 -07004752}
4753
Damien Neil68b81c32019-08-22 11:41:32 -07004754// appendBytesValue encodes a []byte value as a Bytes.
4755func appendBytesValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004756 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004757 b = wire.AppendBytes(b, v.Bytes())
Damien Neilc37adef2019-04-01 13:49:56 -07004758 return b, nil
4759}
4760
Damien Neil68b81c32019-08-22 11:41:32 -07004761// consumeBytesValue decodes a []byte value as a Bytes.
4762func consumeBytesValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07004763 if wtyp != wire.BytesType {
Damien Neil68b81c32019-08-22 11:41:32 -07004764 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004765 }
4766 v, n := wire.ConsumeBytes(b)
4767 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004768 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004769 }
Damien Neil5366f822019-12-05 14:54:35 -08004770 return protoreflect.ValueOfBytes(append(emptyBuf[:], v...)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004771}
4772
Damien Neil68b81c32019-08-22 11:41:32 -07004773var coderBytesValue = valueCoderFuncs{
4774 size: sizeBytesValue,
4775 marshal: appendBytesValue,
4776 unmarshal: consumeBytesValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004777}
4778
Damien Neil68b81c32019-08-22 11:41:32 -07004779// sizeBytesSliceValue returns the size of wire encoding a [][]byte value as a repeated Bytes.
4780func sizeBytesSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
4781 list := listv.List()
4782 for i, llen := 0, list.Len(); i < llen; i++ {
4783 v := list.Get(i)
4784 size += tagsize + wire.SizeBytes(len(v.Bytes()))
Damien Neilc37adef2019-04-01 13:49:56 -07004785 }
4786 return size
4787}
4788
Damien Neil68b81c32019-08-22 11:41:32 -07004789// appendBytesSliceValue encodes a [][]byte value as a repeated Bytes.
4790func appendBytesSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
4791 list := listv.List()
4792 for i, llen := 0, list.Len(); i < llen; i++ {
4793 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07004794 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004795 b = wire.AppendBytes(b, v.Bytes())
Damien Neilc37adef2019-04-01 13:49:56 -07004796 }
4797 return b, nil
4798}
4799
Damien Neil68b81c32019-08-22 11:41:32 -07004800// consumeBytesSliceValue wire decodes a [][]byte value as a repeated Bytes.
4801func consumeBytesSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
4802 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07004803 if wtyp != wire.BytesType {
Damien Neil68b81c32019-08-22 11:41:32 -07004804 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004805 }
4806 v, n := wire.ConsumeBytes(b)
4807 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004808 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004809 }
Damien Neil5366f822019-12-05 14:54:35 -08004810 list.Append(protoreflect.ValueOfBytes(append(emptyBuf[:], v...)))
Damien Neil68b81c32019-08-22 11:41:32 -07004811 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004812}
4813
Damien Neil68b81c32019-08-22 11:41:32 -07004814var coderBytesSliceValue = valueCoderFuncs{
4815 size: sizeBytesSliceValue,
4816 marshal: appendBytesSliceValue,
4817 unmarshal: consumeBytesSliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004818}
4819
Damien Neil8003f082019-08-02 15:13:00 -07004820// We append to an empty array rather than a nil []byte to get non-nil zero-length byte slices.
4821var emptyBuf [0]byte
4822
Damien Neilc37adef2019-04-01 13:49:56 -07004823var wireTypes = map[protoreflect.Kind]wire.Type{
4824 protoreflect.BoolKind: wire.VarintType,
4825 protoreflect.EnumKind: wire.VarintType,
4826 protoreflect.Int32Kind: wire.VarintType,
4827 protoreflect.Sint32Kind: wire.VarintType,
4828 protoreflect.Uint32Kind: wire.VarintType,
4829 protoreflect.Int64Kind: wire.VarintType,
4830 protoreflect.Sint64Kind: wire.VarintType,
4831 protoreflect.Uint64Kind: wire.VarintType,
4832 protoreflect.Sfixed32Kind: wire.Fixed32Type,
4833 protoreflect.Fixed32Kind: wire.Fixed32Type,
4834 protoreflect.FloatKind: wire.Fixed32Type,
4835 protoreflect.Sfixed64Kind: wire.Fixed64Type,
4836 protoreflect.Fixed64Kind: wire.Fixed64Type,
4837 protoreflect.DoubleKind: wire.Fixed64Type,
4838 protoreflect.StringKind: wire.BytesType,
4839 protoreflect.BytesKind: wire.BytesType,
4840 protoreflect.MessageKind: wire.BytesType,
4841 protoreflect.GroupKind: wire.StartGroupType,
4842}