blob: 3d47dccf2e6292e30e07cf02af4141dc1fef5ce3 [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 Neil7492a092019-07-10 15:23:29 -0700299 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -0700300 for i, llen := 0, list.Len(); i < llen; i++ {
301 v := list.Get(i)
302 n += wire.SizeVarint(wire.EncodeBool(v.Bool()))
Damien Neil7492a092019-07-10 15:23:29 -0700303 }
304 return tagsize + wire.SizeBytes(n)
305}
306
Damien Neil68b81c32019-08-22 11:41:32 -0700307// appendBoolPackedSliceValue encodes a []bool value as a packed repeated Bool.
308func appendBoolPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
309 list := listv.List()
310 llen := list.Len()
311 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -0700312 return b, nil
313 }
314 b = wire.AppendVarint(b, wiretag)
315 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -0700316 for i := 0; i < llen; i++ {
317 v := list.Get(i)
318 n += wire.SizeVarint(wire.EncodeBool(v.Bool()))
Damien Neil7492a092019-07-10 15:23:29 -0700319 }
320 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -0700321 for i := 0; i < llen; i++ {
322 v := list.Get(i)
323 b = wire.AppendVarint(b, wire.EncodeBool(v.Bool()))
Damien Neil7492a092019-07-10 15:23:29 -0700324 }
325 return b, nil
326}
327
Damien Neil68b81c32019-08-22 11:41:32 -0700328var coderBoolPackedSliceValue = valueCoderFuncs{
329 size: sizeBoolPackedSliceValue,
330 marshal: appendBoolPackedSliceValue,
331 unmarshal: consumeBoolSliceValue,
332}
333
334// sizeEnumValue returns the size of wire encoding a value as a Enum.
335func sizeEnumValue(v protoreflect.Value, tagsize int, _ marshalOptions) int {
336 return tagsize + wire.SizeVarint(uint64(v.Enum()))
337}
338
339// appendEnumValue encodes a value as a Enum.
340func appendEnumValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
341 b = wire.AppendVarint(b, wiretag)
342 b = wire.AppendVarint(b, uint64(v.Enum()))
343 return b, nil
344}
345
346// consumeEnumValue decodes a value as a Enum.
347func consumeEnumValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
348 if wtyp != wire.VarintType {
349 return protoreflect.Value{}, 0, errUnknown
350 }
351 v, n := wire.ConsumeVarint(b)
352 if n < 0 {
353 return protoreflect.Value{}, 0, wire.ParseError(n)
354 }
355 return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), n, nil
356}
357
358var coderEnumValue = valueCoderFuncs{
359 size: sizeEnumValue,
360 marshal: appendEnumValue,
361 unmarshal: consumeEnumValue,
362}
363
364// sizeEnumSliceValue returns the size of wire encoding a [] value as a repeated Enum.
365func sizeEnumSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
366 list := listv.List()
367 for i, llen := 0, list.Len(); i < llen; i++ {
368 v := list.Get(i)
369 size += tagsize + wire.SizeVarint(uint64(v.Enum()))
370 }
371 return size
372}
373
374// appendEnumSliceValue encodes a [] value as a repeated Enum.
375func appendEnumSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
376 list := listv.List()
377 for i, llen := 0, list.Len(); i < llen; i++ {
378 v := list.Get(i)
379 b = wire.AppendVarint(b, wiretag)
380 b = wire.AppendVarint(b, uint64(v.Enum()))
381 }
382 return b, nil
383}
384
385// consumeEnumSliceValue wire decodes a [] value as a repeated Enum.
386func consumeEnumSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
387 list := listv.List()
388 if wtyp == wire.BytesType {
389 b, n = wire.ConsumeBytes(b)
390 if n < 0 {
391 return protoreflect.Value{}, 0, wire.ParseError(n)
392 }
393 for len(b) > 0 {
394 v, n := wire.ConsumeVarint(b)
395 if n < 0 {
396 return protoreflect.Value{}, 0, wire.ParseError(n)
397 }
398 list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
399 b = b[n:]
400 }
401 return listv, n, nil
402 }
403 if wtyp != wire.VarintType {
404 return protoreflect.Value{}, 0, errUnknown
405 }
406 v, n := wire.ConsumeVarint(b)
407 if n < 0 {
408 return protoreflect.Value{}, 0, wire.ParseError(n)
409 }
410 list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
411 return listv, n, nil
412}
413
414var coderEnumSliceValue = valueCoderFuncs{
415 size: sizeEnumSliceValue,
416 marshal: appendEnumSliceValue,
417 unmarshal: consumeEnumSliceValue,
418}
419
420// sizeEnumPackedSliceValue returns the size of wire encoding a [] value as a packed repeated Enum.
421func sizeEnumPackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
422 list := listv.List()
423 n := 0
424 for i, llen := 0, list.Len(); i < llen; i++ {
425 v := list.Get(i)
426 n += wire.SizeVarint(uint64(v.Enum()))
427 }
428 return tagsize + wire.SizeBytes(n)
429}
430
431// appendEnumPackedSliceValue encodes a [] value as a packed repeated Enum.
432func appendEnumPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
433 list := listv.List()
434 llen := list.Len()
435 if llen == 0 {
436 return b, nil
437 }
438 b = wire.AppendVarint(b, wiretag)
439 n := 0
440 for i := 0; i < llen; i++ {
441 v := list.Get(i)
442 n += wire.SizeVarint(uint64(v.Enum()))
443 }
444 b = wire.AppendVarint(b, uint64(n))
445 for i := 0; i < llen; i++ {
446 v := list.Get(i)
447 b = wire.AppendVarint(b, uint64(v.Enum()))
448 }
449 return b, nil
450}
451
452var coderEnumPackedSliceValue = valueCoderFuncs{
453 size: sizeEnumPackedSliceValue,
454 marshal: appendEnumPackedSliceValue,
455 unmarshal: consumeEnumSliceValue,
Damien Neil7492a092019-07-10 15:23:29 -0700456}
457
Damien Neilc37adef2019-04-01 13:49:56 -0700458// sizeInt32 returns the size of wire encoding a int32 pointer as a Int32.
459func sizeInt32(p pointer, tagsize int, _ marshalOptions) (size int) {
460 v := *p.Int32()
461 return tagsize + wire.SizeVarint(uint64(v))
462}
463
464// appendInt32 wire encodes a int32 pointer as a Int32.
465func appendInt32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
466 v := *p.Int32()
467 b = wire.AppendVarint(b, wiretag)
468 b = wire.AppendVarint(b, uint64(v))
469 return b, nil
470}
471
Damien Neile91877d2019-06-27 10:54:42 -0700472// consumeInt32 wire decodes a int32 pointer as a Int32.
473func consumeInt32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
474 if wtyp != wire.VarintType {
475 return 0, errUnknown
476 }
477 v, n := wire.ConsumeVarint(b)
478 if n < 0 {
479 return 0, wire.ParseError(n)
480 }
481 *p.Int32() = int32(v)
482 return n, nil
483}
484
Damien Neilc37adef2019-04-01 13:49:56 -0700485var coderInt32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700486 size: sizeInt32,
487 marshal: appendInt32,
488 unmarshal: consumeInt32,
Damien Neilc37adef2019-04-01 13:49:56 -0700489}
490
Joe Tsaic51e2e02019-07-13 00:44:41 -0700491// sizeInt32NoZero returns the size of wire encoding a int32 pointer as a Int32.
Damien Neilc37adef2019-04-01 13:49:56 -0700492// The zero value is not encoded.
493func sizeInt32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
494 v := *p.Int32()
495 if v == 0 {
496 return 0
497 }
498 return tagsize + wire.SizeVarint(uint64(v))
499}
500
Joe Tsaic51e2e02019-07-13 00:44:41 -0700501// appendInt32NoZero wire encodes a int32 pointer as a Int32.
Damien Neilc37adef2019-04-01 13:49:56 -0700502// The zero value is not encoded.
503func appendInt32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
504 v := *p.Int32()
505 if v == 0 {
506 return b, nil
507 }
508 b = wire.AppendVarint(b, wiretag)
509 b = wire.AppendVarint(b, uint64(v))
510 return b, nil
511}
512
513var coderInt32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700514 size: sizeInt32NoZero,
515 marshal: appendInt32NoZero,
516 unmarshal: consumeInt32,
Damien Neilc37adef2019-04-01 13:49:56 -0700517}
518
519// sizeInt32Ptr returns the size of wire encoding a *int32 pointer as a Int32.
520// It panics if the pointer is nil.
521func sizeInt32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
522 v := **p.Int32Ptr()
523 return tagsize + wire.SizeVarint(uint64(v))
524}
525
Damien Neile91877d2019-06-27 10:54:42 -0700526// appendInt32Ptr wire encodes a *int32 pointer as a Int32.
Damien Neilc37adef2019-04-01 13:49:56 -0700527// It panics if the pointer is nil.
528func appendInt32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
529 v := **p.Int32Ptr()
530 b = wire.AppendVarint(b, wiretag)
531 b = wire.AppendVarint(b, uint64(v))
532 return b, nil
533}
534
Damien Neile91877d2019-06-27 10:54:42 -0700535// consumeInt32Ptr wire decodes a *int32 pointer as a Int32.
536func consumeInt32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
537 if wtyp != wire.VarintType {
538 return 0, errUnknown
539 }
540 v, n := wire.ConsumeVarint(b)
541 if n < 0 {
542 return 0, wire.ParseError(n)
543 }
544 vp := p.Int32Ptr()
545 if *vp == nil {
546 *vp = new(int32)
547 }
548 **vp = int32(v)
549 return n, nil
550}
551
Damien Neilc37adef2019-04-01 13:49:56 -0700552var coderInt32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700553 size: sizeInt32Ptr,
554 marshal: appendInt32Ptr,
555 unmarshal: consumeInt32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -0700556}
557
558// sizeInt32Slice returns the size of wire encoding a []int32 pointer as a repeated Int32.
559func sizeInt32Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
560 s := *p.Int32Slice()
561 for _, v := range s {
562 size += tagsize + wire.SizeVarint(uint64(v))
563 }
564 return size
565}
566
567// appendInt32Slice encodes a []int32 pointer as a repeated Int32.
568func appendInt32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
569 s := *p.Int32Slice()
570 for _, v := range s {
571 b = wire.AppendVarint(b, wiretag)
572 b = wire.AppendVarint(b, uint64(v))
573 }
574 return b, nil
575}
576
Damien Neile91877d2019-06-27 10:54:42 -0700577// consumeInt32Slice wire decodes a []int32 pointer as a repeated Int32.
578func consumeInt32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
579 sp := p.Int32Slice()
580 if wtyp == wire.BytesType {
581 s := *sp
582 b, n = wire.ConsumeBytes(b)
583 if n < 0 {
584 return 0, wire.ParseError(n)
585 }
586 for len(b) > 0 {
587 v, n := wire.ConsumeVarint(b)
588 if n < 0 {
589 return 0, wire.ParseError(n)
590 }
591 s = append(s, int32(v))
592 b = b[n:]
593 }
594 *sp = s
595 return n, nil
596 }
597 if wtyp != wire.VarintType {
598 return 0, errUnknown
599 }
600 v, n := wire.ConsumeVarint(b)
601 if n < 0 {
602 return 0, wire.ParseError(n)
603 }
604 *sp = append(*sp, int32(v))
605 return n, nil
606}
607
Damien Neilc37adef2019-04-01 13:49:56 -0700608var coderInt32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700609 size: sizeInt32Slice,
610 marshal: appendInt32Slice,
611 unmarshal: consumeInt32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -0700612}
613
614// sizeInt32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Int32.
615func sizeInt32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
616 s := *p.Int32Slice()
617 if len(s) == 0 {
618 return 0
619 }
620 n := 0
621 for _, v := range s {
622 n += wire.SizeVarint(uint64(v))
623 }
624 return tagsize + wire.SizeBytes(n)
625}
626
627// appendInt32PackedSlice encodes a []int32 pointer as a packed repeated Int32.
628func appendInt32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
629 s := *p.Int32Slice()
630 if len(s) == 0 {
631 return b, nil
632 }
633 b = wire.AppendVarint(b, wiretag)
634 n := 0
635 for _, v := range s {
636 n += wire.SizeVarint(uint64(v))
637 }
638 b = wire.AppendVarint(b, uint64(n))
639 for _, v := range s {
640 b = wire.AppendVarint(b, uint64(v))
641 }
642 return b, nil
643}
644
645var coderInt32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700646 size: sizeInt32PackedSlice,
647 marshal: appendInt32PackedSlice,
648 unmarshal: consumeInt32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -0700649}
650
Damien Neil68b81c32019-08-22 11:41:32 -0700651// sizeInt32Value returns the size of wire encoding a int32 value as a Int32.
652func sizeInt32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
653 return tagsize + wire.SizeVarint(uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700654}
655
Damien Neil68b81c32019-08-22 11:41:32 -0700656// appendInt32Value encodes a int32 value as a Int32.
657func appendInt32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700658 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -0700659 b = wire.AppendVarint(b, uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700660 return b, nil
661}
662
Damien Neil68b81c32019-08-22 11:41:32 -0700663// consumeInt32Value decodes a int32 value as a Int32.
664func consumeInt32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -0700665 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -0700666 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700667 }
668 v, n := wire.ConsumeVarint(b)
669 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700670 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700671 }
Damien Neil68b81c32019-08-22 11:41:32 -0700672 return protoreflect.ValueOfInt32(int32(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -0700673}
674
Damien Neil68b81c32019-08-22 11:41:32 -0700675var coderInt32Value = valueCoderFuncs{
676 size: sizeInt32Value,
677 marshal: appendInt32Value,
678 unmarshal: consumeInt32Value,
Damien Neilc37adef2019-04-01 13:49:56 -0700679}
680
Damien Neil68b81c32019-08-22 11:41:32 -0700681// sizeInt32SliceValue returns the size of wire encoding a []int32 value as a repeated Int32.
682func sizeInt32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
683 list := listv.List()
684 for i, llen := 0, list.Len(); i < llen; i++ {
685 v := list.Get(i)
686 size += tagsize + wire.SizeVarint(uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700687 }
688 return size
689}
690
Damien Neil68b81c32019-08-22 11:41:32 -0700691// appendInt32SliceValue encodes a []int32 value as a repeated Int32.
692func appendInt32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
693 list := listv.List()
694 for i, llen := 0, list.Len(); i < llen; i++ {
695 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -0700696 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -0700697 b = wire.AppendVarint(b, uint64(int32(v.Int())))
Damien Neilc37adef2019-04-01 13:49:56 -0700698 }
699 return b, nil
700}
701
Damien Neil68b81c32019-08-22 11:41:32 -0700702// consumeInt32SliceValue wire decodes a []int32 value as a repeated Int32.
703func consumeInt32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
704 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -0700705 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -0700706 b, n = wire.ConsumeBytes(b)
707 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700708 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700709 }
710 for len(b) > 0 {
711 v, n := wire.ConsumeVarint(b)
712 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700713 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700714 }
Damien Neil68b81c32019-08-22 11:41:32 -0700715 list.Append(protoreflect.ValueOfInt32(int32(v)))
Damien Neile91877d2019-06-27 10:54:42 -0700716 b = b[n:]
717 }
Damien Neil68b81c32019-08-22 11:41:32 -0700718 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -0700719 }
720 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -0700721 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700722 }
723 v, n := wire.ConsumeVarint(b)
724 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700725 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700726 }
Damien Neil68b81c32019-08-22 11:41:32 -0700727 list.Append(protoreflect.ValueOfInt32(int32(v)))
728 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -0700729}
730
Damien Neil68b81c32019-08-22 11:41:32 -0700731var coderInt32SliceValue = valueCoderFuncs{
732 size: sizeInt32SliceValue,
733 marshal: appendInt32SliceValue,
734 unmarshal: consumeInt32SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -0700735}
736
Damien Neil68b81c32019-08-22 11:41:32 -0700737// sizeInt32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Int32.
738func sizeInt32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
739 list := listv.List()
Damien Neil7492a092019-07-10 15:23:29 -0700740 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -0700741 for i, llen := 0, list.Len(); i < llen; i++ {
742 v := list.Get(i)
743 n += wire.SizeVarint(uint64(int32(v.Int())))
Damien Neil7492a092019-07-10 15:23:29 -0700744 }
745 return tagsize + wire.SizeBytes(n)
746}
747
Damien Neil68b81c32019-08-22 11:41:32 -0700748// appendInt32PackedSliceValue encodes a []int32 value as a packed repeated Int32.
749func appendInt32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
750 list := listv.List()
751 llen := list.Len()
752 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -0700753 return b, nil
754 }
755 b = wire.AppendVarint(b, wiretag)
756 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -0700757 for i := 0; i < llen; i++ {
758 v := list.Get(i)
759 n += wire.SizeVarint(uint64(int32(v.Int())))
Damien Neil7492a092019-07-10 15:23:29 -0700760 }
761 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -0700762 for i := 0; i < llen; i++ {
763 v := list.Get(i)
764 b = wire.AppendVarint(b, uint64(int32(v.Int())))
Damien Neil7492a092019-07-10 15:23:29 -0700765 }
766 return b, nil
767}
768
Damien Neil68b81c32019-08-22 11:41:32 -0700769var coderInt32PackedSliceValue = valueCoderFuncs{
770 size: sizeInt32PackedSliceValue,
771 marshal: appendInt32PackedSliceValue,
772 unmarshal: consumeInt32SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -0700773}
774
Damien Neilc37adef2019-04-01 13:49:56 -0700775// sizeSint32 returns the size of wire encoding a int32 pointer as a Sint32.
776func sizeSint32(p pointer, tagsize int, _ marshalOptions) (size int) {
777 v := *p.Int32()
778 return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v)))
779}
780
781// appendSint32 wire encodes a int32 pointer as a Sint32.
782func appendSint32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
783 v := *p.Int32()
784 b = wire.AppendVarint(b, wiretag)
785 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v)))
786 return b, nil
787}
788
Damien Neile91877d2019-06-27 10:54:42 -0700789// consumeSint32 wire decodes a int32 pointer as a Sint32.
790func consumeSint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
791 if wtyp != wire.VarintType {
792 return 0, errUnknown
793 }
794 v, n := wire.ConsumeVarint(b)
795 if n < 0 {
796 return 0, wire.ParseError(n)
797 }
798 *p.Int32() = int32(wire.DecodeZigZag(v & math.MaxUint32))
799 return n, nil
800}
801
Damien Neilc37adef2019-04-01 13:49:56 -0700802var coderSint32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700803 size: sizeSint32,
804 marshal: appendSint32,
805 unmarshal: consumeSint32,
Damien Neilc37adef2019-04-01 13:49:56 -0700806}
807
Joe Tsaic51e2e02019-07-13 00:44:41 -0700808// sizeSint32NoZero returns the size of wire encoding a int32 pointer as a Sint32.
Damien Neilc37adef2019-04-01 13:49:56 -0700809// The zero value is not encoded.
810func sizeSint32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
811 v := *p.Int32()
812 if v == 0 {
813 return 0
814 }
815 return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v)))
816}
817
Joe Tsaic51e2e02019-07-13 00:44:41 -0700818// appendSint32NoZero wire encodes a int32 pointer as a Sint32.
Damien Neilc37adef2019-04-01 13:49:56 -0700819// The zero value is not encoded.
820func appendSint32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
821 v := *p.Int32()
822 if v == 0 {
823 return b, nil
824 }
825 b = wire.AppendVarint(b, wiretag)
826 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v)))
827 return b, nil
828}
829
830var coderSint32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700831 size: sizeSint32NoZero,
832 marshal: appendSint32NoZero,
833 unmarshal: consumeSint32,
Damien Neilc37adef2019-04-01 13:49:56 -0700834}
835
836// sizeSint32Ptr returns the size of wire encoding a *int32 pointer as a Sint32.
837// It panics if the pointer is nil.
838func sizeSint32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
839 v := **p.Int32Ptr()
840 return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v)))
841}
842
Damien Neile91877d2019-06-27 10:54:42 -0700843// appendSint32Ptr wire encodes a *int32 pointer as a Sint32.
Damien Neilc37adef2019-04-01 13:49:56 -0700844// It panics if the pointer is nil.
845func appendSint32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
846 v := **p.Int32Ptr()
847 b = wire.AppendVarint(b, wiretag)
848 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v)))
849 return b, nil
850}
851
Damien Neile91877d2019-06-27 10:54:42 -0700852// consumeSint32Ptr wire decodes a *int32 pointer as a Sint32.
853func consumeSint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
854 if wtyp != wire.VarintType {
855 return 0, errUnknown
856 }
857 v, n := wire.ConsumeVarint(b)
858 if n < 0 {
859 return 0, wire.ParseError(n)
860 }
861 vp := p.Int32Ptr()
862 if *vp == nil {
863 *vp = new(int32)
864 }
865 **vp = int32(wire.DecodeZigZag(v & math.MaxUint32))
866 return n, nil
867}
868
Damien Neilc37adef2019-04-01 13:49:56 -0700869var coderSint32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700870 size: sizeSint32Ptr,
871 marshal: appendSint32Ptr,
872 unmarshal: consumeSint32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -0700873}
874
875// sizeSint32Slice returns the size of wire encoding a []int32 pointer as a repeated Sint32.
876func sizeSint32Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
877 s := *p.Int32Slice()
878 for _, v := range s {
879 size += tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v)))
880 }
881 return size
882}
883
884// appendSint32Slice encodes a []int32 pointer as a repeated Sint32.
885func appendSint32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
886 s := *p.Int32Slice()
887 for _, v := range s {
888 b = wire.AppendVarint(b, wiretag)
889 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v)))
890 }
891 return b, nil
892}
893
Damien Neile91877d2019-06-27 10:54:42 -0700894// consumeSint32Slice wire decodes a []int32 pointer as a repeated Sint32.
895func consumeSint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
896 sp := p.Int32Slice()
897 if wtyp == wire.BytesType {
898 s := *sp
899 b, n = wire.ConsumeBytes(b)
900 if n < 0 {
901 return 0, wire.ParseError(n)
902 }
903 for len(b) > 0 {
904 v, n := wire.ConsumeVarint(b)
905 if n < 0 {
906 return 0, wire.ParseError(n)
907 }
908 s = append(s, int32(wire.DecodeZigZag(v&math.MaxUint32)))
909 b = b[n:]
910 }
911 *sp = s
912 return n, nil
913 }
914 if wtyp != wire.VarintType {
915 return 0, errUnknown
916 }
917 v, n := wire.ConsumeVarint(b)
918 if n < 0 {
919 return 0, wire.ParseError(n)
920 }
921 *sp = append(*sp, int32(wire.DecodeZigZag(v&math.MaxUint32)))
922 return n, nil
923}
924
Damien Neilc37adef2019-04-01 13:49:56 -0700925var coderSint32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700926 size: sizeSint32Slice,
927 marshal: appendSint32Slice,
928 unmarshal: consumeSint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -0700929}
930
931// sizeSint32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sint32.
932func sizeSint32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
933 s := *p.Int32Slice()
934 if len(s) == 0 {
935 return 0
936 }
937 n := 0
938 for _, v := range s {
939 n += wire.SizeVarint(wire.EncodeZigZag(int64(v)))
940 }
941 return tagsize + wire.SizeBytes(n)
942}
943
944// appendSint32PackedSlice encodes a []int32 pointer as a packed repeated Sint32.
945func appendSint32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
946 s := *p.Int32Slice()
947 if len(s) == 0 {
948 return b, nil
949 }
950 b = wire.AppendVarint(b, wiretag)
951 n := 0
952 for _, v := range s {
953 n += wire.SizeVarint(wire.EncodeZigZag(int64(v)))
954 }
955 b = wire.AppendVarint(b, uint64(n))
956 for _, v := range s {
957 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v)))
958 }
959 return b, nil
960}
961
962var coderSint32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -0700963 size: sizeSint32PackedSlice,
964 marshal: appendSint32PackedSlice,
965 unmarshal: consumeSint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -0700966}
967
Damien Neil68b81c32019-08-22 11:41:32 -0700968// sizeSint32Value returns the size of wire encoding a int32 value as a Sint32.
969func sizeSint32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
970 return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -0700971}
972
Damien Neil68b81c32019-08-22 11:41:32 -0700973// appendSint32Value encodes a int32 value as a Sint32.
974func appendSint32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -0700975 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -0700976 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -0700977 return b, nil
978}
979
Damien Neil68b81c32019-08-22 11:41:32 -0700980// consumeSint32Value decodes a int32 value as a Sint32.
981func consumeSint32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -0700982 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -0700983 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -0700984 }
985 v, n := wire.ConsumeVarint(b)
986 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -0700987 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -0700988 }
Damien Neil68b81c32019-08-22 11:41:32 -0700989 return protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32))), n, nil
Damien Neile91877d2019-06-27 10:54:42 -0700990}
991
Damien Neil68b81c32019-08-22 11:41:32 -0700992var coderSint32Value = valueCoderFuncs{
993 size: sizeSint32Value,
994 marshal: appendSint32Value,
995 unmarshal: consumeSint32Value,
Damien Neilc37adef2019-04-01 13:49:56 -0700996}
997
Damien Neil68b81c32019-08-22 11:41:32 -0700998// sizeSint32SliceValue returns the size of wire encoding a []int32 value as a repeated Sint32.
999func sizeSint32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1000 list := listv.List()
1001 for i, llen := 0, list.Len(); i < llen; i++ {
1002 v := list.Get(i)
1003 size += tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -07001004 }
1005 return size
1006}
1007
Damien Neil68b81c32019-08-22 11:41:32 -07001008// appendSint32SliceValue encodes a []int32 value as a repeated Sint32.
1009func appendSint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1010 list := listv.List()
1011 for i, llen := 0, list.Len(); i < llen; i++ {
1012 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07001013 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001014 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neilc37adef2019-04-01 13:49:56 -07001015 }
1016 return b, nil
1017}
1018
Damien Neil68b81c32019-08-22 11:41:32 -07001019// consumeSint32SliceValue wire decodes a []int32 value as a repeated Sint32.
1020func consumeSint32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
1021 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07001022 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07001023 b, n = wire.ConsumeBytes(b)
1024 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001025 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001026 }
1027 for len(b) > 0 {
1028 v, n := wire.ConsumeVarint(b)
1029 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001030 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001031 }
Damien Neil68b81c32019-08-22 11:41:32 -07001032 list.Append(protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32))))
Damien Neile91877d2019-06-27 10:54:42 -07001033 b = b[n:]
1034 }
Damien Neil68b81c32019-08-22 11:41:32 -07001035 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001036 }
1037 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001038 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001039 }
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))))
1045 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001046}
1047
Damien Neil68b81c32019-08-22 11:41:32 -07001048var coderSint32SliceValue = valueCoderFuncs{
1049 size: sizeSint32SliceValue,
1050 marshal: appendSint32SliceValue,
1051 unmarshal: consumeSint32SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07001052}
1053
Damien Neil68b81c32019-08-22 11:41:32 -07001054// sizeSint32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sint32.
1055func sizeSint32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1056 list := listv.List()
Damien Neil7492a092019-07-10 15:23:29 -07001057 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07001058 for i, llen := 0, list.Len(); i < llen; i++ {
1059 v := list.Get(i)
1060 n += wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neil7492a092019-07-10 15:23:29 -07001061 }
1062 return tagsize + wire.SizeBytes(n)
1063}
1064
Damien Neil68b81c32019-08-22 11:41:32 -07001065// appendSint32PackedSliceValue encodes a []int32 value as a packed repeated Sint32.
1066func appendSint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1067 list := listv.List()
1068 llen := list.Len()
1069 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07001070 return b, nil
1071 }
1072 b = wire.AppendVarint(b, wiretag)
1073 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07001074 for i := 0; i < llen; i++ {
1075 v := list.Get(i)
1076 n += wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neil7492a092019-07-10 15:23:29 -07001077 }
1078 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07001079 for i := 0; i < llen; i++ {
1080 v := list.Get(i)
1081 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int()))))
Damien Neil7492a092019-07-10 15:23:29 -07001082 }
1083 return b, nil
1084}
1085
Damien Neil68b81c32019-08-22 11:41:32 -07001086var coderSint32PackedSliceValue = valueCoderFuncs{
1087 size: sizeSint32PackedSliceValue,
1088 marshal: appendSint32PackedSliceValue,
1089 unmarshal: consumeSint32SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07001090}
1091
Damien Neilc37adef2019-04-01 13:49:56 -07001092// sizeUint32 returns the size of wire encoding a uint32 pointer as a Uint32.
1093func sizeUint32(p pointer, tagsize int, _ marshalOptions) (size int) {
1094 v := *p.Uint32()
1095 return tagsize + wire.SizeVarint(uint64(v))
1096}
1097
1098// appendUint32 wire encodes a uint32 pointer as a Uint32.
1099func appendUint32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1100 v := *p.Uint32()
1101 b = wire.AppendVarint(b, wiretag)
1102 b = wire.AppendVarint(b, uint64(v))
1103 return b, nil
1104}
1105
Damien Neile91877d2019-06-27 10:54:42 -07001106// consumeUint32 wire decodes a uint32 pointer as a Uint32.
1107func consumeUint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1108 if wtyp != wire.VarintType {
1109 return 0, errUnknown
1110 }
1111 v, n := wire.ConsumeVarint(b)
1112 if n < 0 {
1113 return 0, wire.ParseError(n)
1114 }
1115 *p.Uint32() = uint32(v)
1116 return n, nil
1117}
1118
Damien Neilc37adef2019-04-01 13:49:56 -07001119var coderUint32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001120 size: sizeUint32,
1121 marshal: appendUint32,
1122 unmarshal: consumeUint32,
Damien Neilc37adef2019-04-01 13:49:56 -07001123}
1124
Joe Tsaic51e2e02019-07-13 00:44:41 -07001125// sizeUint32NoZero returns the size of wire encoding a uint32 pointer as a Uint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001126// The zero value is not encoded.
1127func sizeUint32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
1128 v := *p.Uint32()
1129 if v == 0 {
1130 return 0
1131 }
1132 return tagsize + wire.SizeVarint(uint64(v))
1133}
1134
Joe Tsaic51e2e02019-07-13 00:44:41 -07001135// appendUint32NoZero wire encodes a uint32 pointer as a Uint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001136// The zero value is not encoded.
1137func appendUint32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1138 v := *p.Uint32()
1139 if v == 0 {
1140 return b, nil
1141 }
1142 b = wire.AppendVarint(b, wiretag)
1143 b = wire.AppendVarint(b, uint64(v))
1144 return b, nil
1145}
1146
1147var coderUint32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001148 size: sizeUint32NoZero,
1149 marshal: appendUint32NoZero,
1150 unmarshal: consumeUint32,
Damien Neilc37adef2019-04-01 13:49:56 -07001151}
1152
1153// sizeUint32Ptr returns the size of wire encoding a *uint32 pointer as a Uint32.
1154// It panics if the pointer is nil.
1155func sizeUint32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
1156 v := **p.Uint32Ptr()
1157 return tagsize + wire.SizeVarint(uint64(v))
1158}
1159
Damien Neile91877d2019-06-27 10:54:42 -07001160// appendUint32Ptr wire encodes a *uint32 pointer as a Uint32.
Damien Neilc37adef2019-04-01 13:49:56 -07001161// It panics if the pointer is nil.
1162func appendUint32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1163 v := **p.Uint32Ptr()
1164 b = wire.AppendVarint(b, wiretag)
1165 b = wire.AppendVarint(b, uint64(v))
1166 return b, nil
1167}
1168
Damien Neile91877d2019-06-27 10:54:42 -07001169// consumeUint32Ptr wire decodes a *uint32 pointer as a Uint32.
1170func consumeUint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1171 if wtyp != wire.VarintType {
1172 return 0, errUnknown
1173 }
1174 v, n := wire.ConsumeVarint(b)
1175 if n < 0 {
1176 return 0, wire.ParseError(n)
1177 }
1178 vp := p.Uint32Ptr()
1179 if *vp == nil {
1180 *vp = new(uint32)
1181 }
1182 **vp = uint32(v)
1183 return n, nil
1184}
1185
Damien Neilc37adef2019-04-01 13:49:56 -07001186var coderUint32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001187 size: sizeUint32Ptr,
1188 marshal: appendUint32Ptr,
1189 unmarshal: consumeUint32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07001190}
1191
1192// sizeUint32Slice returns the size of wire encoding a []uint32 pointer as a repeated Uint32.
1193func sizeUint32Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
1194 s := *p.Uint32Slice()
1195 for _, v := range s {
1196 size += tagsize + wire.SizeVarint(uint64(v))
1197 }
1198 return size
1199}
1200
1201// appendUint32Slice encodes a []uint32 pointer as a repeated Uint32.
1202func appendUint32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1203 s := *p.Uint32Slice()
1204 for _, v := range s {
1205 b = wire.AppendVarint(b, wiretag)
1206 b = wire.AppendVarint(b, uint64(v))
1207 }
1208 return b, nil
1209}
1210
Damien Neile91877d2019-06-27 10:54:42 -07001211// consumeUint32Slice wire decodes a []uint32 pointer as a repeated Uint32.
1212func consumeUint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1213 sp := p.Uint32Slice()
1214 if wtyp == wire.BytesType {
1215 s := *sp
1216 b, n = wire.ConsumeBytes(b)
1217 if n < 0 {
1218 return 0, wire.ParseError(n)
1219 }
1220 for len(b) > 0 {
1221 v, n := wire.ConsumeVarint(b)
1222 if n < 0 {
1223 return 0, wire.ParseError(n)
1224 }
1225 s = append(s, uint32(v))
1226 b = b[n:]
1227 }
1228 *sp = s
1229 return n, nil
1230 }
1231 if wtyp != wire.VarintType {
1232 return 0, errUnknown
1233 }
1234 v, n := wire.ConsumeVarint(b)
1235 if n < 0 {
1236 return 0, wire.ParseError(n)
1237 }
1238 *sp = append(*sp, uint32(v))
1239 return n, nil
1240}
1241
Damien Neilc37adef2019-04-01 13:49:56 -07001242var coderUint32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001243 size: sizeUint32Slice,
1244 marshal: appendUint32Slice,
1245 unmarshal: consumeUint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001246}
1247
1248// sizeUint32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Uint32.
1249func sizeUint32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
1250 s := *p.Uint32Slice()
1251 if len(s) == 0 {
1252 return 0
1253 }
1254 n := 0
1255 for _, v := range s {
1256 n += wire.SizeVarint(uint64(v))
1257 }
1258 return tagsize + wire.SizeBytes(n)
1259}
1260
1261// appendUint32PackedSlice encodes a []uint32 pointer as a packed repeated Uint32.
1262func appendUint32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1263 s := *p.Uint32Slice()
1264 if len(s) == 0 {
1265 return b, nil
1266 }
1267 b = wire.AppendVarint(b, wiretag)
1268 n := 0
1269 for _, v := range s {
1270 n += wire.SizeVarint(uint64(v))
1271 }
1272 b = wire.AppendVarint(b, uint64(n))
1273 for _, v := range s {
1274 b = wire.AppendVarint(b, uint64(v))
1275 }
1276 return b, nil
1277}
1278
1279var coderUint32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001280 size: sizeUint32PackedSlice,
1281 marshal: appendUint32PackedSlice,
1282 unmarshal: consumeUint32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001283}
1284
Damien Neil68b81c32019-08-22 11:41:32 -07001285// sizeUint32Value returns the size of wire encoding a uint32 value as a Uint32.
1286func sizeUint32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
1287 return tagsize + wire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001288}
1289
Damien Neil68b81c32019-08-22 11:41:32 -07001290// appendUint32Value encodes a uint32 value as a Uint32.
1291func appendUint32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001292 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001293 b = wire.AppendVarint(b, uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001294 return b, nil
1295}
1296
Damien Neil68b81c32019-08-22 11:41:32 -07001297// consumeUint32Value decodes a uint32 value as a Uint32.
1298func consumeUint32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07001299 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001300 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001301 }
1302 v, n := wire.ConsumeVarint(b)
1303 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001304 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001305 }
Damien Neil68b81c32019-08-22 11:41:32 -07001306 return protoreflect.ValueOfUint32(uint32(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001307}
1308
Damien Neil68b81c32019-08-22 11:41:32 -07001309var coderUint32Value = valueCoderFuncs{
1310 size: sizeUint32Value,
1311 marshal: appendUint32Value,
1312 unmarshal: consumeUint32Value,
Damien Neilc37adef2019-04-01 13:49:56 -07001313}
1314
Damien Neil68b81c32019-08-22 11:41:32 -07001315// sizeUint32SliceValue returns the size of wire encoding a []uint32 value as a repeated Uint32.
1316func sizeUint32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1317 list := listv.List()
1318 for i, llen := 0, list.Len(); i < llen; i++ {
1319 v := list.Get(i)
1320 size += tagsize + wire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001321 }
1322 return size
1323}
1324
Damien Neil68b81c32019-08-22 11:41:32 -07001325// appendUint32SliceValue encodes a []uint32 value as a repeated Uint32.
1326func appendUint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1327 list := listv.List()
1328 for i, llen := 0, list.Len(); i < llen; i++ {
1329 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07001330 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001331 b = wire.AppendVarint(b, uint64(uint32(v.Uint())))
Damien Neilc37adef2019-04-01 13:49:56 -07001332 }
1333 return b, nil
1334}
1335
Damien Neil68b81c32019-08-22 11:41:32 -07001336// consumeUint32SliceValue wire decodes a []uint32 value as a repeated Uint32.
1337func consumeUint32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
1338 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07001339 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07001340 b, n = wire.ConsumeBytes(b)
1341 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001342 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001343 }
1344 for len(b) > 0 {
1345 v, n := wire.ConsumeVarint(b)
1346 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001347 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001348 }
Damien Neil68b81c32019-08-22 11:41:32 -07001349 list.Append(protoreflect.ValueOfUint32(uint32(v)))
Damien Neile91877d2019-06-27 10:54:42 -07001350 b = b[n:]
1351 }
Damien Neil68b81c32019-08-22 11:41:32 -07001352 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001353 }
1354 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001355 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001356 }
1357 v, n := wire.ConsumeVarint(b)
1358 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001359 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001360 }
Damien Neil68b81c32019-08-22 11:41:32 -07001361 list.Append(protoreflect.ValueOfUint32(uint32(v)))
1362 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001363}
1364
Damien Neil68b81c32019-08-22 11:41:32 -07001365var coderUint32SliceValue = valueCoderFuncs{
1366 size: sizeUint32SliceValue,
1367 marshal: appendUint32SliceValue,
1368 unmarshal: consumeUint32SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07001369}
1370
Damien Neil68b81c32019-08-22 11:41:32 -07001371// sizeUint32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Uint32.
1372func sizeUint32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1373 list := listv.List()
Damien Neil7492a092019-07-10 15:23:29 -07001374 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07001375 for i, llen := 0, list.Len(); i < llen; i++ {
1376 v := list.Get(i)
1377 n += wire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neil7492a092019-07-10 15:23:29 -07001378 }
1379 return tagsize + wire.SizeBytes(n)
1380}
1381
Damien Neil68b81c32019-08-22 11:41:32 -07001382// appendUint32PackedSliceValue encodes a []uint32 value as a packed repeated Uint32.
1383func appendUint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1384 list := listv.List()
1385 llen := list.Len()
1386 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07001387 return b, nil
1388 }
1389 b = wire.AppendVarint(b, wiretag)
1390 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07001391 for i := 0; i < llen; i++ {
1392 v := list.Get(i)
1393 n += wire.SizeVarint(uint64(uint32(v.Uint())))
Damien Neil7492a092019-07-10 15:23:29 -07001394 }
1395 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07001396 for i := 0; i < llen; i++ {
1397 v := list.Get(i)
1398 b = wire.AppendVarint(b, uint64(uint32(v.Uint())))
Damien Neil7492a092019-07-10 15:23:29 -07001399 }
1400 return b, nil
1401}
1402
Damien Neil68b81c32019-08-22 11:41:32 -07001403var coderUint32PackedSliceValue = valueCoderFuncs{
1404 size: sizeUint32PackedSliceValue,
1405 marshal: appendUint32PackedSliceValue,
1406 unmarshal: consumeUint32SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07001407}
1408
Damien Neilc37adef2019-04-01 13:49:56 -07001409// sizeInt64 returns the size of wire encoding a int64 pointer as a Int64.
1410func sizeInt64(p pointer, tagsize int, _ marshalOptions) (size int) {
1411 v := *p.Int64()
1412 return tagsize + wire.SizeVarint(uint64(v))
1413}
1414
1415// appendInt64 wire encodes a int64 pointer as a Int64.
1416func appendInt64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1417 v := *p.Int64()
1418 b = wire.AppendVarint(b, wiretag)
1419 b = wire.AppendVarint(b, uint64(v))
1420 return b, nil
1421}
1422
Damien Neile91877d2019-06-27 10:54:42 -07001423// consumeInt64 wire decodes a int64 pointer as a Int64.
1424func consumeInt64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1425 if wtyp != wire.VarintType {
1426 return 0, errUnknown
1427 }
1428 v, n := wire.ConsumeVarint(b)
1429 if n < 0 {
1430 return 0, wire.ParseError(n)
1431 }
1432 *p.Int64() = int64(v)
1433 return n, nil
1434}
1435
Damien Neilc37adef2019-04-01 13:49:56 -07001436var coderInt64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001437 size: sizeInt64,
1438 marshal: appendInt64,
1439 unmarshal: consumeInt64,
Damien Neilc37adef2019-04-01 13:49:56 -07001440}
1441
Joe Tsaic51e2e02019-07-13 00:44:41 -07001442// sizeInt64NoZero returns the size of wire encoding a int64 pointer as a Int64.
Damien Neilc37adef2019-04-01 13:49:56 -07001443// The zero value is not encoded.
1444func sizeInt64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
1445 v := *p.Int64()
1446 if v == 0 {
1447 return 0
1448 }
1449 return tagsize + wire.SizeVarint(uint64(v))
1450}
1451
Joe Tsaic51e2e02019-07-13 00:44:41 -07001452// appendInt64NoZero wire encodes a int64 pointer as a Int64.
Damien Neilc37adef2019-04-01 13:49:56 -07001453// The zero value is not encoded.
1454func appendInt64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1455 v := *p.Int64()
1456 if v == 0 {
1457 return b, nil
1458 }
1459 b = wire.AppendVarint(b, wiretag)
1460 b = wire.AppendVarint(b, uint64(v))
1461 return b, nil
1462}
1463
1464var coderInt64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001465 size: sizeInt64NoZero,
1466 marshal: appendInt64NoZero,
1467 unmarshal: consumeInt64,
Damien Neilc37adef2019-04-01 13:49:56 -07001468}
1469
1470// sizeInt64Ptr returns the size of wire encoding a *int64 pointer as a Int64.
1471// It panics if the pointer is nil.
1472func sizeInt64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
1473 v := **p.Int64Ptr()
1474 return tagsize + wire.SizeVarint(uint64(v))
1475}
1476
Damien Neile91877d2019-06-27 10:54:42 -07001477// appendInt64Ptr wire encodes a *int64 pointer as a Int64.
Damien Neilc37adef2019-04-01 13:49:56 -07001478// It panics if the pointer is nil.
1479func appendInt64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1480 v := **p.Int64Ptr()
1481 b = wire.AppendVarint(b, wiretag)
1482 b = wire.AppendVarint(b, uint64(v))
1483 return b, nil
1484}
1485
Damien Neile91877d2019-06-27 10:54:42 -07001486// consumeInt64Ptr wire decodes a *int64 pointer as a Int64.
1487func consumeInt64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1488 if wtyp != wire.VarintType {
1489 return 0, errUnknown
1490 }
1491 v, n := wire.ConsumeVarint(b)
1492 if n < 0 {
1493 return 0, wire.ParseError(n)
1494 }
1495 vp := p.Int64Ptr()
1496 if *vp == nil {
1497 *vp = new(int64)
1498 }
1499 **vp = int64(v)
1500 return n, nil
1501}
1502
Damien Neilc37adef2019-04-01 13:49:56 -07001503var coderInt64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001504 size: sizeInt64Ptr,
1505 marshal: appendInt64Ptr,
1506 unmarshal: consumeInt64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07001507}
1508
1509// sizeInt64Slice returns the size of wire encoding a []int64 pointer as a repeated Int64.
1510func sizeInt64Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
1511 s := *p.Int64Slice()
1512 for _, v := range s {
1513 size += tagsize + wire.SizeVarint(uint64(v))
1514 }
1515 return size
1516}
1517
1518// appendInt64Slice encodes a []int64 pointer as a repeated Int64.
1519func appendInt64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1520 s := *p.Int64Slice()
1521 for _, v := range s {
1522 b = wire.AppendVarint(b, wiretag)
1523 b = wire.AppendVarint(b, uint64(v))
1524 }
1525 return b, nil
1526}
1527
Damien Neile91877d2019-06-27 10:54:42 -07001528// consumeInt64Slice wire decodes a []int64 pointer as a repeated Int64.
1529func consumeInt64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1530 sp := p.Int64Slice()
1531 if wtyp == wire.BytesType {
1532 s := *sp
1533 b, n = wire.ConsumeBytes(b)
1534 if n < 0 {
1535 return 0, wire.ParseError(n)
1536 }
1537 for len(b) > 0 {
1538 v, n := wire.ConsumeVarint(b)
1539 if n < 0 {
1540 return 0, wire.ParseError(n)
1541 }
1542 s = append(s, int64(v))
1543 b = b[n:]
1544 }
1545 *sp = s
1546 return n, nil
1547 }
1548 if wtyp != wire.VarintType {
1549 return 0, errUnknown
1550 }
1551 v, n := wire.ConsumeVarint(b)
1552 if n < 0 {
1553 return 0, wire.ParseError(n)
1554 }
1555 *sp = append(*sp, int64(v))
1556 return n, nil
1557}
1558
Damien Neilc37adef2019-04-01 13:49:56 -07001559var coderInt64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001560 size: sizeInt64Slice,
1561 marshal: appendInt64Slice,
1562 unmarshal: consumeInt64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001563}
1564
1565// sizeInt64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Int64.
1566func sizeInt64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
1567 s := *p.Int64Slice()
1568 if len(s) == 0 {
1569 return 0
1570 }
1571 n := 0
1572 for _, v := range s {
1573 n += wire.SizeVarint(uint64(v))
1574 }
1575 return tagsize + wire.SizeBytes(n)
1576}
1577
1578// appendInt64PackedSlice encodes a []int64 pointer as a packed repeated Int64.
1579func appendInt64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1580 s := *p.Int64Slice()
1581 if len(s) == 0 {
1582 return b, nil
1583 }
1584 b = wire.AppendVarint(b, wiretag)
1585 n := 0
1586 for _, v := range s {
1587 n += wire.SizeVarint(uint64(v))
1588 }
1589 b = wire.AppendVarint(b, uint64(n))
1590 for _, v := range s {
1591 b = wire.AppendVarint(b, uint64(v))
1592 }
1593 return b, nil
1594}
1595
1596var coderInt64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001597 size: sizeInt64PackedSlice,
1598 marshal: appendInt64PackedSlice,
1599 unmarshal: consumeInt64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001600}
1601
Damien Neil68b81c32019-08-22 11:41:32 -07001602// sizeInt64Value returns the size of wire encoding a int64 value as a Int64.
1603func sizeInt64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
1604 return tagsize + wire.SizeVarint(uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001605}
1606
Damien Neil68b81c32019-08-22 11:41:32 -07001607// appendInt64Value encodes a int64 value as a Int64.
1608func appendInt64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001609 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001610 b = wire.AppendVarint(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001611 return b, nil
1612}
1613
Damien Neil68b81c32019-08-22 11:41:32 -07001614// consumeInt64Value decodes a int64 value as a Int64.
1615func consumeInt64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07001616 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001617 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001618 }
1619 v, n := wire.ConsumeVarint(b)
1620 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001621 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001622 }
Damien Neil68b81c32019-08-22 11:41:32 -07001623 return protoreflect.ValueOfInt64(int64(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001624}
1625
Damien Neil68b81c32019-08-22 11:41:32 -07001626var coderInt64Value = valueCoderFuncs{
1627 size: sizeInt64Value,
1628 marshal: appendInt64Value,
1629 unmarshal: consumeInt64Value,
Damien Neilc37adef2019-04-01 13:49:56 -07001630}
1631
Damien Neil68b81c32019-08-22 11:41:32 -07001632// sizeInt64SliceValue returns the size of wire encoding a []int64 value as a repeated Int64.
1633func sizeInt64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1634 list := listv.List()
1635 for i, llen := 0, list.Len(); i < llen; i++ {
1636 v := list.Get(i)
1637 size += tagsize + wire.SizeVarint(uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001638 }
1639 return size
1640}
1641
Damien Neil68b81c32019-08-22 11:41:32 -07001642// appendInt64SliceValue encodes a []int64 value as a repeated Int64.
1643func appendInt64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1644 list := listv.List()
1645 for i, llen := 0, list.Len(); i < llen; i++ {
1646 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07001647 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001648 b = wire.AppendVarint(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001649 }
1650 return b, nil
1651}
1652
Damien Neil68b81c32019-08-22 11:41:32 -07001653// consumeInt64SliceValue wire decodes a []int64 value as a repeated Int64.
1654func consumeInt64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
1655 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07001656 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07001657 b, n = wire.ConsumeBytes(b)
1658 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001659 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001660 }
1661 for len(b) > 0 {
1662 v, n := wire.ConsumeVarint(b)
1663 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001664 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001665 }
Damien Neil68b81c32019-08-22 11:41:32 -07001666 list.Append(protoreflect.ValueOfInt64(int64(v)))
Damien Neile91877d2019-06-27 10:54:42 -07001667 b = b[n:]
1668 }
Damien Neil68b81c32019-08-22 11:41:32 -07001669 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001670 }
1671 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001672 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001673 }
1674 v, n := wire.ConsumeVarint(b)
1675 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001676 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001677 }
Damien Neil68b81c32019-08-22 11:41:32 -07001678 list.Append(protoreflect.ValueOfInt64(int64(v)))
1679 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001680}
1681
Damien Neil68b81c32019-08-22 11:41:32 -07001682var coderInt64SliceValue = valueCoderFuncs{
1683 size: sizeInt64SliceValue,
1684 marshal: appendInt64SliceValue,
1685 unmarshal: consumeInt64SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07001686}
1687
Damien Neil68b81c32019-08-22 11:41:32 -07001688// sizeInt64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Int64.
1689func sizeInt64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1690 list := listv.List()
Damien Neil7492a092019-07-10 15:23:29 -07001691 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07001692 for i, llen := 0, list.Len(); i < llen; i++ {
1693 v := list.Get(i)
1694 n += wire.SizeVarint(uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07001695 }
1696 return tagsize + wire.SizeBytes(n)
1697}
1698
Damien Neil68b81c32019-08-22 11:41:32 -07001699// appendInt64PackedSliceValue encodes a []int64 value as a packed repeated Int64.
1700func appendInt64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1701 list := listv.List()
1702 llen := list.Len()
1703 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07001704 return b, nil
1705 }
1706 b = wire.AppendVarint(b, wiretag)
1707 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07001708 for i := 0; i < llen; i++ {
1709 v := list.Get(i)
1710 n += wire.SizeVarint(uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07001711 }
1712 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07001713 for i := 0; i < llen; i++ {
1714 v := list.Get(i)
1715 b = wire.AppendVarint(b, uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07001716 }
1717 return b, nil
1718}
1719
Damien Neil68b81c32019-08-22 11:41:32 -07001720var coderInt64PackedSliceValue = valueCoderFuncs{
1721 size: sizeInt64PackedSliceValue,
1722 marshal: appendInt64PackedSliceValue,
1723 unmarshal: consumeInt64SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07001724}
1725
Damien Neilc37adef2019-04-01 13:49:56 -07001726// sizeSint64 returns the size of wire encoding a int64 pointer as a Sint64.
1727func sizeSint64(p pointer, tagsize int, _ marshalOptions) (size int) {
1728 v := *p.Int64()
1729 return tagsize + wire.SizeVarint(wire.EncodeZigZag(v))
1730}
1731
1732// appendSint64 wire encodes a int64 pointer as a Sint64.
1733func appendSint64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1734 v := *p.Int64()
1735 b = wire.AppendVarint(b, wiretag)
1736 b = wire.AppendVarint(b, wire.EncodeZigZag(v))
1737 return b, nil
1738}
1739
Damien Neile91877d2019-06-27 10:54:42 -07001740// consumeSint64 wire decodes a int64 pointer as a Sint64.
1741func consumeSint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1742 if wtyp != wire.VarintType {
1743 return 0, errUnknown
1744 }
1745 v, n := wire.ConsumeVarint(b)
1746 if n < 0 {
1747 return 0, wire.ParseError(n)
1748 }
1749 *p.Int64() = wire.DecodeZigZag(v)
1750 return n, nil
1751}
1752
Damien Neilc37adef2019-04-01 13:49:56 -07001753var coderSint64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001754 size: sizeSint64,
1755 marshal: appendSint64,
1756 unmarshal: consumeSint64,
Damien Neilc37adef2019-04-01 13:49:56 -07001757}
1758
Joe Tsaic51e2e02019-07-13 00:44:41 -07001759// sizeSint64NoZero returns the size of wire encoding a int64 pointer as a Sint64.
Damien Neilc37adef2019-04-01 13:49:56 -07001760// The zero value is not encoded.
1761func sizeSint64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
1762 v := *p.Int64()
1763 if v == 0 {
1764 return 0
1765 }
1766 return tagsize + wire.SizeVarint(wire.EncodeZigZag(v))
1767}
1768
Joe Tsaic51e2e02019-07-13 00:44:41 -07001769// appendSint64NoZero wire encodes a int64 pointer as a Sint64.
Damien Neilc37adef2019-04-01 13:49:56 -07001770// The zero value is not encoded.
1771func appendSint64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1772 v := *p.Int64()
1773 if v == 0 {
1774 return b, nil
1775 }
1776 b = wire.AppendVarint(b, wiretag)
1777 b = wire.AppendVarint(b, wire.EncodeZigZag(v))
1778 return b, nil
1779}
1780
1781var coderSint64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001782 size: sizeSint64NoZero,
1783 marshal: appendSint64NoZero,
1784 unmarshal: consumeSint64,
Damien Neilc37adef2019-04-01 13:49:56 -07001785}
1786
1787// sizeSint64Ptr returns the size of wire encoding a *int64 pointer as a Sint64.
1788// It panics if the pointer is nil.
1789func sizeSint64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
1790 v := **p.Int64Ptr()
1791 return tagsize + wire.SizeVarint(wire.EncodeZigZag(v))
1792}
1793
Damien Neile91877d2019-06-27 10:54:42 -07001794// appendSint64Ptr wire encodes a *int64 pointer as a Sint64.
Damien Neilc37adef2019-04-01 13:49:56 -07001795// It panics if the pointer is nil.
1796func appendSint64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1797 v := **p.Int64Ptr()
1798 b = wire.AppendVarint(b, wiretag)
1799 b = wire.AppendVarint(b, wire.EncodeZigZag(v))
1800 return b, nil
1801}
1802
Damien Neile91877d2019-06-27 10:54:42 -07001803// consumeSint64Ptr wire decodes a *int64 pointer as a Sint64.
1804func consumeSint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1805 if wtyp != wire.VarintType {
1806 return 0, errUnknown
1807 }
1808 v, n := wire.ConsumeVarint(b)
1809 if n < 0 {
1810 return 0, wire.ParseError(n)
1811 }
1812 vp := p.Int64Ptr()
1813 if *vp == nil {
1814 *vp = new(int64)
1815 }
1816 **vp = wire.DecodeZigZag(v)
1817 return n, nil
1818}
1819
Damien Neilc37adef2019-04-01 13:49:56 -07001820var coderSint64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001821 size: sizeSint64Ptr,
1822 marshal: appendSint64Ptr,
1823 unmarshal: consumeSint64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07001824}
1825
1826// sizeSint64Slice returns the size of wire encoding a []int64 pointer as a repeated Sint64.
1827func sizeSint64Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
1828 s := *p.Int64Slice()
1829 for _, v := range s {
1830 size += tagsize + wire.SizeVarint(wire.EncodeZigZag(v))
1831 }
1832 return size
1833}
1834
1835// appendSint64Slice encodes a []int64 pointer as a repeated Sint64.
1836func appendSint64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1837 s := *p.Int64Slice()
1838 for _, v := range s {
1839 b = wire.AppendVarint(b, wiretag)
1840 b = wire.AppendVarint(b, wire.EncodeZigZag(v))
1841 }
1842 return b, nil
1843}
1844
Damien Neile91877d2019-06-27 10:54:42 -07001845// consumeSint64Slice wire decodes a []int64 pointer as a repeated Sint64.
1846func consumeSint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
1847 sp := p.Int64Slice()
1848 if wtyp == wire.BytesType {
1849 s := *sp
1850 b, n = wire.ConsumeBytes(b)
1851 if n < 0 {
1852 return 0, wire.ParseError(n)
1853 }
1854 for len(b) > 0 {
1855 v, n := wire.ConsumeVarint(b)
1856 if n < 0 {
1857 return 0, wire.ParseError(n)
1858 }
1859 s = append(s, wire.DecodeZigZag(v))
1860 b = b[n:]
1861 }
1862 *sp = s
1863 return n, nil
1864 }
1865 if wtyp != wire.VarintType {
1866 return 0, errUnknown
1867 }
1868 v, n := wire.ConsumeVarint(b)
1869 if n < 0 {
1870 return 0, wire.ParseError(n)
1871 }
1872 *sp = append(*sp, wire.DecodeZigZag(v))
1873 return n, nil
1874}
1875
Damien Neilc37adef2019-04-01 13:49:56 -07001876var coderSint64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001877 size: sizeSint64Slice,
1878 marshal: appendSint64Slice,
1879 unmarshal: consumeSint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001880}
1881
1882// sizeSint64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sint64.
1883func sizeSint64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
1884 s := *p.Int64Slice()
1885 if len(s) == 0 {
1886 return 0
1887 }
1888 n := 0
1889 for _, v := range s {
1890 n += wire.SizeVarint(wire.EncodeZigZag(v))
1891 }
1892 return tagsize + wire.SizeBytes(n)
1893}
1894
1895// appendSint64PackedSlice encodes a []int64 pointer as a packed repeated Sint64.
1896func appendSint64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
1897 s := *p.Int64Slice()
1898 if len(s) == 0 {
1899 return b, nil
1900 }
1901 b = wire.AppendVarint(b, wiretag)
1902 n := 0
1903 for _, v := range s {
1904 n += wire.SizeVarint(wire.EncodeZigZag(v))
1905 }
1906 b = wire.AppendVarint(b, uint64(n))
1907 for _, v := range s {
1908 b = wire.AppendVarint(b, wire.EncodeZigZag(v))
1909 }
1910 return b, nil
1911}
1912
1913var coderSint64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07001914 size: sizeSint64PackedSlice,
1915 marshal: appendSint64PackedSlice,
1916 unmarshal: consumeSint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07001917}
1918
Damien Neil68b81c32019-08-22 11:41:32 -07001919// sizeSint64Value returns the size of wire encoding a int64 value as a Sint64.
1920func sizeSint64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
1921 return tagsize + wire.SizeVarint(wire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001922}
1923
Damien Neil68b81c32019-08-22 11:41:32 -07001924// appendSint64Value encodes a int64 value as a Sint64.
1925func appendSint64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07001926 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001927 b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001928 return b, nil
1929}
1930
Damien Neil68b81c32019-08-22 11:41:32 -07001931// consumeSint64Value decodes a int64 value as a Sint64.
1932func consumeSint64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07001933 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001934 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001935 }
1936 v, n := wire.ConsumeVarint(b)
1937 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001938 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001939 }
Damien Neil68b81c32019-08-22 11:41:32 -07001940 return protoreflect.ValueOfInt64(wire.DecodeZigZag(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001941}
1942
Damien Neil68b81c32019-08-22 11:41:32 -07001943var coderSint64Value = valueCoderFuncs{
1944 size: sizeSint64Value,
1945 marshal: appendSint64Value,
1946 unmarshal: consumeSint64Value,
Damien Neilc37adef2019-04-01 13:49:56 -07001947}
1948
Damien Neil68b81c32019-08-22 11:41:32 -07001949// sizeSint64SliceValue returns the size of wire encoding a []int64 value as a repeated Sint64.
1950func sizeSint64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
1951 list := listv.List()
1952 for i, llen := 0, list.Len(); i < llen; i++ {
1953 v := list.Get(i)
1954 size += tagsize + wire.SizeVarint(wire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001955 }
1956 return size
1957}
1958
Damien Neil68b81c32019-08-22 11:41:32 -07001959// appendSint64SliceValue encodes a []int64 value as a repeated Sint64.
1960func appendSint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
1961 list := listv.List()
1962 for i, llen := 0, list.Len(); i < llen; i++ {
1963 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07001964 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07001965 b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07001966 }
1967 return b, nil
1968}
1969
Damien Neil68b81c32019-08-22 11:41:32 -07001970// consumeSint64SliceValue wire decodes a []int64 value as a repeated Sint64.
1971func consumeSint64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
1972 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07001973 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07001974 b, n = wire.ConsumeBytes(b)
1975 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001976 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001977 }
1978 for len(b) > 0 {
1979 v, n := wire.ConsumeVarint(b)
1980 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001981 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001982 }
Damien Neil68b81c32019-08-22 11:41:32 -07001983 list.Append(protoreflect.ValueOfInt64(wire.DecodeZigZag(v)))
Damien Neile91877d2019-06-27 10:54:42 -07001984 b = b[n:]
1985 }
Damien Neil68b81c32019-08-22 11:41:32 -07001986 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001987 }
1988 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07001989 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07001990 }
1991 v, n := wire.ConsumeVarint(b)
1992 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07001993 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07001994 }
Damien Neil68b81c32019-08-22 11:41:32 -07001995 list.Append(protoreflect.ValueOfInt64(wire.DecodeZigZag(v)))
1996 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07001997}
1998
Damien Neil68b81c32019-08-22 11:41:32 -07001999var coderSint64SliceValue = valueCoderFuncs{
2000 size: sizeSint64SliceValue,
2001 marshal: appendSint64SliceValue,
2002 unmarshal: consumeSint64SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002003}
2004
Damien Neil68b81c32019-08-22 11:41:32 -07002005// sizeSint64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sint64.
2006func sizeSint64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2007 list := listv.List()
Damien Neil7492a092019-07-10 15:23:29 -07002008 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07002009 for i, llen := 0, list.Len(); i < llen; i++ {
2010 v := list.Get(i)
2011 n += wire.SizeVarint(wire.EncodeZigZag(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002012 }
2013 return tagsize + wire.SizeBytes(n)
2014}
2015
Damien Neil68b81c32019-08-22 11:41:32 -07002016// appendSint64PackedSliceValue encodes a []int64 value as a packed repeated Sint64.
2017func appendSint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2018 list := listv.List()
2019 llen := list.Len()
2020 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07002021 return b, nil
2022 }
2023 b = wire.AppendVarint(b, wiretag)
2024 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07002025 for i := 0; i < llen; i++ {
2026 v := list.Get(i)
2027 n += wire.SizeVarint(wire.EncodeZigZag(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002028 }
2029 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07002030 for i := 0; i < llen; i++ {
2031 v := list.Get(i)
2032 b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002033 }
2034 return b, nil
2035}
2036
Damien Neil68b81c32019-08-22 11:41:32 -07002037var coderSint64PackedSliceValue = valueCoderFuncs{
2038 size: sizeSint64PackedSliceValue,
2039 marshal: appendSint64PackedSliceValue,
2040 unmarshal: consumeSint64SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07002041}
2042
Damien Neilc37adef2019-04-01 13:49:56 -07002043// sizeUint64 returns the size of wire encoding a uint64 pointer as a Uint64.
2044func sizeUint64(p pointer, tagsize int, _ marshalOptions) (size int) {
2045 v := *p.Uint64()
2046 return tagsize + wire.SizeVarint(v)
2047}
2048
2049// appendUint64 wire encodes a uint64 pointer as a Uint64.
2050func appendUint64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2051 v := *p.Uint64()
2052 b = wire.AppendVarint(b, wiretag)
2053 b = wire.AppendVarint(b, v)
2054 return b, nil
2055}
2056
Damien Neile91877d2019-06-27 10:54:42 -07002057// consumeUint64 wire decodes a uint64 pointer as a Uint64.
2058func consumeUint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2059 if wtyp != wire.VarintType {
2060 return 0, errUnknown
2061 }
2062 v, n := wire.ConsumeVarint(b)
2063 if n < 0 {
2064 return 0, wire.ParseError(n)
2065 }
2066 *p.Uint64() = v
2067 return n, nil
2068}
2069
Damien Neilc37adef2019-04-01 13:49:56 -07002070var coderUint64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002071 size: sizeUint64,
2072 marshal: appendUint64,
2073 unmarshal: consumeUint64,
Damien Neilc37adef2019-04-01 13:49:56 -07002074}
2075
Joe Tsaic51e2e02019-07-13 00:44:41 -07002076// sizeUint64NoZero returns the size of wire encoding a uint64 pointer as a Uint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002077// The zero value is not encoded.
2078func sizeUint64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
2079 v := *p.Uint64()
2080 if v == 0 {
2081 return 0
2082 }
2083 return tagsize + wire.SizeVarint(v)
2084}
2085
Joe Tsaic51e2e02019-07-13 00:44:41 -07002086// appendUint64NoZero wire encodes a uint64 pointer as a Uint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002087// The zero value is not encoded.
2088func appendUint64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2089 v := *p.Uint64()
2090 if v == 0 {
2091 return b, nil
2092 }
2093 b = wire.AppendVarint(b, wiretag)
2094 b = wire.AppendVarint(b, v)
2095 return b, nil
2096}
2097
2098var coderUint64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002099 size: sizeUint64NoZero,
2100 marshal: appendUint64NoZero,
2101 unmarshal: consumeUint64,
Damien Neilc37adef2019-04-01 13:49:56 -07002102}
2103
2104// sizeUint64Ptr returns the size of wire encoding a *uint64 pointer as a Uint64.
2105// It panics if the pointer is nil.
2106func sizeUint64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
2107 v := **p.Uint64Ptr()
2108 return tagsize + wire.SizeVarint(v)
2109}
2110
Damien Neile91877d2019-06-27 10:54:42 -07002111// appendUint64Ptr wire encodes a *uint64 pointer as a Uint64.
Damien Neilc37adef2019-04-01 13:49:56 -07002112// It panics if the pointer is nil.
2113func appendUint64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2114 v := **p.Uint64Ptr()
2115 b = wire.AppendVarint(b, wiretag)
2116 b = wire.AppendVarint(b, v)
2117 return b, nil
2118}
2119
Damien Neile91877d2019-06-27 10:54:42 -07002120// consumeUint64Ptr wire decodes a *uint64 pointer as a Uint64.
2121func consumeUint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2122 if wtyp != wire.VarintType {
2123 return 0, errUnknown
2124 }
2125 v, n := wire.ConsumeVarint(b)
2126 if n < 0 {
2127 return 0, wire.ParseError(n)
2128 }
2129 vp := p.Uint64Ptr()
2130 if *vp == nil {
2131 *vp = new(uint64)
2132 }
2133 **vp = v
2134 return n, nil
2135}
2136
Damien Neilc37adef2019-04-01 13:49:56 -07002137var coderUint64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002138 size: sizeUint64Ptr,
2139 marshal: appendUint64Ptr,
2140 unmarshal: consumeUint64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07002141}
2142
2143// sizeUint64Slice returns the size of wire encoding a []uint64 pointer as a repeated Uint64.
2144func sizeUint64Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
2145 s := *p.Uint64Slice()
2146 for _, v := range s {
2147 size += tagsize + wire.SizeVarint(v)
2148 }
2149 return size
2150}
2151
2152// appendUint64Slice encodes a []uint64 pointer as a repeated Uint64.
2153func appendUint64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2154 s := *p.Uint64Slice()
2155 for _, v := range s {
2156 b = wire.AppendVarint(b, wiretag)
2157 b = wire.AppendVarint(b, v)
2158 }
2159 return b, nil
2160}
2161
Damien Neile91877d2019-06-27 10:54:42 -07002162// consumeUint64Slice wire decodes a []uint64 pointer as a repeated Uint64.
2163func consumeUint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2164 sp := p.Uint64Slice()
2165 if wtyp == wire.BytesType {
2166 s := *sp
2167 b, n = wire.ConsumeBytes(b)
2168 if n < 0 {
2169 return 0, wire.ParseError(n)
2170 }
2171 for len(b) > 0 {
2172 v, n := wire.ConsumeVarint(b)
2173 if n < 0 {
2174 return 0, wire.ParseError(n)
2175 }
2176 s = append(s, v)
2177 b = b[n:]
2178 }
2179 *sp = s
2180 return n, nil
2181 }
2182 if wtyp != wire.VarintType {
2183 return 0, errUnknown
2184 }
2185 v, n := wire.ConsumeVarint(b)
2186 if n < 0 {
2187 return 0, wire.ParseError(n)
2188 }
2189 *sp = append(*sp, v)
2190 return n, nil
2191}
2192
Damien Neilc37adef2019-04-01 13:49:56 -07002193var coderUint64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002194 size: sizeUint64Slice,
2195 marshal: appendUint64Slice,
2196 unmarshal: consumeUint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002197}
2198
2199// sizeUint64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Uint64.
2200func sizeUint64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
2201 s := *p.Uint64Slice()
2202 if len(s) == 0 {
2203 return 0
2204 }
2205 n := 0
2206 for _, v := range s {
2207 n += wire.SizeVarint(v)
2208 }
2209 return tagsize + wire.SizeBytes(n)
2210}
2211
2212// appendUint64PackedSlice encodes a []uint64 pointer as a packed repeated Uint64.
2213func appendUint64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2214 s := *p.Uint64Slice()
2215 if len(s) == 0 {
2216 return b, nil
2217 }
2218 b = wire.AppendVarint(b, wiretag)
2219 n := 0
2220 for _, v := range s {
2221 n += wire.SizeVarint(v)
2222 }
2223 b = wire.AppendVarint(b, uint64(n))
2224 for _, v := range s {
2225 b = wire.AppendVarint(b, v)
2226 }
2227 return b, nil
2228}
2229
2230var coderUint64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002231 size: sizeUint64PackedSlice,
2232 marshal: appendUint64PackedSlice,
2233 unmarshal: consumeUint64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002234}
2235
Damien Neil68b81c32019-08-22 11:41:32 -07002236// sizeUint64Value returns the size of wire encoding a uint64 value as a Uint64.
2237func sizeUint64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
2238 return tagsize + wire.SizeVarint(v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002239}
2240
Damien Neil68b81c32019-08-22 11:41:32 -07002241// appendUint64Value encodes a uint64 value as a Uint64.
2242func appendUint64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002243 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002244 b = wire.AppendVarint(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002245 return b, nil
2246}
2247
Damien Neil68b81c32019-08-22 11:41:32 -07002248// consumeUint64Value decodes a uint64 value as a Uint64.
2249func consumeUint64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07002250 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07002251 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002252 }
2253 v, n := wire.ConsumeVarint(b)
2254 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002255 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002256 }
Damien Neil68b81c32019-08-22 11:41:32 -07002257 return protoreflect.ValueOfUint64(v), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002258}
2259
Damien Neil68b81c32019-08-22 11:41:32 -07002260var coderUint64Value = valueCoderFuncs{
2261 size: sizeUint64Value,
2262 marshal: appendUint64Value,
2263 unmarshal: consumeUint64Value,
Damien Neilc37adef2019-04-01 13:49:56 -07002264}
2265
Damien Neil68b81c32019-08-22 11:41:32 -07002266// sizeUint64SliceValue returns the size of wire encoding a []uint64 value as a repeated Uint64.
2267func sizeUint64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2268 list := listv.List()
2269 for i, llen := 0, list.Len(); i < llen; i++ {
2270 v := list.Get(i)
2271 size += tagsize + wire.SizeVarint(v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002272 }
2273 return size
2274}
2275
Damien Neil68b81c32019-08-22 11:41:32 -07002276// appendUint64SliceValue encodes a []uint64 value as a repeated Uint64.
2277func appendUint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2278 list := listv.List()
2279 for i, llen := 0, list.Len(); i < llen; i++ {
2280 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07002281 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002282 b = wire.AppendVarint(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07002283 }
2284 return b, nil
2285}
2286
Damien Neil68b81c32019-08-22 11:41:32 -07002287// consumeUint64SliceValue wire decodes a []uint64 value as a repeated Uint64.
2288func consumeUint64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
2289 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07002290 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07002291 b, n = wire.ConsumeBytes(b)
2292 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002293 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002294 }
2295 for len(b) > 0 {
2296 v, n := wire.ConsumeVarint(b)
2297 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002298 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002299 }
Damien Neil68b81c32019-08-22 11:41:32 -07002300 list.Append(protoreflect.ValueOfUint64(v))
Damien Neile91877d2019-06-27 10:54:42 -07002301 b = b[n:]
2302 }
Damien Neil68b81c32019-08-22 11:41:32 -07002303 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002304 }
2305 if wtyp != wire.VarintType {
Damien Neil68b81c32019-08-22 11:41:32 -07002306 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002307 }
2308 v, n := wire.ConsumeVarint(b)
2309 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002310 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002311 }
Damien Neil68b81c32019-08-22 11:41:32 -07002312 list.Append(protoreflect.ValueOfUint64(v))
2313 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002314}
2315
Damien Neil68b81c32019-08-22 11:41:32 -07002316var coderUint64SliceValue = valueCoderFuncs{
2317 size: sizeUint64SliceValue,
2318 marshal: appendUint64SliceValue,
2319 unmarshal: consumeUint64SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002320}
2321
Damien Neil68b81c32019-08-22 11:41:32 -07002322// sizeUint64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Uint64.
2323func sizeUint64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2324 list := listv.List()
Damien Neil7492a092019-07-10 15:23:29 -07002325 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07002326 for i, llen := 0, list.Len(); i < llen; i++ {
2327 v := list.Get(i)
2328 n += wire.SizeVarint(v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07002329 }
2330 return tagsize + wire.SizeBytes(n)
2331}
2332
Damien Neil68b81c32019-08-22 11:41:32 -07002333// appendUint64PackedSliceValue encodes a []uint64 value as a packed repeated Uint64.
2334func appendUint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2335 list := listv.List()
2336 llen := list.Len()
2337 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07002338 return b, nil
2339 }
2340 b = wire.AppendVarint(b, wiretag)
2341 n := 0
Damien Neil68b81c32019-08-22 11:41:32 -07002342 for i := 0; i < llen; i++ {
2343 v := list.Get(i)
2344 n += wire.SizeVarint(v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07002345 }
2346 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07002347 for i := 0; i < llen; i++ {
2348 v := list.Get(i)
2349 b = wire.AppendVarint(b, v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07002350 }
2351 return b, nil
2352}
2353
Damien Neil68b81c32019-08-22 11:41:32 -07002354var coderUint64PackedSliceValue = valueCoderFuncs{
2355 size: sizeUint64PackedSliceValue,
2356 marshal: appendUint64PackedSliceValue,
2357 unmarshal: consumeUint64SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07002358}
2359
Damien Neilc37adef2019-04-01 13:49:56 -07002360// sizeSfixed32 returns the size of wire encoding a int32 pointer as a Sfixed32.
2361func sizeSfixed32(p pointer, tagsize int, _ marshalOptions) (size int) {
2362
2363 return tagsize + wire.SizeFixed32()
2364}
2365
2366// appendSfixed32 wire encodes a int32 pointer as a Sfixed32.
2367func appendSfixed32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2368 v := *p.Int32()
2369 b = wire.AppendVarint(b, wiretag)
2370 b = wire.AppendFixed32(b, uint32(v))
2371 return b, nil
2372}
2373
Damien Neile91877d2019-06-27 10:54:42 -07002374// consumeSfixed32 wire decodes a int32 pointer as a Sfixed32.
2375func consumeSfixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2376 if wtyp != wire.Fixed32Type {
2377 return 0, errUnknown
2378 }
2379 v, n := wire.ConsumeFixed32(b)
2380 if n < 0 {
2381 return 0, wire.ParseError(n)
2382 }
2383 *p.Int32() = int32(v)
2384 return n, nil
2385}
2386
Damien Neilc37adef2019-04-01 13:49:56 -07002387var coderSfixed32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002388 size: sizeSfixed32,
2389 marshal: appendSfixed32,
2390 unmarshal: consumeSfixed32,
Damien Neilc37adef2019-04-01 13:49:56 -07002391}
2392
Joe Tsaic51e2e02019-07-13 00:44:41 -07002393// sizeSfixed32NoZero returns the size of wire encoding a int32 pointer as a Sfixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002394// The zero value is not encoded.
2395func sizeSfixed32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
2396 v := *p.Int32()
2397 if v == 0 {
2398 return 0
2399 }
2400 return tagsize + wire.SizeFixed32()
2401}
2402
Joe Tsaic51e2e02019-07-13 00:44:41 -07002403// appendSfixed32NoZero wire encodes a int32 pointer as a Sfixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002404// The zero value is not encoded.
2405func appendSfixed32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2406 v := *p.Int32()
2407 if v == 0 {
2408 return b, nil
2409 }
2410 b = wire.AppendVarint(b, wiretag)
2411 b = wire.AppendFixed32(b, uint32(v))
2412 return b, nil
2413}
2414
2415var coderSfixed32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002416 size: sizeSfixed32NoZero,
2417 marshal: appendSfixed32NoZero,
2418 unmarshal: consumeSfixed32,
Damien Neilc37adef2019-04-01 13:49:56 -07002419}
2420
2421// sizeSfixed32Ptr returns the size of wire encoding a *int32 pointer as a Sfixed32.
2422// It panics if the pointer is nil.
2423func sizeSfixed32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
2424 return tagsize + wire.SizeFixed32()
2425}
2426
Damien Neile91877d2019-06-27 10:54:42 -07002427// appendSfixed32Ptr wire encodes a *int32 pointer as a Sfixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002428// It panics if the pointer is nil.
2429func appendSfixed32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2430 v := **p.Int32Ptr()
2431 b = wire.AppendVarint(b, wiretag)
2432 b = wire.AppendFixed32(b, uint32(v))
2433 return b, nil
2434}
2435
Damien Neile91877d2019-06-27 10:54:42 -07002436// consumeSfixed32Ptr wire decodes a *int32 pointer as a Sfixed32.
2437func consumeSfixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2438 if wtyp != wire.Fixed32Type {
2439 return 0, errUnknown
2440 }
2441 v, n := wire.ConsumeFixed32(b)
2442 if n < 0 {
2443 return 0, wire.ParseError(n)
2444 }
2445 vp := p.Int32Ptr()
2446 if *vp == nil {
2447 *vp = new(int32)
2448 }
2449 **vp = int32(v)
2450 return n, nil
2451}
2452
Damien Neilc37adef2019-04-01 13:49:56 -07002453var coderSfixed32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002454 size: sizeSfixed32Ptr,
2455 marshal: appendSfixed32Ptr,
2456 unmarshal: consumeSfixed32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07002457}
2458
2459// sizeSfixed32Slice returns the size of wire encoding a []int32 pointer as a repeated Sfixed32.
2460func sizeSfixed32Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
2461 s := *p.Int32Slice()
2462 size = len(s) * (tagsize + wire.SizeFixed32())
2463 return size
2464}
2465
2466// appendSfixed32Slice encodes a []int32 pointer as a repeated Sfixed32.
2467func appendSfixed32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2468 s := *p.Int32Slice()
2469 for _, v := range s {
2470 b = wire.AppendVarint(b, wiretag)
2471 b = wire.AppendFixed32(b, uint32(v))
2472 }
2473 return b, nil
2474}
2475
Damien Neile91877d2019-06-27 10:54:42 -07002476// consumeSfixed32Slice wire decodes a []int32 pointer as a repeated Sfixed32.
2477func consumeSfixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2478 sp := p.Int32Slice()
2479 if wtyp == wire.BytesType {
2480 s := *sp
2481 b, n = wire.ConsumeBytes(b)
2482 if n < 0 {
2483 return 0, wire.ParseError(n)
2484 }
2485 for len(b) > 0 {
2486 v, n := wire.ConsumeFixed32(b)
2487 if n < 0 {
2488 return 0, wire.ParseError(n)
2489 }
2490 s = append(s, int32(v))
2491 b = b[n:]
2492 }
2493 *sp = s
2494 return n, nil
2495 }
2496 if wtyp != wire.Fixed32Type {
2497 return 0, errUnknown
2498 }
2499 v, n := wire.ConsumeFixed32(b)
2500 if n < 0 {
2501 return 0, wire.ParseError(n)
2502 }
2503 *sp = append(*sp, int32(v))
2504 return n, nil
2505}
2506
Damien Neilc37adef2019-04-01 13:49:56 -07002507var coderSfixed32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002508 size: sizeSfixed32Slice,
2509 marshal: appendSfixed32Slice,
2510 unmarshal: consumeSfixed32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002511}
2512
2513// sizeSfixed32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sfixed32.
2514func sizeSfixed32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
2515 s := *p.Int32Slice()
2516 if len(s) == 0 {
2517 return 0
2518 }
2519 n := len(s) * wire.SizeFixed32()
2520 return tagsize + wire.SizeBytes(n)
2521}
2522
2523// appendSfixed32PackedSlice encodes a []int32 pointer as a packed repeated Sfixed32.
2524func appendSfixed32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2525 s := *p.Int32Slice()
2526 if len(s) == 0 {
2527 return b, nil
2528 }
2529 b = wire.AppendVarint(b, wiretag)
2530 n := len(s) * wire.SizeFixed32()
2531 b = wire.AppendVarint(b, uint64(n))
2532 for _, v := range s {
2533 b = wire.AppendFixed32(b, uint32(v))
2534 }
2535 return b, nil
2536}
2537
2538var coderSfixed32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002539 size: sizeSfixed32PackedSlice,
2540 marshal: appendSfixed32PackedSlice,
2541 unmarshal: consumeSfixed32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002542}
2543
Damien Neil68b81c32019-08-22 11:41:32 -07002544// sizeSfixed32Value returns the size of wire encoding a int32 value as a Sfixed32.
2545func sizeSfixed32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07002546 return tagsize + wire.SizeFixed32()
2547}
2548
Damien Neil68b81c32019-08-22 11:41:32 -07002549// appendSfixed32Value encodes a int32 value as a Sfixed32.
2550func appendSfixed32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002551 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002552 b = wire.AppendFixed32(b, uint32(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002553 return b, nil
2554}
2555
Damien Neil68b81c32019-08-22 11:41:32 -07002556// consumeSfixed32Value decodes a int32 value as a Sfixed32.
2557func consumeSfixed32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07002558 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07002559 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002560 }
2561 v, n := wire.ConsumeFixed32(b)
2562 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002563 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002564 }
Damien Neil68b81c32019-08-22 11:41:32 -07002565 return protoreflect.ValueOfInt32(int32(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002566}
2567
Damien Neil68b81c32019-08-22 11:41:32 -07002568var coderSfixed32Value = valueCoderFuncs{
2569 size: sizeSfixed32Value,
2570 marshal: appendSfixed32Value,
2571 unmarshal: consumeSfixed32Value,
Damien Neilc37adef2019-04-01 13:49:56 -07002572}
2573
Damien Neil68b81c32019-08-22 11:41:32 -07002574// sizeSfixed32SliceValue returns the size of wire encoding a []int32 value as a repeated Sfixed32.
2575func sizeSfixed32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2576 list := listv.List()
2577 size = list.Len() * (tagsize + wire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07002578 return size
2579}
2580
Damien Neil68b81c32019-08-22 11:41:32 -07002581// appendSfixed32SliceValue encodes a []int32 value as a repeated Sfixed32.
2582func appendSfixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2583 list := listv.List()
2584 for i, llen := 0, list.Len(); i < llen; i++ {
2585 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07002586 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002587 b = wire.AppendFixed32(b, uint32(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07002588 }
2589 return b, nil
2590}
2591
Damien Neil68b81c32019-08-22 11:41:32 -07002592// consumeSfixed32SliceValue wire decodes a []int32 value as a repeated Sfixed32.
2593func consumeSfixed32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
2594 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07002595 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07002596 b, n = wire.ConsumeBytes(b)
2597 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002598 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002599 }
2600 for len(b) > 0 {
2601 v, n := wire.ConsumeFixed32(b)
2602 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002603 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002604 }
Damien Neil68b81c32019-08-22 11:41:32 -07002605 list.Append(protoreflect.ValueOfInt32(int32(v)))
Damien Neile91877d2019-06-27 10:54:42 -07002606 b = b[n:]
2607 }
Damien Neil68b81c32019-08-22 11:41:32 -07002608 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002609 }
2610 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07002611 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002612 }
2613 v, n := wire.ConsumeFixed32(b)
2614 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002615 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002616 }
Damien Neil68b81c32019-08-22 11:41:32 -07002617 list.Append(protoreflect.ValueOfInt32(int32(v)))
2618 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002619}
2620
Damien Neil68b81c32019-08-22 11:41:32 -07002621var coderSfixed32SliceValue = valueCoderFuncs{
2622 size: sizeSfixed32SliceValue,
2623 marshal: appendSfixed32SliceValue,
2624 unmarshal: consumeSfixed32SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002625}
2626
Damien Neil68b81c32019-08-22 11:41:32 -07002627// sizeSfixed32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sfixed32.
2628func sizeSfixed32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2629 list := listv.List()
2630 n := list.Len() * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07002631 return tagsize + wire.SizeBytes(n)
2632}
2633
Damien Neil68b81c32019-08-22 11:41:32 -07002634// appendSfixed32PackedSliceValue encodes a []int32 value as a packed repeated Sfixed32.
2635func appendSfixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2636 list := listv.List()
2637 llen := list.Len()
2638 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07002639 return b, nil
2640 }
2641 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002642 n := llen * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07002643 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07002644 for i := 0; i < llen; i++ {
2645 v := list.Get(i)
2646 b = wire.AppendFixed32(b, uint32(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07002647 }
2648 return b, nil
2649}
2650
Damien Neil68b81c32019-08-22 11:41:32 -07002651var coderSfixed32PackedSliceValue = valueCoderFuncs{
2652 size: sizeSfixed32PackedSliceValue,
2653 marshal: appendSfixed32PackedSliceValue,
2654 unmarshal: consumeSfixed32SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07002655}
2656
Damien Neilc37adef2019-04-01 13:49:56 -07002657// sizeFixed32 returns the size of wire encoding a uint32 pointer as a Fixed32.
2658func sizeFixed32(p pointer, tagsize int, _ marshalOptions) (size int) {
2659
2660 return tagsize + wire.SizeFixed32()
2661}
2662
2663// appendFixed32 wire encodes a uint32 pointer as a Fixed32.
2664func appendFixed32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2665 v := *p.Uint32()
2666 b = wire.AppendVarint(b, wiretag)
2667 b = wire.AppendFixed32(b, v)
2668 return b, nil
2669}
2670
Damien Neile91877d2019-06-27 10:54:42 -07002671// consumeFixed32 wire decodes a uint32 pointer as a Fixed32.
2672func consumeFixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2673 if wtyp != wire.Fixed32Type {
2674 return 0, errUnknown
2675 }
2676 v, n := wire.ConsumeFixed32(b)
2677 if n < 0 {
2678 return 0, wire.ParseError(n)
2679 }
2680 *p.Uint32() = v
2681 return n, nil
2682}
2683
Damien Neilc37adef2019-04-01 13:49:56 -07002684var coderFixed32 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002685 size: sizeFixed32,
2686 marshal: appendFixed32,
2687 unmarshal: consumeFixed32,
Damien Neilc37adef2019-04-01 13:49:56 -07002688}
2689
Joe Tsaic51e2e02019-07-13 00:44:41 -07002690// sizeFixed32NoZero returns the size of wire encoding a uint32 pointer as a Fixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002691// The zero value is not encoded.
2692func sizeFixed32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
2693 v := *p.Uint32()
2694 if v == 0 {
2695 return 0
2696 }
2697 return tagsize + wire.SizeFixed32()
2698}
2699
Joe Tsaic51e2e02019-07-13 00:44:41 -07002700// appendFixed32NoZero wire encodes a uint32 pointer as a Fixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002701// The zero value is not encoded.
2702func appendFixed32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2703 v := *p.Uint32()
2704 if v == 0 {
2705 return b, nil
2706 }
2707 b = wire.AppendVarint(b, wiretag)
2708 b = wire.AppendFixed32(b, v)
2709 return b, nil
2710}
2711
2712var coderFixed32NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002713 size: sizeFixed32NoZero,
2714 marshal: appendFixed32NoZero,
2715 unmarshal: consumeFixed32,
Damien Neilc37adef2019-04-01 13:49:56 -07002716}
2717
2718// sizeFixed32Ptr returns the size of wire encoding a *uint32 pointer as a Fixed32.
2719// It panics if the pointer is nil.
2720func sizeFixed32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
2721 return tagsize + wire.SizeFixed32()
2722}
2723
Damien Neile91877d2019-06-27 10:54:42 -07002724// appendFixed32Ptr wire encodes a *uint32 pointer as a Fixed32.
Damien Neilc37adef2019-04-01 13:49:56 -07002725// It panics if the pointer is nil.
2726func appendFixed32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2727 v := **p.Uint32Ptr()
2728 b = wire.AppendVarint(b, wiretag)
2729 b = wire.AppendFixed32(b, v)
2730 return b, nil
2731}
2732
Damien Neile91877d2019-06-27 10:54:42 -07002733// consumeFixed32Ptr wire decodes a *uint32 pointer as a Fixed32.
2734func consumeFixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2735 if wtyp != wire.Fixed32Type {
2736 return 0, errUnknown
2737 }
2738 v, n := wire.ConsumeFixed32(b)
2739 if n < 0 {
2740 return 0, wire.ParseError(n)
2741 }
2742 vp := p.Uint32Ptr()
2743 if *vp == nil {
2744 *vp = new(uint32)
2745 }
2746 **vp = v
2747 return n, nil
2748}
2749
Damien Neilc37adef2019-04-01 13:49:56 -07002750var coderFixed32Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002751 size: sizeFixed32Ptr,
2752 marshal: appendFixed32Ptr,
2753 unmarshal: consumeFixed32Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07002754}
2755
2756// sizeFixed32Slice returns the size of wire encoding a []uint32 pointer as a repeated Fixed32.
2757func sizeFixed32Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
2758 s := *p.Uint32Slice()
2759 size = len(s) * (tagsize + wire.SizeFixed32())
2760 return size
2761}
2762
2763// appendFixed32Slice encodes a []uint32 pointer as a repeated Fixed32.
2764func appendFixed32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2765 s := *p.Uint32Slice()
2766 for _, v := range s {
2767 b = wire.AppendVarint(b, wiretag)
2768 b = wire.AppendFixed32(b, v)
2769 }
2770 return b, nil
2771}
2772
Damien Neile91877d2019-06-27 10:54:42 -07002773// consumeFixed32Slice wire decodes a []uint32 pointer as a repeated Fixed32.
2774func consumeFixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2775 sp := p.Uint32Slice()
2776 if wtyp == wire.BytesType {
2777 s := *sp
2778 b, n = wire.ConsumeBytes(b)
2779 if n < 0 {
2780 return 0, wire.ParseError(n)
2781 }
2782 for len(b) > 0 {
2783 v, n := wire.ConsumeFixed32(b)
2784 if n < 0 {
2785 return 0, wire.ParseError(n)
2786 }
2787 s = append(s, v)
2788 b = b[n:]
2789 }
2790 *sp = s
2791 return n, nil
2792 }
2793 if wtyp != wire.Fixed32Type {
2794 return 0, errUnknown
2795 }
2796 v, n := wire.ConsumeFixed32(b)
2797 if n < 0 {
2798 return 0, wire.ParseError(n)
2799 }
2800 *sp = append(*sp, v)
2801 return n, nil
2802}
2803
Damien Neilc37adef2019-04-01 13:49:56 -07002804var coderFixed32Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002805 size: sizeFixed32Slice,
2806 marshal: appendFixed32Slice,
2807 unmarshal: consumeFixed32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002808}
2809
2810// sizeFixed32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Fixed32.
2811func sizeFixed32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
2812 s := *p.Uint32Slice()
2813 if len(s) == 0 {
2814 return 0
2815 }
2816 n := len(s) * wire.SizeFixed32()
2817 return tagsize + wire.SizeBytes(n)
2818}
2819
2820// appendFixed32PackedSlice encodes a []uint32 pointer as a packed repeated Fixed32.
2821func appendFixed32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2822 s := *p.Uint32Slice()
2823 if len(s) == 0 {
2824 return b, nil
2825 }
2826 b = wire.AppendVarint(b, wiretag)
2827 n := len(s) * wire.SizeFixed32()
2828 b = wire.AppendVarint(b, uint64(n))
2829 for _, v := range s {
2830 b = wire.AppendFixed32(b, v)
2831 }
2832 return b, nil
2833}
2834
2835var coderFixed32PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002836 size: sizeFixed32PackedSlice,
2837 marshal: appendFixed32PackedSlice,
2838 unmarshal: consumeFixed32Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07002839}
2840
Damien Neil68b81c32019-08-22 11:41:32 -07002841// sizeFixed32Value returns the size of wire encoding a uint32 value as a Fixed32.
2842func sizeFixed32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07002843 return tagsize + wire.SizeFixed32()
2844}
2845
Damien Neil68b81c32019-08-22 11:41:32 -07002846// appendFixed32Value encodes a uint32 value as a Fixed32.
2847func appendFixed32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07002848 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002849 b = wire.AppendFixed32(b, uint32(v.Uint()))
Damien Neilc37adef2019-04-01 13:49:56 -07002850 return b, nil
2851}
2852
Damien Neil68b81c32019-08-22 11:41:32 -07002853// consumeFixed32Value decodes a uint32 value as a Fixed32.
2854func consumeFixed32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07002855 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07002856 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002857 }
2858 v, n := wire.ConsumeFixed32(b)
2859 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002860 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002861 }
Damien Neil68b81c32019-08-22 11:41:32 -07002862 return protoreflect.ValueOfUint32(uint32(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002863}
2864
Damien Neil68b81c32019-08-22 11:41:32 -07002865var coderFixed32Value = valueCoderFuncs{
2866 size: sizeFixed32Value,
2867 marshal: appendFixed32Value,
2868 unmarshal: consumeFixed32Value,
Damien Neilc37adef2019-04-01 13:49:56 -07002869}
2870
Damien Neil68b81c32019-08-22 11:41:32 -07002871// sizeFixed32SliceValue returns the size of wire encoding a []uint32 value as a repeated Fixed32.
2872func sizeFixed32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2873 list := listv.List()
2874 size = list.Len() * (tagsize + wire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07002875 return size
2876}
2877
Damien Neil68b81c32019-08-22 11:41:32 -07002878// appendFixed32SliceValue encodes a []uint32 value as a repeated Fixed32.
2879func appendFixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2880 list := listv.List()
2881 for i, llen := 0, list.Len(); i < llen; i++ {
2882 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07002883 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002884 b = wire.AppendFixed32(b, uint32(v.Uint()))
Damien Neilc37adef2019-04-01 13:49:56 -07002885 }
2886 return b, nil
2887}
2888
Damien Neil68b81c32019-08-22 11:41:32 -07002889// consumeFixed32SliceValue wire decodes a []uint32 value as a repeated Fixed32.
2890func consumeFixed32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
2891 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07002892 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07002893 b, n = wire.ConsumeBytes(b)
2894 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002895 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002896 }
2897 for len(b) > 0 {
2898 v, n := wire.ConsumeFixed32(b)
2899 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002900 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002901 }
Damien Neil68b81c32019-08-22 11:41:32 -07002902 list.Append(protoreflect.ValueOfUint32(uint32(v)))
Damien Neile91877d2019-06-27 10:54:42 -07002903 b = b[n:]
2904 }
Damien Neil68b81c32019-08-22 11:41:32 -07002905 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002906 }
2907 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07002908 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07002909 }
2910 v, n := wire.ConsumeFixed32(b)
2911 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07002912 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07002913 }
Damien Neil68b81c32019-08-22 11:41:32 -07002914 list.Append(protoreflect.ValueOfUint32(uint32(v)))
2915 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07002916}
2917
Damien Neil68b81c32019-08-22 11:41:32 -07002918var coderFixed32SliceValue = valueCoderFuncs{
2919 size: sizeFixed32SliceValue,
2920 marshal: appendFixed32SliceValue,
2921 unmarshal: consumeFixed32SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07002922}
2923
Damien Neil68b81c32019-08-22 11:41:32 -07002924// sizeFixed32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Fixed32.
2925func sizeFixed32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
2926 list := listv.List()
2927 n := list.Len() * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07002928 return tagsize + wire.SizeBytes(n)
2929}
2930
Damien Neil68b81c32019-08-22 11:41:32 -07002931// appendFixed32PackedSliceValue encodes a []uint32 value as a packed repeated Fixed32.
2932func appendFixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
2933 list := listv.List()
2934 llen := list.Len()
2935 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07002936 return b, nil
2937 }
2938 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07002939 n := llen * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07002940 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07002941 for i := 0; i < llen; i++ {
2942 v := list.Get(i)
2943 b = wire.AppendFixed32(b, uint32(v.Uint()))
Damien Neil7492a092019-07-10 15:23:29 -07002944 }
2945 return b, nil
2946}
2947
Damien Neil68b81c32019-08-22 11:41:32 -07002948var coderFixed32PackedSliceValue = valueCoderFuncs{
2949 size: sizeFixed32PackedSliceValue,
2950 marshal: appendFixed32PackedSliceValue,
2951 unmarshal: consumeFixed32SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07002952}
2953
Damien Neilc37adef2019-04-01 13:49:56 -07002954// sizeFloat returns the size of wire encoding a float32 pointer as a Float.
2955func sizeFloat(p pointer, tagsize int, _ marshalOptions) (size int) {
2956
2957 return tagsize + wire.SizeFixed32()
2958}
2959
2960// appendFloat wire encodes a float32 pointer as a Float.
2961func appendFloat(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
2962 v := *p.Float32()
2963 b = wire.AppendVarint(b, wiretag)
2964 b = wire.AppendFixed32(b, math.Float32bits(v))
2965 return b, nil
2966}
2967
Damien Neile91877d2019-06-27 10:54:42 -07002968// consumeFloat wire decodes a float32 pointer as a Float.
2969func consumeFloat(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
2970 if wtyp != wire.Fixed32Type {
2971 return 0, errUnknown
2972 }
2973 v, n := wire.ConsumeFixed32(b)
2974 if n < 0 {
2975 return 0, wire.ParseError(n)
2976 }
2977 *p.Float32() = math.Float32frombits(v)
2978 return n, nil
2979}
2980
Damien Neilc37adef2019-04-01 13:49:56 -07002981var coderFloat = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07002982 size: sizeFloat,
2983 marshal: appendFloat,
2984 unmarshal: consumeFloat,
Damien Neilc37adef2019-04-01 13:49:56 -07002985}
2986
Joe Tsaic51e2e02019-07-13 00:44:41 -07002987// sizeFloatNoZero returns the size of wire encoding a float32 pointer as a Float.
Damien Neilc37adef2019-04-01 13:49:56 -07002988// The zero value is not encoded.
2989func sizeFloatNoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
2990 v := *p.Float32()
2991 if v == 0 && !math.Signbit(float64(v)) {
2992 return 0
2993 }
2994 return tagsize + wire.SizeFixed32()
2995}
2996
Joe Tsaic51e2e02019-07-13 00:44:41 -07002997// appendFloatNoZero wire encodes a float32 pointer as a Float.
Damien Neilc37adef2019-04-01 13:49:56 -07002998// The zero value is not encoded.
2999func appendFloatNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3000 v := *p.Float32()
3001 if v == 0 && !math.Signbit(float64(v)) {
3002 return b, nil
3003 }
3004 b = wire.AppendVarint(b, wiretag)
3005 b = wire.AppendFixed32(b, math.Float32bits(v))
3006 return b, nil
3007}
3008
3009var coderFloatNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003010 size: sizeFloatNoZero,
3011 marshal: appendFloatNoZero,
3012 unmarshal: consumeFloat,
Damien Neilc37adef2019-04-01 13:49:56 -07003013}
3014
3015// sizeFloatPtr returns the size of wire encoding a *float32 pointer as a Float.
3016// It panics if the pointer is nil.
3017func sizeFloatPtr(p pointer, tagsize int, _ marshalOptions) (size int) {
3018 return tagsize + wire.SizeFixed32()
3019}
3020
Damien Neile91877d2019-06-27 10:54:42 -07003021// appendFloatPtr wire encodes a *float32 pointer as a Float.
Damien Neilc37adef2019-04-01 13:49:56 -07003022// It panics if the pointer is nil.
3023func appendFloatPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3024 v := **p.Float32Ptr()
3025 b = wire.AppendVarint(b, wiretag)
3026 b = wire.AppendFixed32(b, math.Float32bits(v))
3027 return b, nil
3028}
3029
Damien Neile91877d2019-06-27 10:54:42 -07003030// consumeFloatPtr wire decodes a *float32 pointer as a Float.
3031func consumeFloatPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3032 if wtyp != wire.Fixed32Type {
3033 return 0, errUnknown
3034 }
3035 v, n := wire.ConsumeFixed32(b)
3036 if n < 0 {
3037 return 0, wire.ParseError(n)
3038 }
3039 vp := p.Float32Ptr()
3040 if *vp == nil {
3041 *vp = new(float32)
3042 }
3043 **vp = math.Float32frombits(v)
3044 return n, nil
3045}
3046
Damien Neilc37adef2019-04-01 13:49:56 -07003047var coderFloatPtr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003048 size: sizeFloatPtr,
3049 marshal: appendFloatPtr,
3050 unmarshal: consumeFloatPtr,
Damien Neilc37adef2019-04-01 13:49:56 -07003051}
3052
3053// sizeFloatSlice returns the size of wire encoding a []float32 pointer as a repeated Float.
3054func sizeFloatSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
3055 s := *p.Float32Slice()
3056 size = len(s) * (tagsize + wire.SizeFixed32())
3057 return size
3058}
3059
3060// appendFloatSlice encodes a []float32 pointer as a repeated Float.
3061func appendFloatSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3062 s := *p.Float32Slice()
3063 for _, v := range s {
3064 b = wire.AppendVarint(b, wiretag)
3065 b = wire.AppendFixed32(b, math.Float32bits(v))
3066 }
3067 return b, nil
3068}
3069
Damien Neile91877d2019-06-27 10:54:42 -07003070// consumeFloatSlice wire decodes a []float32 pointer as a repeated Float.
3071func consumeFloatSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3072 sp := p.Float32Slice()
3073 if wtyp == wire.BytesType {
3074 s := *sp
3075 b, n = wire.ConsumeBytes(b)
3076 if n < 0 {
3077 return 0, wire.ParseError(n)
3078 }
3079 for len(b) > 0 {
3080 v, n := wire.ConsumeFixed32(b)
3081 if n < 0 {
3082 return 0, wire.ParseError(n)
3083 }
3084 s = append(s, math.Float32frombits(v))
3085 b = b[n:]
3086 }
3087 *sp = s
3088 return n, nil
3089 }
3090 if wtyp != wire.Fixed32Type {
3091 return 0, errUnknown
3092 }
3093 v, n := wire.ConsumeFixed32(b)
3094 if n < 0 {
3095 return 0, wire.ParseError(n)
3096 }
3097 *sp = append(*sp, math.Float32frombits(v))
3098 return n, nil
3099}
3100
Damien Neilc37adef2019-04-01 13:49:56 -07003101var coderFloatSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003102 size: sizeFloatSlice,
3103 marshal: appendFloatSlice,
3104 unmarshal: consumeFloatSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07003105}
3106
3107// sizeFloatPackedSlice returns the size of wire encoding a []float32 pointer as a packed repeated Float.
3108func sizeFloatPackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
3109 s := *p.Float32Slice()
3110 if len(s) == 0 {
3111 return 0
3112 }
3113 n := len(s) * wire.SizeFixed32()
3114 return tagsize + wire.SizeBytes(n)
3115}
3116
3117// appendFloatPackedSlice encodes a []float32 pointer as a packed repeated Float.
3118func appendFloatPackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3119 s := *p.Float32Slice()
3120 if len(s) == 0 {
3121 return b, nil
3122 }
3123 b = wire.AppendVarint(b, wiretag)
3124 n := len(s) * wire.SizeFixed32()
3125 b = wire.AppendVarint(b, uint64(n))
3126 for _, v := range s {
3127 b = wire.AppendFixed32(b, math.Float32bits(v))
3128 }
3129 return b, nil
3130}
3131
3132var coderFloatPackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003133 size: sizeFloatPackedSlice,
3134 marshal: appendFloatPackedSlice,
3135 unmarshal: consumeFloatSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07003136}
3137
Damien Neil68b81c32019-08-22 11:41:32 -07003138// sizeFloatValue returns the size of wire encoding a float32 value as a Float.
3139func sizeFloatValue(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07003140 return tagsize + wire.SizeFixed32()
3141}
3142
Damien Neil68b81c32019-08-22 11:41:32 -07003143// appendFloatValue encodes a float32 value as a Float.
3144func appendFloatValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003145 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003146 b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
Damien Neilc37adef2019-04-01 13:49:56 -07003147 return b, nil
3148}
3149
Damien Neil68b81c32019-08-22 11:41:32 -07003150// consumeFloatValue decodes a float32 value as a Float.
3151func consumeFloatValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07003152 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003153 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003154 }
3155 v, n := wire.ConsumeFixed32(b)
3156 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003157 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003158 }
Damien Neil68b81c32019-08-22 11:41:32 -07003159 return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003160}
3161
Damien Neil68b81c32019-08-22 11:41:32 -07003162var coderFloatValue = valueCoderFuncs{
3163 size: sizeFloatValue,
3164 marshal: appendFloatValue,
3165 unmarshal: consumeFloatValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003166}
3167
Damien Neil68b81c32019-08-22 11:41:32 -07003168// sizeFloatSliceValue returns the size of wire encoding a []float32 value as a repeated Float.
3169func sizeFloatSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3170 list := listv.List()
3171 size = list.Len() * (tagsize + wire.SizeFixed32())
Damien Neilc37adef2019-04-01 13:49:56 -07003172 return size
3173}
3174
Damien Neil68b81c32019-08-22 11:41:32 -07003175// appendFloatSliceValue encodes a []float32 value as a repeated Float.
3176func appendFloatSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3177 list := listv.List()
3178 for i, llen := 0, list.Len(); i < llen; i++ {
3179 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07003180 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003181 b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
Damien Neilc37adef2019-04-01 13:49:56 -07003182 }
3183 return b, nil
3184}
3185
Damien Neil68b81c32019-08-22 11:41:32 -07003186// consumeFloatSliceValue wire decodes a []float32 value as a repeated Float.
3187func consumeFloatSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
3188 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07003189 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07003190 b, n = wire.ConsumeBytes(b)
3191 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003192 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003193 }
3194 for len(b) > 0 {
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 list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
Damien Neile91877d2019-06-27 10:54:42 -07003200 b = b[n:]
3201 }
Damien Neil68b81c32019-08-22 11:41:32 -07003202 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003203 }
3204 if wtyp != wire.Fixed32Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003205 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003206 }
3207 v, n := wire.ConsumeFixed32(b)
3208 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003209 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003210 }
Damien Neil68b81c32019-08-22 11:41:32 -07003211 list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
3212 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003213}
3214
Damien Neil68b81c32019-08-22 11:41:32 -07003215var coderFloatSliceValue = valueCoderFuncs{
3216 size: sizeFloatSliceValue,
3217 marshal: appendFloatSliceValue,
3218 unmarshal: consumeFloatSliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003219}
3220
Damien Neil68b81c32019-08-22 11:41:32 -07003221// sizeFloatPackedSliceValue returns the size of wire encoding a []float32 value as a packed repeated Float.
3222func sizeFloatPackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3223 list := listv.List()
3224 n := list.Len() * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07003225 return tagsize + wire.SizeBytes(n)
3226}
3227
Damien Neil68b81c32019-08-22 11:41:32 -07003228// appendFloatPackedSliceValue encodes a []float32 value as a packed repeated Float.
3229func appendFloatPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3230 list := listv.List()
3231 llen := list.Len()
3232 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07003233 return b, nil
3234 }
3235 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003236 n := llen * wire.SizeFixed32()
Damien Neil7492a092019-07-10 15:23:29 -07003237 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07003238 for i := 0; i < llen; i++ {
3239 v := list.Get(i)
3240 b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
Damien Neil7492a092019-07-10 15:23:29 -07003241 }
3242 return b, nil
3243}
3244
Damien Neil68b81c32019-08-22 11:41:32 -07003245var coderFloatPackedSliceValue = valueCoderFuncs{
3246 size: sizeFloatPackedSliceValue,
3247 marshal: appendFloatPackedSliceValue,
3248 unmarshal: consumeFloatSliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07003249}
3250
Damien Neilc37adef2019-04-01 13:49:56 -07003251// sizeSfixed64 returns the size of wire encoding a int64 pointer as a Sfixed64.
3252func sizeSfixed64(p pointer, tagsize int, _ marshalOptions) (size int) {
3253
3254 return tagsize + wire.SizeFixed64()
3255}
3256
3257// appendSfixed64 wire encodes a int64 pointer as a Sfixed64.
3258func appendSfixed64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3259 v := *p.Int64()
3260 b = wire.AppendVarint(b, wiretag)
3261 b = wire.AppendFixed64(b, uint64(v))
3262 return b, nil
3263}
3264
Damien Neile91877d2019-06-27 10:54:42 -07003265// consumeSfixed64 wire decodes a int64 pointer as a Sfixed64.
3266func consumeSfixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3267 if wtyp != wire.Fixed64Type {
3268 return 0, errUnknown
3269 }
3270 v, n := wire.ConsumeFixed64(b)
3271 if n < 0 {
3272 return 0, wire.ParseError(n)
3273 }
3274 *p.Int64() = int64(v)
3275 return n, nil
3276}
3277
Damien Neilc37adef2019-04-01 13:49:56 -07003278var coderSfixed64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003279 size: sizeSfixed64,
3280 marshal: appendSfixed64,
3281 unmarshal: consumeSfixed64,
Damien Neilc37adef2019-04-01 13:49:56 -07003282}
3283
Joe Tsaic51e2e02019-07-13 00:44:41 -07003284// sizeSfixed64NoZero returns the size of wire encoding a int64 pointer as a Sfixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003285// The zero value is not encoded.
3286func sizeSfixed64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
3287 v := *p.Int64()
3288 if v == 0 {
3289 return 0
3290 }
3291 return tagsize + wire.SizeFixed64()
3292}
3293
Joe Tsaic51e2e02019-07-13 00:44:41 -07003294// appendSfixed64NoZero wire encodes a int64 pointer as a Sfixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003295// The zero value is not encoded.
3296func appendSfixed64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3297 v := *p.Int64()
3298 if v == 0 {
3299 return b, nil
3300 }
3301 b = wire.AppendVarint(b, wiretag)
3302 b = wire.AppendFixed64(b, uint64(v))
3303 return b, nil
3304}
3305
3306var coderSfixed64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003307 size: sizeSfixed64NoZero,
3308 marshal: appendSfixed64NoZero,
3309 unmarshal: consumeSfixed64,
Damien Neilc37adef2019-04-01 13:49:56 -07003310}
3311
3312// sizeSfixed64Ptr returns the size of wire encoding a *int64 pointer as a Sfixed64.
3313// It panics if the pointer is nil.
3314func sizeSfixed64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
3315 return tagsize + wire.SizeFixed64()
3316}
3317
Damien Neile91877d2019-06-27 10:54:42 -07003318// appendSfixed64Ptr wire encodes a *int64 pointer as a Sfixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003319// It panics if the pointer is nil.
3320func appendSfixed64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3321 v := **p.Int64Ptr()
3322 b = wire.AppendVarint(b, wiretag)
3323 b = wire.AppendFixed64(b, uint64(v))
3324 return b, nil
3325}
3326
Damien Neile91877d2019-06-27 10:54:42 -07003327// consumeSfixed64Ptr wire decodes a *int64 pointer as a Sfixed64.
3328func consumeSfixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3329 if wtyp != wire.Fixed64Type {
3330 return 0, errUnknown
3331 }
3332 v, n := wire.ConsumeFixed64(b)
3333 if n < 0 {
3334 return 0, wire.ParseError(n)
3335 }
3336 vp := p.Int64Ptr()
3337 if *vp == nil {
3338 *vp = new(int64)
3339 }
3340 **vp = int64(v)
3341 return n, nil
3342}
3343
Damien Neilc37adef2019-04-01 13:49:56 -07003344var coderSfixed64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003345 size: sizeSfixed64Ptr,
3346 marshal: appendSfixed64Ptr,
3347 unmarshal: consumeSfixed64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07003348}
3349
3350// sizeSfixed64Slice returns the size of wire encoding a []int64 pointer as a repeated Sfixed64.
3351func sizeSfixed64Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
3352 s := *p.Int64Slice()
3353 size = len(s) * (tagsize + wire.SizeFixed64())
3354 return size
3355}
3356
3357// appendSfixed64Slice encodes a []int64 pointer as a repeated Sfixed64.
3358func appendSfixed64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3359 s := *p.Int64Slice()
3360 for _, v := range s {
3361 b = wire.AppendVarint(b, wiretag)
3362 b = wire.AppendFixed64(b, uint64(v))
3363 }
3364 return b, nil
3365}
3366
Damien Neile91877d2019-06-27 10:54:42 -07003367// consumeSfixed64Slice wire decodes a []int64 pointer as a repeated Sfixed64.
3368func consumeSfixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3369 sp := p.Int64Slice()
3370 if wtyp == wire.BytesType {
3371 s := *sp
3372 b, n = wire.ConsumeBytes(b)
3373 if n < 0 {
3374 return 0, wire.ParseError(n)
3375 }
3376 for len(b) > 0 {
3377 v, n := wire.ConsumeFixed64(b)
3378 if n < 0 {
3379 return 0, wire.ParseError(n)
3380 }
3381 s = append(s, int64(v))
3382 b = b[n:]
3383 }
3384 *sp = s
3385 return n, nil
3386 }
3387 if wtyp != wire.Fixed64Type {
3388 return 0, errUnknown
3389 }
3390 v, n := wire.ConsumeFixed64(b)
3391 if n < 0 {
3392 return 0, wire.ParseError(n)
3393 }
3394 *sp = append(*sp, int64(v))
3395 return n, nil
3396}
3397
Damien Neilc37adef2019-04-01 13:49:56 -07003398var coderSfixed64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003399 size: sizeSfixed64Slice,
3400 marshal: appendSfixed64Slice,
3401 unmarshal: consumeSfixed64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003402}
3403
3404// sizeSfixed64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sfixed64.
3405func sizeSfixed64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
3406 s := *p.Int64Slice()
3407 if len(s) == 0 {
3408 return 0
3409 }
3410 n := len(s) * wire.SizeFixed64()
3411 return tagsize + wire.SizeBytes(n)
3412}
3413
3414// appendSfixed64PackedSlice encodes a []int64 pointer as a packed repeated Sfixed64.
3415func appendSfixed64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3416 s := *p.Int64Slice()
3417 if len(s) == 0 {
3418 return b, nil
3419 }
3420 b = wire.AppendVarint(b, wiretag)
3421 n := len(s) * wire.SizeFixed64()
3422 b = wire.AppendVarint(b, uint64(n))
3423 for _, v := range s {
3424 b = wire.AppendFixed64(b, uint64(v))
3425 }
3426 return b, nil
3427}
3428
3429var coderSfixed64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003430 size: sizeSfixed64PackedSlice,
3431 marshal: appendSfixed64PackedSlice,
3432 unmarshal: consumeSfixed64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003433}
3434
Damien Neil68b81c32019-08-22 11:41:32 -07003435// sizeSfixed64Value returns the size of wire encoding a int64 value as a Sfixed64.
3436func sizeSfixed64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07003437 return tagsize + wire.SizeFixed64()
3438}
3439
Damien Neil68b81c32019-08-22 11:41:32 -07003440// appendSfixed64Value encodes a int64 value as a Sfixed64.
3441func appendSfixed64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003442 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003443 b = wire.AppendFixed64(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07003444 return b, nil
3445}
3446
Damien Neil68b81c32019-08-22 11:41:32 -07003447// consumeSfixed64Value decodes a int64 value as a Sfixed64.
3448func consumeSfixed64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07003449 if wtyp != wire.Fixed64Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003450 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003451 }
3452 v, n := wire.ConsumeFixed64(b)
3453 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003454 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003455 }
Damien Neil68b81c32019-08-22 11:41:32 -07003456 return protoreflect.ValueOfInt64(int64(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003457}
3458
Damien Neil68b81c32019-08-22 11:41:32 -07003459var coderSfixed64Value = valueCoderFuncs{
3460 size: sizeSfixed64Value,
3461 marshal: appendSfixed64Value,
3462 unmarshal: consumeSfixed64Value,
Damien Neilc37adef2019-04-01 13:49:56 -07003463}
3464
Damien Neil68b81c32019-08-22 11:41:32 -07003465// sizeSfixed64SliceValue returns the size of wire encoding a []int64 value as a repeated Sfixed64.
3466func sizeSfixed64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3467 list := listv.List()
3468 size = list.Len() * (tagsize + wire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07003469 return size
3470}
3471
Damien Neil68b81c32019-08-22 11:41:32 -07003472// appendSfixed64SliceValue encodes a []int64 value as a repeated Sfixed64.
3473func appendSfixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3474 list := listv.List()
3475 for i, llen := 0, list.Len(); i < llen; i++ {
3476 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07003477 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003478 b = wire.AppendFixed64(b, uint64(v.Int()))
Damien Neilc37adef2019-04-01 13:49:56 -07003479 }
3480 return b, nil
3481}
3482
Damien Neil68b81c32019-08-22 11:41:32 -07003483// consumeSfixed64SliceValue wire decodes a []int64 value as a repeated Sfixed64.
3484func consumeSfixed64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
3485 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07003486 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07003487 b, n = wire.ConsumeBytes(b)
3488 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003489 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003490 }
3491 for len(b) > 0 {
3492 v, n := wire.ConsumeFixed64(b)
3493 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003494 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003495 }
Damien Neil68b81c32019-08-22 11:41:32 -07003496 list.Append(protoreflect.ValueOfInt64(int64(v)))
Damien Neile91877d2019-06-27 10:54:42 -07003497 b = b[n:]
3498 }
Damien Neil68b81c32019-08-22 11:41:32 -07003499 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003500 }
3501 if wtyp != wire.Fixed64Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003502 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003503 }
3504 v, n := wire.ConsumeFixed64(b)
3505 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003506 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003507 }
Damien Neil68b81c32019-08-22 11:41:32 -07003508 list.Append(protoreflect.ValueOfInt64(int64(v)))
3509 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003510}
3511
Damien Neil68b81c32019-08-22 11:41:32 -07003512var coderSfixed64SliceValue = valueCoderFuncs{
3513 size: sizeSfixed64SliceValue,
3514 marshal: appendSfixed64SliceValue,
3515 unmarshal: consumeSfixed64SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003516}
3517
Damien Neil68b81c32019-08-22 11:41:32 -07003518// sizeSfixed64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sfixed64.
3519func sizeSfixed64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3520 list := listv.List()
3521 n := list.Len() * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07003522 return tagsize + wire.SizeBytes(n)
3523}
3524
Damien Neil68b81c32019-08-22 11:41:32 -07003525// appendSfixed64PackedSliceValue encodes a []int64 value as a packed repeated Sfixed64.
3526func appendSfixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3527 list := listv.List()
3528 llen := list.Len()
3529 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07003530 return b, nil
3531 }
3532 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003533 n := llen * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07003534 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07003535 for i := 0; i < llen; i++ {
3536 v := list.Get(i)
3537 b = wire.AppendFixed64(b, uint64(v.Int()))
Damien Neil7492a092019-07-10 15:23:29 -07003538 }
3539 return b, nil
3540}
3541
Damien Neil68b81c32019-08-22 11:41:32 -07003542var coderSfixed64PackedSliceValue = valueCoderFuncs{
3543 size: sizeSfixed64PackedSliceValue,
3544 marshal: appendSfixed64PackedSliceValue,
3545 unmarshal: consumeSfixed64SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07003546}
3547
Damien Neilc37adef2019-04-01 13:49:56 -07003548// sizeFixed64 returns the size of wire encoding a uint64 pointer as a Fixed64.
3549func sizeFixed64(p pointer, tagsize int, _ marshalOptions) (size int) {
3550
3551 return tagsize + wire.SizeFixed64()
3552}
3553
3554// appendFixed64 wire encodes a uint64 pointer as a Fixed64.
3555func appendFixed64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3556 v := *p.Uint64()
3557 b = wire.AppendVarint(b, wiretag)
3558 b = wire.AppendFixed64(b, v)
3559 return b, nil
3560}
3561
Damien Neile91877d2019-06-27 10:54:42 -07003562// consumeFixed64 wire decodes a uint64 pointer as a Fixed64.
3563func consumeFixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3564 if wtyp != wire.Fixed64Type {
3565 return 0, errUnknown
3566 }
3567 v, n := wire.ConsumeFixed64(b)
3568 if n < 0 {
3569 return 0, wire.ParseError(n)
3570 }
3571 *p.Uint64() = v
3572 return n, nil
3573}
3574
Damien Neilc37adef2019-04-01 13:49:56 -07003575var coderFixed64 = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003576 size: sizeFixed64,
3577 marshal: appendFixed64,
3578 unmarshal: consumeFixed64,
Damien Neilc37adef2019-04-01 13:49:56 -07003579}
3580
Joe Tsaic51e2e02019-07-13 00:44:41 -07003581// sizeFixed64NoZero returns the size of wire encoding a uint64 pointer as a Fixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003582// The zero value is not encoded.
3583func sizeFixed64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
3584 v := *p.Uint64()
3585 if v == 0 {
3586 return 0
3587 }
3588 return tagsize + wire.SizeFixed64()
3589}
3590
Joe Tsaic51e2e02019-07-13 00:44:41 -07003591// appendFixed64NoZero wire encodes a uint64 pointer as a Fixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003592// The zero value is not encoded.
3593func appendFixed64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3594 v := *p.Uint64()
3595 if v == 0 {
3596 return b, nil
3597 }
3598 b = wire.AppendVarint(b, wiretag)
3599 b = wire.AppendFixed64(b, v)
3600 return b, nil
3601}
3602
3603var coderFixed64NoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003604 size: sizeFixed64NoZero,
3605 marshal: appendFixed64NoZero,
3606 unmarshal: consumeFixed64,
Damien Neilc37adef2019-04-01 13:49:56 -07003607}
3608
3609// sizeFixed64Ptr returns the size of wire encoding a *uint64 pointer as a Fixed64.
3610// It panics if the pointer is nil.
3611func sizeFixed64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) {
3612 return tagsize + wire.SizeFixed64()
3613}
3614
Damien Neile91877d2019-06-27 10:54:42 -07003615// appendFixed64Ptr wire encodes a *uint64 pointer as a Fixed64.
Damien Neilc37adef2019-04-01 13:49:56 -07003616// It panics if the pointer is nil.
3617func appendFixed64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3618 v := **p.Uint64Ptr()
3619 b = wire.AppendVarint(b, wiretag)
3620 b = wire.AppendFixed64(b, v)
3621 return b, nil
3622}
3623
Damien Neile91877d2019-06-27 10:54:42 -07003624// consumeFixed64Ptr wire decodes a *uint64 pointer as a Fixed64.
3625func consumeFixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3626 if wtyp != wire.Fixed64Type {
3627 return 0, errUnknown
3628 }
3629 v, n := wire.ConsumeFixed64(b)
3630 if n < 0 {
3631 return 0, wire.ParseError(n)
3632 }
3633 vp := p.Uint64Ptr()
3634 if *vp == nil {
3635 *vp = new(uint64)
3636 }
3637 **vp = v
3638 return n, nil
3639}
3640
Damien Neilc37adef2019-04-01 13:49:56 -07003641var coderFixed64Ptr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003642 size: sizeFixed64Ptr,
3643 marshal: appendFixed64Ptr,
3644 unmarshal: consumeFixed64Ptr,
Damien Neilc37adef2019-04-01 13:49:56 -07003645}
3646
3647// sizeFixed64Slice returns the size of wire encoding a []uint64 pointer as a repeated Fixed64.
3648func sizeFixed64Slice(p pointer, tagsize int, _ marshalOptions) (size int) {
3649 s := *p.Uint64Slice()
3650 size = len(s) * (tagsize + wire.SizeFixed64())
3651 return size
3652}
3653
3654// appendFixed64Slice encodes a []uint64 pointer as a repeated Fixed64.
3655func appendFixed64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3656 s := *p.Uint64Slice()
3657 for _, v := range s {
3658 b = wire.AppendVarint(b, wiretag)
3659 b = wire.AppendFixed64(b, v)
3660 }
3661 return b, nil
3662}
3663
Damien Neile91877d2019-06-27 10:54:42 -07003664// consumeFixed64Slice wire decodes a []uint64 pointer as a repeated Fixed64.
3665func consumeFixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3666 sp := p.Uint64Slice()
3667 if wtyp == wire.BytesType {
3668 s := *sp
3669 b, n = wire.ConsumeBytes(b)
3670 if n < 0 {
3671 return 0, wire.ParseError(n)
3672 }
3673 for len(b) > 0 {
3674 v, n := wire.ConsumeFixed64(b)
3675 if n < 0 {
3676 return 0, wire.ParseError(n)
3677 }
3678 s = append(s, v)
3679 b = b[n:]
3680 }
3681 *sp = s
3682 return n, nil
3683 }
3684 if wtyp != wire.Fixed64Type {
3685 return 0, errUnknown
3686 }
3687 v, n := wire.ConsumeFixed64(b)
3688 if n < 0 {
3689 return 0, wire.ParseError(n)
3690 }
3691 *sp = append(*sp, v)
3692 return n, nil
3693}
3694
Damien Neilc37adef2019-04-01 13:49:56 -07003695var coderFixed64Slice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003696 size: sizeFixed64Slice,
3697 marshal: appendFixed64Slice,
3698 unmarshal: consumeFixed64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003699}
3700
3701// sizeFixed64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Fixed64.
3702func sizeFixed64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
3703 s := *p.Uint64Slice()
3704 if len(s) == 0 {
3705 return 0
3706 }
3707 n := len(s) * wire.SizeFixed64()
3708 return tagsize + wire.SizeBytes(n)
3709}
3710
3711// appendFixed64PackedSlice encodes a []uint64 pointer as a packed repeated Fixed64.
3712func appendFixed64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3713 s := *p.Uint64Slice()
3714 if len(s) == 0 {
3715 return b, nil
3716 }
3717 b = wire.AppendVarint(b, wiretag)
3718 n := len(s) * wire.SizeFixed64()
3719 b = wire.AppendVarint(b, uint64(n))
3720 for _, v := range s {
3721 b = wire.AppendFixed64(b, v)
3722 }
3723 return b, nil
3724}
3725
3726var coderFixed64PackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003727 size: sizeFixed64PackedSlice,
3728 marshal: appendFixed64PackedSlice,
3729 unmarshal: consumeFixed64Slice,
Damien Neilc37adef2019-04-01 13:49:56 -07003730}
3731
Damien Neil68b81c32019-08-22 11:41:32 -07003732// sizeFixed64Value returns the size of wire encoding a uint64 value as a Fixed64.
3733func sizeFixed64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07003734 return tagsize + wire.SizeFixed64()
3735}
3736
Damien Neil68b81c32019-08-22 11:41:32 -07003737// appendFixed64Value encodes a uint64 value as a Fixed64.
3738func appendFixed64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07003739 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003740 b = wire.AppendFixed64(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07003741 return b, nil
3742}
3743
Damien Neil68b81c32019-08-22 11:41:32 -07003744// consumeFixed64Value decodes a uint64 value as a Fixed64.
3745func consumeFixed64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07003746 if wtyp != wire.Fixed64Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003747 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003748 }
3749 v, n := wire.ConsumeFixed64(b)
3750 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003751 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003752 }
Damien Neil68b81c32019-08-22 11:41:32 -07003753 return protoreflect.ValueOfUint64(v), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003754}
3755
Damien Neil68b81c32019-08-22 11:41:32 -07003756var coderFixed64Value = valueCoderFuncs{
3757 size: sizeFixed64Value,
3758 marshal: appendFixed64Value,
3759 unmarshal: consumeFixed64Value,
Damien Neilc37adef2019-04-01 13:49:56 -07003760}
3761
Damien Neil68b81c32019-08-22 11:41:32 -07003762// sizeFixed64SliceValue returns the size of wire encoding a []uint64 value as a repeated Fixed64.
3763func sizeFixed64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3764 list := listv.List()
3765 size = list.Len() * (tagsize + wire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07003766 return size
3767}
3768
Damien Neil68b81c32019-08-22 11:41:32 -07003769// appendFixed64SliceValue encodes a []uint64 value as a repeated Fixed64.
3770func appendFixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3771 list := listv.List()
3772 for i, llen := 0, list.Len(); i < llen; i++ {
3773 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07003774 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003775 b = wire.AppendFixed64(b, v.Uint())
Damien Neilc37adef2019-04-01 13:49:56 -07003776 }
3777 return b, nil
3778}
3779
Damien Neil68b81c32019-08-22 11:41:32 -07003780// consumeFixed64SliceValue wire decodes a []uint64 value as a repeated Fixed64.
3781func consumeFixed64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
3782 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07003783 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07003784 b, n = wire.ConsumeBytes(b)
3785 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003786 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003787 }
3788 for len(b) > 0 {
3789 v, n := wire.ConsumeFixed64(b)
3790 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003791 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003792 }
Damien Neil68b81c32019-08-22 11:41:32 -07003793 list.Append(protoreflect.ValueOfUint64(v))
Damien Neile91877d2019-06-27 10:54:42 -07003794 b = b[n:]
3795 }
Damien Neil68b81c32019-08-22 11:41:32 -07003796 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003797 }
3798 if wtyp != wire.Fixed64Type {
Damien Neil68b81c32019-08-22 11:41:32 -07003799 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07003800 }
3801 v, n := wire.ConsumeFixed64(b)
3802 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07003803 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07003804 }
Damien Neil68b81c32019-08-22 11:41:32 -07003805 list.Append(protoreflect.ValueOfUint64(v))
3806 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07003807}
3808
Damien Neil68b81c32019-08-22 11:41:32 -07003809var coderFixed64SliceValue = valueCoderFuncs{
3810 size: sizeFixed64SliceValue,
3811 marshal: appendFixed64SliceValue,
3812 unmarshal: consumeFixed64SliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07003813}
3814
Damien Neil68b81c32019-08-22 11:41:32 -07003815// sizeFixed64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Fixed64.
3816func sizeFixed64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
3817 list := listv.List()
3818 n := list.Len() * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07003819 return tagsize + wire.SizeBytes(n)
3820}
3821
Damien Neil68b81c32019-08-22 11:41:32 -07003822// appendFixed64PackedSliceValue encodes a []uint64 value as a packed repeated Fixed64.
3823func appendFixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
3824 list := listv.List()
3825 llen := list.Len()
3826 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07003827 return b, nil
3828 }
3829 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07003830 n := llen * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07003831 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07003832 for i := 0; i < llen; i++ {
3833 v := list.Get(i)
3834 b = wire.AppendFixed64(b, v.Uint())
Damien Neil7492a092019-07-10 15:23:29 -07003835 }
3836 return b, nil
3837}
3838
Damien Neil68b81c32019-08-22 11:41:32 -07003839var coderFixed64PackedSliceValue = valueCoderFuncs{
3840 size: sizeFixed64PackedSliceValue,
3841 marshal: appendFixed64PackedSliceValue,
3842 unmarshal: consumeFixed64SliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07003843}
3844
Damien Neilc37adef2019-04-01 13:49:56 -07003845// sizeDouble returns the size of wire encoding a float64 pointer as a Double.
3846func sizeDouble(p pointer, tagsize int, _ marshalOptions) (size int) {
3847
3848 return tagsize + wire.SizeFixed64()
3849}
3850
3851// appendDouble wire encodes a float64 pointer as a Double.
3852func appendDouble(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3853 v := *p.Float64()
3854 b = wire.AppendVarint(b, wiretag)
3855 b = wire.AppendFixed64(b, math.Float64bits(v))
3856 return b, nil
3857}
3858
Damien Neile91877d2019-06-27 10:54:42 -07003859// consumeDouble wire decodes a float64 pointer as a Double.
3860func consumeDouble(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3861 if wtyp != wire.Fixed64Type {
3862 return 0, errUnknown
3863 }
3864 v, n := wire.ConsumeFixed64(b)
3865 if n < 0 {
3866 return 0, wire.ParseError(n)
3867 }
3868 *p.Float64() = math.Float64frombits(v)
3869 return n, nil
3870}
3871
Damien Neilc37adef2019-04-01 13:49:56 -07003872var coderDouble = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003873 size: sizeDouble,
3874 marshal: appendDouble,
3875 unmarshal: consumeDouble,
Damien Neilc37adef2019-04-01 13:49:56 -07003876}
3877
Joe Tsaic51e2e02019-07-13 00:44:41 -07003878// sizeDoubleNoZero returns the size of wire encoding a float64 pointer as a Double.
Damien Neilc37adef2019-04-01 13:49:56 -07003879// The zero value is not encoded.
3880func sizeDoubleNoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
3881 v := *p.Float64()
3882 if v == 0 && !math.Signbit(float64(v)) {
3883 return 0
3884 }
3885 return tagsize + wire.SizeFixed64()
3886}
3887
Joe Tsaic51e2e02019-07-13 00:44:41 -07003888// appendDoubleNoZero wire encodes a float64 pointer as a Double.
Damien Neilc37adef2019-04-01 13:49:56 -07003889// The zero value is not encoded.
3890func appendDoubleNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3891 v := *p.Float64()
3892 if v == 0 && !math.Signbit(float64(v)) {
3893 return b, nil
3894 }
3895 b = wire.AppendVarint(b, wiretag)
3896 b = wire.AppendFixed64(b, math.Float64bits(v))
3897 return b, nil
3898}
3899
3900var coderDoubleNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003901 size: sizeDoubleNoZero,
3902 marshal: appendDoubleNoZero,
3903 unmarshal: consumeDouble,
Damien Neilc37adef2019-04-01 13:49:56 -07003904}
3905
3906// sizeDoublePtr returns the size of wire encoding a *float64 pointer as a Double.
3907// It panics if the pointer is nil.
3908func sizeDoublePtr(p pointer, tagsize int, _ marshalOptions) (size int) {
3909 return tagsize + wire.SizeFixed64()
3910}
3911
Damien Neile91877d2019-06-27 10:54:42 -07003912// appendDoublePtr wire encodes a *float64 pointer as a Double.
Damien Neilc37adef2019-04-01 13:49:56 -07003913// It panics if the pointer is nil.
3914func appendDoublePtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3915 v := **p.Float64Ptr()
3916 b = wire.AppendVarint(b, wiretag)
3917 b = wire.AppendFixed64(b, math.Float64bits(v))
3918 return b, nil
3919}
3920
Damien Neile91877d2019-06-27 10:54:42 -07003921// consumeDoublePtr wire decodes a *float64 pointer as a Double.
3922func consumeDoublePtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3923 if wtyp != wire.Fixed64Type {
3924 return 0, errUnknown
3925 }
3926 v, n := wire.ConsumeFixed64(b)
3927 if n < 0 {
3928 return 0, wire.ParseError(n)
3929 }
3930 vp := p.Float64Ptr()
3931 if *vp == nil {
3932 *vp = new(float64)
3933 }
3934 **vp = math.Float64frombits(v)
3935 return n, nil
3936}
3937
Damien Neilc37adef2019-04-01 13:49:56 -07003938var coderDoublePtr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003939 size: sizeDoublePtr,
3940 marshal: appendDoublePtr,
3941 unmarshal: consumeDoublePtr,
Damien Neilc37adef2019-04-01 13:49:56 -07003942}
3943
3944// sizeDoubleSlice returns the size of wire encoding a []float64 pointer as a repeated Double.
3945func sizeDoubleSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
3946 s := *p.Float64Slice()
3947 size = len(s) * (tagsize + wire.SizeFixed64())
3948 return size
3949}
3950
3951// appendDoubleSlice encodes a []float64 pointer as a repeated Double.
3952func appendDoubleSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
3953 s := *p.Float64Slice()
3954 for _, v := range s {
3955 b = wire.AppendVarint(b, wiretag)
3956 b = wire.AppendFixed64(b, math.Float64bits(v))
3957 }
3958 return b, nil
3959}
3960
Damien Neile91877d2019-06-27 10:54:42 -07003961// consumeDoubleSlice wire decodes a []float64 pointer as a repeated Double.
3962func consumeDoubleSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
3963 sp := p.Float64Slice()
3964 if wtyp == wire.BytesType {
3965 s := *sp
3966 b, n = wire.ConsumeBytes(b)
3967 if n < 0 {
3968 return 0, wire.ParseError(n)
3969 }
3970 for len(b) > 0 {
3971 v, n := wire.ConsumeFixed64(b)
3972 if n < 0 {
3973 return 0, wire.ParseError(n)
3974 }
3975 s = append(s, math.Float64frombits(v))
3976 b = b[n:]
3977 }
3978 *sp = s
3979 return n, nil
3980 }
3981 if wtyp != wire.Fixed64Type {
3982 return 0, errUnknown
3983 }
3984 v, n := wire.ConsumeFixed64(b)
3985 if n < 0 {
3986 return 0, wire.ParseError(n)
3987 }
3988 *sp = append(*sp, math.Float64frombits(v))
3989 return n, nil
3990}
3991
Damien Neilc37adef2019-04-01 13:49:56 -07003992var coderDoubleSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07003993 size: sizeDoubleSlice,
3994 marshal: appendDoubleSlice,
3995 unmarshal: consumeDoubleSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07003996}
3997
3998// sizeDoublePackedSlice returns the size of wire encoding a []float64 pointer as a packed repeated Double.
3999func sizeDoublePackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
4000 s := *p.Float64Slice()
4001 if len(s) == 0 {
4002 return 0
4003 }
4004 n := len(s) * wire.SizeFixed64()
4005 return tagsize + wire.SizeBytes(n)
4006}
4007
4008// appendDoublePackedSlice encodes a []float64 pointer as a packed repeated Double.
4009func appendDoublePackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4010 s := *p.Float64Slice()
4011 if len(s) == 0 {
4012 return b, nil
4013 }
4014 b = wire.AppendVarint(b, wiretag)
4015 n := len(s) * wire.SizeFixed64()
4016 b = wire.AppendVarint(b, uint64(n))
4017 for _, v := range s {
4018 b = wire.AppendFixed64(b, math.Float64bits(v))
4019 }
4020 return b, nil
4021}
4022
4023var coderDoublePackedSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004024 size: sizeDoublePackedSlice,
4025 marshal: appendDoublePackedSlice,
4026 unmarshal: consumeDoubleSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07004027}
4028
Damien Neil68b81c32019-08-22 11:41:32 -07004029// sizeDoubleValue returns the size of wire encoding a float64 value as a Double.
4030func sizeDoubleValue(v protoreflect.Value, tagsize int, _ marshalOptions) int {
Damien Neilc37adef2019-04-01 13:49:56 -07004031 return tagsize + wire.SizeFixed64()
4032}
4033
Damien Neil68b81c32019-08-22 11:41:32 -07004034// appendDoubleValue encodes a float64 value as a Double.
4035func appendDoubleValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004036 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004037 b = wire.AppendFixed64(b, math.Float64bits(v.Float()))
Damien Neilc37adef2019-04-01 13:49:56 -07004038 return b, nil
4039}
4040
Damien Neil68b81c32019-08-22 11:41:32 -07004041// consumeDoubleValue decodes a float64 value as a Double.
4042func consumeDoubleValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07004043 if wtyp != wire.Fixed64Type {
Damien Neil68b81c32019-08-22 11:41:32 -07004044 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004045 }
4046 v, n := wire.ConsumeFixed64(b)
4047 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004048 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004049 }
Damien Neil68b81c32019-08-22 11:41:32 -07004050 return protoreflect.ValueOfFloat64(math.Float64frombits(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004051}
4052
Damien Neil68b81c32019-08-22 11:41:32 -07004053var coderDoubleValue = valueCoderFuncs{
4054 size: sizeDoubleValue,
4055 marshal: appendDoubleValue,
4056 unmarshal: consumeDoubleValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004057}
4058
Damien Neil68b81c32019-08-22 11:41:32 -07004059// sizeDoubleSliceValue returns the size of wire encoding a []float64 value as a repeated Double.
4060func sizeDoubleSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
4061 list := listv.List()
4062 size = list.Len() * (tagsize + wire.SizeFixed64())
Damien Neilc37adef2019-04-01 13:49:56 -07004063 return size
4064}
4065
Damien Neil68b81c32019-08-22 11:41:32 -07004066// appendDoubleSliceValue encodes a []float64 value as a repeated Double.
4067func appendDoubleSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
4068 list := listv.List()
4069 for i, llen := 0, list.Len(); i < llen; i++ {
4070 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07004071 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004072 b = wire.AppendFixed64(b, math.Float64bits(v.Float()))
Damien Neilc37adef2019-04-01 13:49:56 -07004073 }
4074 return b, nil
4075}
4076
Damien Neil68b81c32019-08-22 11:41:32 -07004077// consumeDoubleSliceValue wire decodes a []float64 value as a repeated Double.
4078func consumeDoubleSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
4079 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07004080 if wtyp == wire.BytesType {
Damien Neile91877d2019-06-27 10:54:42 -07004081 b, n = wire.ConsumeBytes(b)
4082 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004083 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004084 }
4085 for len(b) > 0 {
4086 v, n := wire.ConsumeFixed64(b)
4087 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004088 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004089 }
Damien Neil68b81c32019-08-22 11:41:32 -07004090 list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
Damien Neile91877d2019-06-27 10:54:42 -07004091 b = b[n:]
4092 }
Damien Neil68b81c32019-08-22 11:41:32 -07004093 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004094 }
4095 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 list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
4103 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004104}
4105
Damien Neil68b81c32019-08-22 11:41:32 -07004106var coderDoubleSliceValue = valueCoderFuncs{
4107 size: sizeDoubleSliceValue,
4108 marshal: appendDoubleSliceValue,
4109 unmarshal: consumeDoubleSliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004110}
4111
Damien Neil68b81c32019-08-22 11:41:32 -07004112// sizeDoublePackedSliceValue returns the size of wire encoding a []float64 value as a packed repeated Double.
4113func sizeDoublePackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
4114 list := listv.List()
4115 n := list.Len() * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07004116 return tagsize + wire.SizeBytes(n)
4117}
4118
Damien Neil68b81c32019-08-22 11:41:32 -07004119// appendDoublePackedSliceValue encodes a []float64 value as a packed repeated Double.
4120func appendDoublePackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
4121 list := listv.List()
4122 llen := list.Len()
4123 if llen == 0 {
Damien Neil7492a092019-07-10 15:23:29 -07004124 return b, nil
4125 }
4126 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004127 n := llen * wire.SizeFixed64()
Damien Neil7492a092019-07-10 15:23:29 -07004128 b = wire.AppendVarint(b, uint64(n))
Damien Neil68b81c32019-08-22 11:41:32 -07004129 for i := 0; i < llen; i++ {
4130 v := list.Get(i)
4131 b = wire.AppendFixed64(b, math.Float64bits(v.Float()))
Damien Neil7492a092019-07-10 15:23:29 -07004132 }
4133 return b, nil
4134}
4135
Damien Neil68b81c32019-08-22 11:41:32 -07004136var coderDoublePackedSliceValue = valueCoderFuncs{
4137 size: sizeDoublePackedSliceValue,
4138 marshal: appendDoublePackedSliceValue,
4139 unmarshal: consumeDoubleSliceValue,
Damien Neil7492a092019-07-10 15:23:29 -07004140}
4141
Damien Neilc37adef2019-04-01 13:49:56 -07004142// sizeString returns the size of wire encoding a string pointer as a String.
4143func sizeString(p pointer, tagsize int, _ marshalOptions) (size int) {
4144 v := *p.String()
Damien Neilcedb5952019-06-21 12:04:07 -07004145 return tagsize + wire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004146}
4147
4148// appendString wire encodes a string pointer as a String.
4149func appendString(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4150 v := *p.String()
4151 b = wire.AppendVarint(b, wiretag)
Damien Neilcedb5952019-06-21 12:04:07 -07004152 b = wire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004153 return b, nil
4154}
4155
Damien Neile91877d2019-06-27 10:54:42 -07004156// consumeString wire decodes a string pointer as a String.
4157func consumeString(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4158 if wtyp != wire.BytesType {
4159 return 0, errUnknown
4160 }
4161 v, n := wire.ConsumeString(b)
4162 if n < 0 {
4163 return 0, wire.ParseError(n)
4164 }
4165 *p.String() = v
4166 return n, nil
4167}
4168
Damien Neilc37adef2019-04-01 13:49:56 -07004169var coderString = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004170 size: sizeString,
4171 marshal: appendString,
4172 unmarshal: consumeString,
Damien Neilc37adef2019-04-01 13:49:56 -07004173}
4174
Joe Tsaic51e2e02019-07-13 00:44:41 -07004175// appendStringValidateUTF8 wire encodes a string pointer as a String.
4176func appendStringValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4177 v := *p.String()
4178 b = wire.AppendVarint(b, wiretag)
4179 b = wire.AppendString(b, v)
4180 if !utf8.ValidString(v) {
4181 return b, errInvalidUTF8{}
4182 }
4183 return b, nil
4184}
4185
4186// consumeStringValidateUTF8 wire decodes a string pointer as a String.
4187func consumeStringValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4188 if wtyp != wire.BytesType {
4189 return 0, errUnknown
4190 }
4191 v, n := wire.ConsumeString(b)
4192 if n < 0 {
4193 return 0, wire.ParseError(n)
4194 }
4195 if !utf8.ValidString(v) {
4196 return 0, errInvalidUTF8{}
4197 }
4198 *p.String() = v
4199 return n, nil
4200}
4201
4202var coderStringValidateUTF8 = pointerCoderFuncs{
4203 size: sizeString,
4204 marshal: appendStringValidateUTF8,
4205 unmarshal: consumeStringValidateUTF8,
4206}
4207
4208// sizeStringNoZero returns the size of wire encoding a string pointer as a String.
Damien Neilc37adef2019-04-01 13:49:56 -07004209// The zero value is not encoded.
4210func sizeStringNoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
4211 v := *p.String()
4212 if len(v) == 0 {
4213 return 0
4214 }
Damien Neilcedb5952019-06-21 12:04:07 -07004215 return tagsize + wire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004216}
4217
Joe Tsaic51e2e02019-07-13 00:44:41 -07004218// appendStringNoZero wire encodes a string pointer as a String.
Damien Neilc37adef2019-04-01 13:49:56 -07004219// The zero value is not encoded.
4220func appendStringNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4221 v := *p.String()
4222 if len(v) == 0 {
4223 return b, nil
4224 }
4225 b = wire.AppendVarint(b, wiretag)
Damien Neilcedb5952019-06-21 12:04:07 -07004226 b = wire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004227 return b, nil
4228}
4229
4230var coderStringNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004231 size: sizeStringNoZero,
4232 marshal: appendStringNoZero,
4233 unmarshal: consumeString,
Damien Neilc37adef2019-04-01 13:49:56 -07004234}
4235
Joe Tsaic51e2e02019-07-13 00:44:41 -07004236// appendStringNoZeroValidateUTF8 wire encodes a string pointer as a String.
4237// The zero value is not encoded.
4238func appendStringNoZeroValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4239 v := *p.String()
4240 if len(v) == 0 {
4241 return b, nil
4242 }
4243 b = wire.AppendVarint(b, wiretag)
4244 b = wire.AppendString(b, v)
4245 if !utf8.ValidString(v) {
4246 return b, errInvalidUTF8{}
4247 }
4248 return b, nil
4249}
4250
4251var coderStringNoZeroValidateUTF8 = pointerCoderFuncs{
4252 size: sizeStringNoZero,
4253 marshal: appendStringNoZeroValidateUTF8,
4254 unmarshal: consumeStringValidateUTF8,
4255}
4256
Damien Neilc37adef2019-04-01 13:49:56 -07004257// sizeStringPtr returns the size of wire encoding a *string pointer as a String.
4258// It panics if the pointer is nil.
4259func sizeStringPtr(p pointer, tagsize int, _ marshalOptions) (size int) {
4260 v := **p.StringPtr()
Damien Neilcedb5952019-06-21 12:04:07 -07004261 return tagsize + wire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004262}
4263
Damien Neile91877d2019-06-27 10:54:42 -07004264// appendStringPtr wire encodes a *string pointer as a String.
Damien Neilc37adef2019-04-01 13:49:56 -07004265// It panics if the pointer is nil.
4266func appendStringPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4267 v := **p.StringPtr()
4268 b = wire.AppendVarint(b, wiretag)
Damien Neilcedb5952019-06-21 12:04:07 -07004269 b = wire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004270 return b, nil
4271}
4272
Damien Neile91877d2019-06-27 10:54:42 -07004273// consumeStringPtr wire decodes a *string pointer as a String.
4274func consumeStringPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4275 if wtyp != wire.BytesType {
4276 return 0, errUnknown
4277 }
4278 v, n := wire.ConsumeString(b)
4279 if n < 0 {
4280 return 0, wire.ParseError(n)
4281 }
4282 vp := p.StringPtr()
4283 if *vp == nil {
4284 *vp = new(string)
4285 }
4286 **vp = v
4287 return n, nil
4288}
4289
Damien Neilc37adef2019-04-01 13:49:56 -07004290var coderStringPtr = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004291 size: sizeStringPtr,
4292 marshal: appendStringPtr,
4293 unmarshal: consumeStringPtr,
Damien Neilc37adef2019-04-01 13:49:56 -07004294}
4295
4296// sizeStringSlice returns the size of wire encoding a []string pointer as a repeated String.
4297func sizeStringSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
4298 s := *p.StringSlice()
4299 for _, v := range s {
Damien Neilcedb5952019-06-21 12:04:07 -07004300 size += tagsize + wire.SizeBytes(len(v))
Damien Neilc37adef2019-04-01 13:49:56 -07004301 }
4302 return size
4303}
4304
4305// appendStringSlice encodes a []string pointer as a repeated String.
4306func appendStringSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4307 s := *p.StringSlice()
4308 for _, v := range s {
4309 b = wire.AppendVarint(b, wiretag)
Damien Neilcedb5952019-06-21 12:04:07 -07004310 b = wire.AppendString(b, v)
Damien Neilc37adef2019-04-01 13:49:56 -07004311 }
4312 return b, nil
4313}
4314
Damien Neile91877d2019-06-27 10:54:42 -07004315// consumeStringSlice wire decodes a []string pointer as a repeated String.
4316func consumeStringSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4317 sp := p.StringSlice()
4318 if wtyp != wire.BytesType {
4319 return 0, errUnknown
4320 }
4321 v, n := wire.ConsumeString(b)
4322 if n < 0 {
4323 return 0, wire.ParseError(n)
4324 }
4325 *sp = append(*sp, v)
4326 return n, nil
4327}
4328
Damien Neilc37adef2019-04-01 13:49:56 -07004329var coderStringSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004330 size: sizeStringSlice,
4331 marshal: appendStringSlice,
4332 unmarshal: consumeStringSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07004333}
4334
Joe Tsaic51e2e02019-07-13 00:44:41 -07004335// appendStringSliceValidateUTF8 encodes a []string pointer as a repeated String.
4336func appendStringSliceValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4337 s := *p.StringSlice()
4338 for _, v := range s {
4339 b = wire.AppendVarint(b, wiretag)
4340 b = wire.AppendString(b, v)
4341 if !utf8.ValidString(v) {
4342 return b, errInvalidUTF8{}
4343 }
4344 }
4345 return b, nil
4346}
4347
4348// consumeStringSliceValidateUTF8 wire decodes a []string pointer as a repeated String.
4349func consumeStringSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4350 sp := p.StringSlice()
4351 if wtyp != wire.BytesType {
4352 return 0, errUnknown
4353 }
4354 v, n := wire.ConsumeString(b)
4355 if n < 0 {
4356 return 0, wire.ParseError(n)
4357 }
4358 if !utf8.ValidString(v) {
4359 return 0, errInvalidUTF8{}
4360 }
4361 *sp = append(*sp, v)
4362 return n, nil
4363}
4364
4365var coderStringSliceValidateUTF8 = pointerCoderFuncs{
4366 size: sizeStringSlice,
4367 marshal: appendStringSliceValidateUTF8,
4368 unmarshal: consumeStringSliceValidateUTF8,
4369}
4370
Damien Neil68b81c32019-08-22 11:41:32 -07004371// sizeStringValue returns the size of wire encoding a string value as a String.
4372func sizeStringValue(v protoreflect.Value, tagsize int, _ marshalOptions) int {
4373 return tagsize + wire.SizeBytes(len(v.String()))
Damien Neilc37adef2019-04-01 13:49:56 -07004374}
4375
Damien Neil68b81c32019-08-22 11:41:32 -07004376// appendStringValue encodes a string value as a String.
4377func appendStringValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004378 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004379 b = wire.AppendString(b, v.String())
Damien Neilc37adef2019-04-01 13:49:56 -07004380 return b, nil
4381}
4382
Damien Neil68b81c32019-08-22 11:41:32 -07004383// consumeStringValue decodes a string value as a String.
4384func consumeStringValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07004385 if wtyp != wire.BytesType {
Damien Neil68b81c32019-08-22 11:41:32 -07004386 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004387 }
4388 v, n := wire.ConsumeString(b)
4389 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004390 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004391 }
Damien Neil68b81c32019-08-22 11:41:32 -07004392 return protoreflect.ValueOfString(string(v)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004393}
4394
Damien Neil68b81c32019-08-22 11:41:32 -07004395var coderStringValue = valueCoderFuncs{
4396 size: sizeStringValue,
4397 marshal: appendStringValue,
4398 unmarshal: consumeStringValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004399}
4400
Damien Neil68b81c32019-08-22 11:41:32 -07004401// appendStringValueValidateUTF8 encodes a string value as a String.
4402func appendStringValueValidateUTF8(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07004403 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004404 b = wire.AppendString(b, v.String())
4405 if !utf8.ValidString(v.String()) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07004406 return b, errInvalidUTF8{}
4407 }
4408 return b, nil
4409}
4410
Damien Neil68b81c32019-08-22 11:41:32 -07004411// consumeStringValueValidateUTF8 decodes a string value as a String.
4412func consumeStringValueValidateUTF8(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07004413 if wtyp != wire.BytesType {
Damien Neil68b81c32019-08-22 11:41:32 -07004414 return protoreflect.Value{}, 0, errUnknown
Joe Tsaic51e2e02019-07-13 00:44:41 -07004415 }
4416 v, n := wire.ConsumeString(b)
4417 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004418 return protoreflect.Value{}, 0, wire.ParseError(n)
Joe Tsaic51e2e02019-07-13 00:44:41 -07004419 }
4420 if !utf8.ValidString(v) {
Damien Neil68b81c32019-08-22 11:41:32 -07004421 return protoreflect.Value{}, 0, errInvalidUTF8{}
Joe Tsaic51e2e02019-07-13 00:44:41 -07004422 }
Damien Neil68b81c32019-08-22 11:41:32 -07004423 return protoreflect.ValueOfString(string(v)), n, nil
Joe Tsaic51e2e02019-07-13 00:44:41 -07004424}
4425
Damien Neil68b81c32019-08-22 11:41:32 -07004426var coderStringValueValidateUTF8 = valueCoderFuncs{
4427 size: sizeStringValue,
4428 marshal: appendStringValueValidateUTF8,
4429 unmarshal: consumeStringValueValidateUTF8,
Joe Tsaic51e2e02019-07-13 00:44:41 -07004430}
4431
Damien Neil68b81c32019-08-22 11:41:32 -07004432// sizeStringSliceValue returns the size of wire encoding a []string value as a repeated String.
4433func sizeStringSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
4434 list := listv.List()
4435 for i, llen := 0, list.Len(); i < llen; i++ {
4436 v := list.Get(i)
4437 size += tagsize + wire.SizeBytes(len(v.String()))
Damien Neilc37adef2019-04-01 13:49:56 -07004438 }
4439 return size
4440}
4441
Damien Neil68b81c32019-08-22 11:41:32 -07004442// appendStringSliceValue encodes a []string value as a repeated String.
4443func appendStringSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
4444 list := listv.List()
4445 for i, llen := 0, list.Len(); i < llen; i++ {
4446 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07004447 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004448 b = wire.AppendString(b, v.String())
Damien Neilc37adef2019-04-01 13:49:56 -07004449 }
4450 return b, nil
4451}
4452
Damien Neil68b81c32019-08-22 11:41:32 -07004453// consumeStringSliceValue wire decodes a []string value as a repeated String.
4454func consumeStringSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
4455 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07004456 if wtyp != wire.BytesType {
Damien Neil68b81c32019-08-22 11:41:32 -07004457 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004458 }
4459 v, n := wire.ConsumeString(b)
4460 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004461 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004462 }
Damien Neil68b81c32019-08-22 11:41:32 -07004463 list.Append(protoreflect.ValueOfString(string(v)))
4464 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004465}
4466
Damien Neil68b81c32019-08-22 11:41:32 -07004467var coderStringSliceValue = valueCoderFuncs{
4468 size: sizeStringSliceValue,
4469 marshal: appendStringSliceValue,
4470 unmarshal: consumeStringSliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004471}
4472
4473// sizeBytes returns the size of wire encoding a []byte pointer as a Bytes.
4474func sizeBytes(p pointer, tagsize int, _ marshalOptions) (size int) {
4475 v := *p.Bytes()
4476 return tagsize + wire.SizeBytes(len(v))
4477}
4478
4479// appendBytes wire encodes a []byte pointer as a Bytes.
4480func appendBytes(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4481 v := *p.Bytes()
4482 b = wire.AppendVarint(b, wiretag)
4483 b = wire.AppendBytes(b, v)
4484 return b, nil
4485}
4486
Damien Neile91877d2019-06-27 10:54:42 -07004487// consumeBytes wire decodes a []byte pointer as a Bytes.
4488func consumeBytes(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4489 if wtyp != wire.BytesType {
4490 return 0, errUnknown
4491 }
4492 v, n := wire.ConsumeBytes(b)
4493 if n < 0 {
4494 return 0, wire.ParseError(n)
4495 }
Damien Neil8003f082019-08-02 15:13:00 -07004496 *p.Bytes() = append(emptyBuf[:], v...)
Damien Neile91877d2019-06-27 10:54:42 -07004497 return n, nil
4498}
4499
Damien Neilc37adef2019-04-01 13:49:56 -07004500var coderBytes = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004501 size: sizeBytes,
4502 marshal: appendBytes,
4503 unmarshal: consumeBytes,
Damien Neilc37adef2019-04-01 13:49:56 -07004504}
4505
Joe Tsaic51e2e02019-07-13 00:44:41 -07004506// appendBytesValidateUTF8 wire encodes a []byte pointer as a Bytes.
4507func appendBytesValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4508 v := *p.Bytes()
4509 b = wire.AppendVarint(b, wiretag)
4510 b = wire.AppendBytes(b, v)
4511 if !utf8.Valid(v) {
4512 return b, errInvalidUTF8{}
4513 }
4514 return b, nil
4515}
4516
4517// consumeBytesValidateUTF8 wire decodes a []byte pointer as a Bytes.
4518func consumeBytesValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4519 if wtyp != wire.BytesType {
4520 return 0, errUnknown
4521 }
4522 v, n := wire.ConsumeBytes(b)
4523 if n < 0 {
4524 return 0, wire.ParseError(n)
4525 }
4526 if !utf8.Valid(v) {
4527 return 0, errInvalidUTF8{}
4528 }
Damien Neil8003f082019-08-02 15:13:00 -07004529 *p.Bytes() = append(emptyBuf[:], v...)
Joe Tsaic51e2e02019-07-13 00:44:41 -07004530 return n, nil
4531}
4532
4533var coderBytesValidateUTF8 = pointerCoderFuncs{
4534 size: sizeBytes,
4535 marshal: appendBytesValidateUTF8,
4536 unmarshal: consumeBytesValidateUTF8,
4537}
4538
4539// sizeBytesNoZero returns the size of wire encoding a []byte pointer as a Bytes.
Damien Neilc37adef2019-04-01 13:49:56 -07004540// The zero value is not encoded.
4541func sizeBytesNoZero(p pointer, tagsize int, _ marshalOptions) (size int) {
4542 v := *p.Bytes()
4543 if len(v) == 0 {
4544 return 0
4545 }
4546 return tagsize + wire.SizeBytes(len(v))
4547}
4548
Joe Tsaic51e2e02019-07-13 00:44:41 -07004549// appendBytesNoZero wire encodes a []byte pointer as a Bytes.
Damien Neilc37adef2019-04-01 13:49:56 -07004550// The zero value is not encoded.
4551func appendBytesNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4552 v := *p.Bytes()
4553 if len(v) == 0 {
4554 return b, nil
4555 }
4556 b = wire.AppendVarint(b, wiretag)
4557 b = wire.AppendBytes(b, v)
4558 return b, nil
4559}
4560
Damien Neil8003f082019-08-02 15:13:00 -07004561// consumeBytesNoZero wire decodes a []byte pointer as a Bytes.
4562// The zero value is not decoded.
4563func consumeBytesNoZero(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4564 if wtyp != wire.BytesType {
4565 return 0, errUnknown
4566 }
4567 v, n := wire.ConsumeBytes(b)
4568 if n < 0 {
4569 return 0, wire.ParseError(n)
4570 }
4571 *p.Bytes() = append(([]byte)(nil), v...)
4572 return n, nil
4573}
4574
Damien Neilc37adef2019-04-01 13:49:56 -07004575var coderBytesNoZero = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004576 size: sizeBytesNoZero,
4577 marshal: appendBytesNoZero,
Damien Neil8003f082019-08-02 15:13:00 -07004578 unmarshal: consumeBytesNoZero,
Damien Neilc37adef2019-04-01 13:49:56 -07004579}
4580
Joe Tsaic51e2e02019-07-13 00:44:41 -07004581// appendBytesNoZeroValidateUTF8 wire encodes a []byte pointer as a Bytes.
4582// The zero value is not encoded.
4583func appendBytesNoZeroValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4584 v := *p.Bytes()
4585 if len(v) == 0 {
4586 return b, nil
4587 }
4588 b = wire.AppendVarint(b, wiretag)
4589 b = wire.AppendBytes(b, v)
4590 if !utf8.Valid(v) {
4591 return b, errInvalidUTF8{}
4592 }
4593 return b, nil
4594}
4595
Damien Neil8003f082019-08-02 15:13:00 -07004596// consumeBytesNoZeroValidateUTF8 wire decodes a []byte pointer as a Bytes.
4597func consumeBytesNoZeroValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4598 if wtyp != wire.BytesType {
4599 return 0, errUnknown
4600 }
4601 v, n := wire.ConsumeBytes(b)
4602 if n < 0 {
4603 return 0, wire.ParseError(n)
4604 }
4605 if !utf8.Valid(v) {
4606 return 0, errInvalidUTF8{}
4607 }
4608 *p.Bytes() = append(([]byte)(nil), v...)
4609 return n, nil
4610}
4611
Joe Tsaic51e2e02019-07-13 00:44:41 -07004612var coderBytesNoZeroValidateUTF8 = pointerCoderFuncs{
4613 size: sizeBytesNoZero,
4614 marshal: appendBytesNoZeroValidateUTF8,
Damien Neil8003f082019-08-02 15:13:00 -07004615 unmarshal: consumeBytesNoZeroValidateUTF8,
Joe Tsaic51e2e02019-07-13 00:44:41 -07004616}
4617
Damien Neilc37adef2019-04-01 13:49:56 -07004618// sizeBytesSlice returns the size of wire encoding a [][]byte pointer as a repeated Bytes.
4619func sizeBytesSlice(p pointer, tagsize int, _ marshalOptions) (size int) {
4620 s := *p.BytesSlice()
4621 for _, v := range s {
4622 size += tagsize + wire.SizeBytes(len(v))
4623 }
4624 return size
4625}
4626
4627// appendBytesSlice encodes a [][]byte pointer as a repeated Bytes.
4628func appendBytesSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4629 s := *p.BytesSlice()
4630 for _, v := range s {
4631 b = wire.AppendVarint(b, wiretag)
4632 b = wire.AppendBytes(b, v)
4633 }
4634 return b, nil
4635}
4636
Damien Neile91877d2019-06-27 10:54:42 -07004637// consumeBytesSlice wire decodes a [][]byte pointer as a repeated Bytes.
4638func consumeBytesSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4639 sp := p.BytesSlice()
4640 if wtyp != wire.BytesType {
4641 return 0, errUnknown
4642 }
4643 v, n := wire.ConsumeBytes(b)
4644 if n < 0 {
4645 return 0, wire.ParseError(n)
4646 }
Damien Neil8003f082019-08-02 15:13:00 -07004647 *sp = append(*sp, append(emptyBuf[:], v...))
Damien Neile91877d2019-06-27 10:54:42 -07004648 return n, nil
4649}
4650
Damien Neilc37adef2019-04-01 13:49:56 -07004651var coderBytesSlice = pointerCoderFuncs{
Damien Neile91877d2019-06-27 10:54:42 -07004652 size: sizeBytesSlice,
4653 marshal: appendBytesSlice,
4654 unmarshal: consumeBytesSlice,
Damien Neilc37adef2019-04-01 13:49:56 -07004655}
4656
Joe Tsaic51e2e02019-07-13 00:44:41 -07004657// appendBytesSliceValidateUTF8 encodes a [][]byte pointer as a repeated Bytes.
4658func appendBytesSliceValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) {
4659 s := *p.BytesSlice()
4660 for _, v := range s {
4661 b = wire.AppendVarint(b, wiretag)
4662 b = wire.AppendBytes(b, v)
4663 if !utf8.Valid(v) {
4664 return b, errInvalidUTF8{}
4665 }
4666 }
4667 return b, nil
4668}
4669
4670// consumeBytesSliceValidateUTF8 wire decodes a [][]byte pointer as a repeated Bytes.
4671func consumeBytesSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) {
4672 sp := p.BytesSlice()
4673 if wtyp != wire.BytesType {
4674 return 0, errUnknown
4675 }
4676 v, n := wire.ConsumeBytes(b)
4677 if n < 0 {
4678 return 0, wire.ParseError(n)
4679 }
4680 if !utf8.Valid(v) {
4681 return 0, errInvalidUTF8{}
4682 }
Damien Neil8003f082019-08-02 15:13:00 -07004683 *sp = append(*sp, append(emptyBuf[:], v...))
Joe Tsaic51e2e02019-07-13 00:44:41 -07004684 return n, nil
4685}
4686
4687var coderBytesSliceValidateUTF8 = pointerCoderFuncs{
4688 size: sizeBytesSlice,
4689 marshal: appendBytesSliceValidateUTF8,
4690 unmarshal: consumeBytesSliceValidateUTF8,
4691}
4692
Damien Neil68b81c32019-08-22 11:41:32 -07004693// sizeBytesValue returns the size of wire encoding a []byte value as a Bytes.
4694func sizeBytesValue(v protoreflect.Value, tagsize int, _ marshalOptions) int {
4695 return tagsize + wire.SizeBytes(len(v.Bytes()))
Damien Neilc37adef2019-04-01 13:49:56 -07004696}
4697
Damien Neil68b81c32019-08-22 11:41:32 -07004698// appendBytesValue encodes a []byte value as a Bytes.
4699func appendBytesValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Damien Neilc37adef2019-04-01 13:49:56 -07004700 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004701 b = wire.AppendBytes(b, v.Bytes())
Damien Neilc37adef2019-04-01 13:49:56 -07004702 return b, nil
4703}
4704
Damien Neil68b81c32019-08-22 11:41:32 -07004705// consumeBytesValue decodes a []byte value as a Bytes.
4706func consumeBytesValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Damien Neile91877d2019-06-27 10:54:42 -07004707 if wtyp != wire.BytesType {
Damien Neil68b81c32019-08-22 11:41:32 -07004708 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004709 }
4710 v, n := wire.ConsumeBytes(b)
4711 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004712 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004713 }
Damien Neil68b81c32019-08-22 11:41:32 -07004714 return protoreflect.ValueOfBytes(append(([]byte)(nil), v...)), n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004715}
4716
Damien Neil68b81c32019-08-22 11:41:32 -07004717var coderBytesValue = valueCoderFuncs{
4718 size: sizeBytesValue,
4719 marshal: appendBytesValue,
4720 unmarshal: consumeBytesValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004721}
4722
Damien Neil68b81c32019-08-22 11:41:32 -07004723// appendBytesValueValidateUTF8 encodes a []byte value as a Bytes.
4724func appendBytesValueValidateUTF8(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07004725 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004726 b = wire.AppendBytes(b, v.Bytes())
4727 if !utf8.Valid(v.Bytes()) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07004728 return b, errInvalidUTF8{}
4729 }
4730 return b, nil
4731}
4732
Damien Neil68b81c32019-08-22 11:41:32 -07004733// consumeBytesValueValidateUTF8 decodes a []byte value as a Bytes.
4734func consumeBytesValueValidateUTF8(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) {
Joe Tsaic51e2e02019-07-13 00:44:41 -07004735 if wtyp != wire.BytesType {
Damien Neil68b81c32019-08-22 11:41:32 -07004736 return protoreflect.Value{}, 0, errUnknown
Joe Tsaic51e2e02019-07-13 00:44:41 -07004737 }
4738 v, n := wire.ConsumeBytes(b)
4739 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004740 return protoreflect.Value{}, 0, wire.ParseError(n)
Joe Tsaic51e2e02019-07-13 00:44:41 -07004741 }
4742 if !utf8.Valid(v) {
Damien Neil68b81c32019-08-22 11:41:32 -07004743 return protoreflect.Value{}, 0, errInvalidUTF8{}
Joe Tsaic51e2e02019-07-13 00:44:41 -07004744 }
Damien Neil68b81c32019-08-22 11:41:32 -07004745 return protoreflect.ValueOfBytes(append(([]byte)(nil), v...)), n, nil
Joe Tsaic51e2e02019-07-13 00:44:41 -07004746}
4747
Damien Neil68b81c32019-08-22 11:41:32 -07004748var coderBytesValueValidateUTF8 = valueCoderFuncs{
4749 size: sizeBytesValue,
4750 marshal: appendBytesValueValidateUTF8,
4751 unmarshal: consumeBytesValueValidateUTF8,
Joe Tsaic51e2e02019-07-13 00:44:41 -07004752}
4753
Damien Neil68b81c32019-08-22 11:41:32 -07004754// sizeBytesSliceValue returns the size of wire encoding a [][]byte value as a repeated Bytes.
4755func sizeBytesSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) {
4756 list := listv.List()
4757 for i, llen := 0, list.Len(); i < llen; i++ {
4758 v := list.Get(i)
4759 size += tagsize + wire.SizeBytes(len(v.Bytes()))
Damien Neilc37adef2019-04-01 13:49:56 -07004760 }
4761 return size
4762}
4763
Damien Neil68b81c32019-08-22 11:41:32 -07004764// appendBytesSliceValue encodes a [][]byte value as a repeated Bytes.
4765func appendBytesSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) {
4766 list := listv.List()
4767 for i, llen := 0, list.Len(); i < llen; i++ {
4768 v := list.Get(i)
Damien Neilc37adef2019-04-01 13:49:56 -07004769 b = wire.AppendVarint(b, wiretag)
Damien Neil68b81c32019-08-22 11:41:32 -07004770 b = wire.AppendBytes(b, v.Bytes())
Damien Neilc37adef2019-04-01 13:49:56 -07004771 }
4772 return b, nil
4773}
4774
Damien Neil68b81c32019-08-22 11:41:32 -07004775// consumeBytesSliceValue wire decodes a [][]byte value as a repeated Bytes.
4776func consumeBytesSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) {
4777 list := listv.List()
Damien Neile91877d2019-06-27 10:54:42 -07004778 if wtyp != wire.BytesType {
Damien Neil68b81c32019-08-22 11:41:32 -07004779 return protoreflect.Value{}, 0, errUnknown
Damien Neile91877d2019-06-27 10:54:42 -07004780 }
4781 v, n := wire.ConsumeBytes(b)
4782 if n < 0 {
Damien Neil68b81c32019-08-22 11:41:32 -07004783 return protoreflect.Value{}, 0, wire.ParseError(n)
Damien Neile91877d2019-06-27 10:54:42 -07004784 }
Damien Neil68b81c32019-08-22 11:41:32 -07004785 list.Append(protoreflect.ValueOfBytes(append(([]byte)(nil), v...)))
4786 return listv, n, nil
Damien Neile91877d2019-06-27 10:54:42 -07004787}
4788
Damien Neil68b81c32019-08-22 11:41:32 -07004789var coderBytesSliceValue = valueCoderFuncs{
4790 size: sizeBytesSliceValue,
4791 marshal: appendBytesSliceValue,
4792 unmarshal: consumeBytesSliceValue,
Damien Neilc37adef2019-04-01 13:49:56 -07004793}
4794
Damien Neil8003f082019-08-02 15:13:00 -07004795// We append to an empty array rather than a nil []byte to get non-nil zero-length byte slices.
4796var emptyBuf [0]byte
4797
Damien Neilc37adef2019-04-01 13:49:56 -07004798var wireTypes = map[protoreflect.Kind]wire.Type{
4799 protoreflect.BoolKind: wire.VarintType,
4800 protoreflect.EnumKind: wire.VarintType,
4801 protoreflect.Int32Kind: wire.VarintType,
4802 protoreflect.Sint32Kind: wire.VarintType,
4803 protoreflect.Uint32Kind: wire.VarintType,
4804 protoreflect.Int64Kind: wire.VarintType,
4805 protoreflect.Sint64Kind: wire.VarintType,
4806 protoreflect.Uint64Kind: wire.VarintType,
4807 protoreflect.Sfixed32Kind: wire.Fixed32Type,
4808 protoreflect.Fixed32Kind: wire.Fixed32Type,
4809 protoreflect.FloatKind: wire.Fixed32Type,
4810 protoreflect.Sfixed64Kind: wire.Fixed64Type,
4811 protoreflect.Fixed64Kind: wire.Fixed64Type,
4812 protoreflect.DoubleKind: wire.Fixed64Type,
4813 protoreflect.StringKind: wire.BytesType,
4814 protoreflect.BytesKind: wire.BytesType,
4815 protoreflect.MessageKind: wire.BytesType,
4816 protoreflect.GroupKind: wire.StartGroupType,
4817}