blob: 301eeb20f82fdbe0bee178adf07d40d657977f3b [file] [log] [blame]
amit.ghosh258d14c2020-10-02 15:13:38 +02001// 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 proto
8
9import (
10 "math"
11 "unicode/utf8"
12
13 "google.golang.org/protobuf/encoding/protowire"
14 "google.golang.org/protobuf/internal/errors"
15 "google.golang.org/protobuf/internal/strs"
16 "google.golang.org/protobuf/reflect/protoreflect"
17)
18
19// unmarshalScalar decodes a value of the given kind.
20//
21// Message values are decoded into a []byte which aliases the input data.
22func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd protoreflect.FieldDescriptor) (val protoreflect.Value, n int, err error) {
23 switch fd.Kind() {
24 case protoreflect.BoolKind:
25 if wtyp != protowire.VarintType {
26 return val, 0, errUnknown
27 }
28 v, n := protowire.ConsumeVarint(b)
29 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +000030 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +020031 }
32 return protoreflect.ValueOfBool(protowire.DecodeBool(v)), n, nil
33 case protoreflect.EnumKind:
34 if wtyp != protowire.VarintType {
35 return val, 0, errUnknown
36 }
37 v, n := protowire.ConsumeVarint(b)
38 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +000039 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +020040 }
41 return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), n, nil
42 case protoreflect.Int32Kind:
43 if wtyp != protowire.VarintType {
44 return val, 0, errUnknown
45 }
46 v, n := protowire.ConsumeVarint(b)
47 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +000048 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +020049 }
50 return protoreflect.ValueOfInt32(int32(v)), n, nil
51 case protoreflect.Sint32Kind:
52 if wtyp != protowire.VarintType {
53 return val, 0, errUnknown
54 }
55 v, n := protowire.ConsumeVarint(b)
56 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +000057 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +020058 }
59 return protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))), n, nil
60 case protoreflect.Uint32Kind:
61 if wtyp != protowire.VarintType {
62 return val, 0, errUnknown
63 }
64 v, n := protowire.ConsumeVarint(b)
65 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +000066 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +020067 }
68 return protoreflect.ValueOfUint32(uint32(v)), n, nil
69 case protoreflect.Int64Kind:
70 if wtyp != protowire.VarintType {
71 return val, 0, errUnknown
72 }
73 v, n := protowire.ConsumeVarint(b)
74 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +000075 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +020076 }
77 return protoreflect.ValueOfInt64(int64(v)), n, nil
78 case protoreflect.Sint64Kind:
79 if wtyp != protowire.VarintType {
80 return val, 0, errUnknown
81 }
82 v, n := protowire.ConsumeVarint(b)
83 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +000084 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +020085 }
86 return protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)), n, nil
87 case protoreflect.Uint64Kind:
88 if wtyp != protowire.VarintType {
89 return val, 0, errUnknown
90 }
91 v, n := protowire.ConsumeVarint(b)
92 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +000093 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +020094 }
95 return protoreflect.ValueOfUint64(v), n, nil
96 case protoreflect.Sfixed32Kind:
97 if wtyp != protowire.Fixed32Type {
98 return val, 0, errUnknown
99 }
100 v, n := protowire.ConsumeFixed32(b)
101 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000102 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200103 }
104 return protoreflect.ValueOfInt32(int32(v)), n, nil
105 case protoreflect.Fixed32Kind:
106 if wtyp != protowire.Fixed32Type {
107 return val, 0, errUnknown
108 }
109 v, n := protowire.ConsumeFixed32(b)
110 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000111 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200112 }
113 return protoreflect.ValueOfUint32(uint32(v)), n, nil
114 case protoreflect.FloatKind:
115 if wtyp != protowire.Fixed32Type {
116 return val, 0, errUnknown
117 }
118 v, n := protowire.ConsumeFixed32(b)
119 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000120 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200121 }
122 return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), n, nil
123 case protoreflect.Sfixed64Kind:
124 if wtyp != protowire.Fixed64Type {
125 return val, 0, errUnknown
126 }
127 v, n := protowire.ConsumeFixed64(b)
128 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000129 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200130 }
131 return protoreflect.ValueOfInt64(int64(v)), n, nil
132 case protoreflect.Fixed64Kind:
133 if wtyp != protowire.Fixed64Type {
134 return val, 0, errUnknown
135 }
136 v, n := protowire.ConsumeFixed64(b)
137 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000138 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200139 }
140 return protoreflect.ValueOfUint64(v), n, nil
141 case protoreflect.DoubleKind:
142 if wtyp != protowire.Fixed64Type {
143 return val, 0, errUnknown
144 }
145 v, n := protowire.ConsumeFixed64(b)
146 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000147 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200148 }
149 return protoreflect.ValueOfFloat64(math.Float64frombits(v)), n, nil
150 case protoreflect.StringKind:
151 if wtyp != protowire.BytesType {
152 return val, 0, errUnknown
153 }
154 v, n := protowire.ConsumeBytes(b)
155 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000156 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200157 }
158 if strs.EnforceUTF8(fd) && !utf8.Valid(v) {
159 return protoreflect.Value{}, 0, errors.InvalidUTF8(string(fd.FullName()))
160 }
161 return protoreflect.ValueOfString(string(v)), n, nil
162 case protoreflect.BytesKind:
163 if wtyp != protowire.BytesType {
164 return val, 0, errUnknown
165 }
166 v, n := protowire.ConsumeBytes(b)
167 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000168 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200169 }
170 return protoreflect.ValueOfBytes(append(emptyBuf[:], v...)), n, nil
171 case protoreflect.MessageKind:
172 if wtyp != protowire.BytesType {
173 return val, 0, errUnknown
174 }
175 v, n := protowire.ConsumeBytes(b)
176 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000177 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200178 }
179 return protoreflect.ValueOfBytes(v), n, nil
180 case protoreflect.GroupKind:
181 if wtyp != protowire.StartGroupType {
182 return val, 0, errUnknown
183 }
184 v, n := protowire.ConsumeGroup(fd.Number(), b)
185 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000186 return val, 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200187 }
188 return protoreflect.ValueOfBytes(v), n, nil
189 default:
190 return val, 0, errUnknown
191 }
192}
193
194func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list protoreflect.List, fd protoreflect.FieldDescriptor) (n int, err error) {
195 switch fd.Kind() {
196 case protoreflect.BoolKind:
197 if wtyp == protowire.BytesType {
198 buf, n := protowire.ConsumeBytes(b)
199 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000200 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200201 }
202 for len(buf) > 0 {
203 v, n := protowire.ConsumeVarint(buf)
204 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000205 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200206 }
207 buf = buf[n:]
208 list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v)))
209 }
210 return n, nil
211 }
212 if wtyp != protowire.VarintType {
213 return 0, errUnknown
214 }
215 v, n := protowire.ConsumeVarint(b)
216 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000217 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200218 }
219 list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v)))
220 return n, nil
221 case protoreflect.EnumKind:
222 if wtyp == protowire.BytesType {
223 buf, n := protowire.ConsumeBytes(b)
224 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000225 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200226 }
227 for len(buf) > 0 {
228 v, n := protowire.ConsumeVarint(buf)
229 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000230 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200231 }
232 buf = buf[n:]
233 list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
234 }
235 return n, nil
236 }
237 if wtyp != protowire.VarintType {
238 return 0, errUnknown
239 }
240 v, n := protowire.ConsumeVarint(b)
241 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000242 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200243 }
244 list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
245 return n, nil
246 case protoreflect.Int32Kind:
247 if wtyp == protowire.BytesType {
248 buf, n := protowire.ConsumeBytes(b)
249 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000250 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200251 }
252 for len(buf) > 0 {
253 v, n := protowire.ConsumeVarint(buf)
254 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000255 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200256 }
257 buf = buf[n:]
258 list.Append(protoreflect.ValueOfInt32(int32(v)))
259 }
260 return n, nil
261 }
262 if wtyp != protowire.VarintType {
263 return 0, errUnknown
264 }
265 v, n := protowire.ConsumeVarint(b)
266 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000267 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200268 }
269 list.Append(protoreflect.ValueOfInt32(int32(v)))
270 return n, nil
271 case protoreflect.Sint32Kind:
272 if wtyp == protowire.BytesType {
273 buf, n := protowire.ConsumeBytes(b)
274 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000275 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200276 }
277 for len(buf) > 0 {
278 v, n := protowire.ConsumeVarint(buf)
279 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000280 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200281 }
282 buf = buf[n:]
283 list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))))
284 }
285 return n, nil
286 }
287 if wtyp != protowire.VarintType {
288 return 0, errUnknown
289 }
290 v, n := protowire.ConsumeVarint(b)
291 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000292 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200293 }
294 list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))))
295 return n, nil
296 case protoreflect.Uint32Kind:
297 if wtyp == protowire.BytesType {
298 buf, n := protowire.ConsumeBytes(b)
299 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000300 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200301 }
302 for len(buf) > 0 {
303 v, n := protowire.ConsumeVarint(buf)
304 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000305 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200306 }
307 buf = buf[n:]
308 list.Append(protoreflect.ValueOfUint32(uint32(v)))
309 }
310 return n, nil
311 }
312 if wtyp != protowire.VarintType {
313 return 0, errUnknown
314 }
315 v, n := protowire.ConsumeVarint(b)
316 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000317 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200318 }
319 list.Append(protoreflect.ValueOfUint32(uint32(v)))
320 return n, nil
321 case protoreflect.Int64Kind:
322 if wtyp == protowire.BytesType {
323 buf, n := protowire.ConsumeBytes(b)
324 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000325 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200326 }
327 for len(buf) > 0 {
328 v, n := protowire.ConsumeVarint(buf)
329 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000330 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200331 }
332 buf = buf[n:]
333 list.Append(protoreflect.ValueOfInt64(int64(v)))
334 }
335 return n, nil
336 }
337 if wtyp != protowire.VarintType {
338 return 0, errUnknown
339 }
340 v, n := protowire.ConsumeVarint(b)
341 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000342 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200343 }
344 list.Append(protoreflect.ValueOfInt64(int64(v)))
345 return n, nil
346 case protoreflect.Sint64Kind:
347 if wtyp == protowire.BytesType {
348 buf, n := protowire.ConsumeBytes(b)
349 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000350 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200351 }
352 for len(buf) > 0 {
353 v, n := protowire.ConsumeVarint(buf)
354 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000355 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200356 }
357 buf = buf[n:]
358 list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)))
359 }
360 return n, nil
361 }
362 if wtyp != protowire.VarintType {
363 return 0, errUnknown
364 }
365 v, n := protowire.ConsumeVarint(b)
366 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000367 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200368 }
369 list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)))
370 return n, nil
371 case protoreflect.Uint64Kind:
372 if wtyp == protowire.BytesType {
373 buf, n := protowire.ConsumeBytes(b)
374 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000375 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200376 }
377 for len(buf) > 0 {
378 v, n := protowire.ConsumeVarint(buf)
379 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000380 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200381 }
382 buf = buf[n:]
383 list.Append(protoreflect.ValueOfUint64(v))
384 }
385 return n, nil
386 }
387 if wtyp != protowire.VarintType {
388 return 0, errUnknown
389 }
390 v, n := protowire.ConsumeVarint(b)
391 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000392 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200393 }
394 list.Append(protoreflect.ValueOfUint64(v))
395 return n, nil
396 case protoreflect.Sfixed32Kind:
397 if wtyp == protowire.BytesType {
398 buf, n := protowire.ConsumeBytes(b)
399 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000400 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200401 }
402 for len(buf) > 0 {
403 v, n := protowire.ConsumeFixed32(buf)
404 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000405 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200406 }
407 buf = buf[n:]
408 list.Append(protoreflect.ValueOfInt32(int32(v)))
409 }
410 return n, nil
411 }
412 if wtyp != protowire.Fixed32Type {
413 return 0, errUnknown
414 }
415 v, n := protowire.ConsumeFixed32(b)
416 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000417 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200418 }
419 list.Append(protoreflect.ValueOfInt32(int32(v)))
420 return n, nil
421 case protoreflect.Fixed32Kind:
422 if wtyp == protowire.BytesType {
423 buf, n := protowire.ConsumeBytes(b)
424 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000425 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200426 }
427 for len(buf) > 0 {
428 v, n := protowire.ConsumeFixed32(buf)
429 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000430 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200431 }
432 buf = buf[n:]
433 list.Append(protoreflect.ValueOfUint32(uint32(v)))
434 }
435 return n, nil
436 }
437 if wtyp != protowire.Fixed32Type {
438 return 0, errUnknown
439 }
440 v, n := protowire.ConsumeFixed32(b)
441 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000442 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200443 }
444 list.Append(protoreflect.ValueOfUint32(uint32(v)))
445 return n, nil
446 case protoreflect.FloatKind:
447 if wtyp == protowire.BytesType {
448 buf, n := protowire.ConsumeBytes(b)
449 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000450 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200451 }
452 for len(buf) > 0 {
453 v, n := protowire.ConsumeFixed32(buf)
454 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000455 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200456 }
457 buf = buf[n:]
458 list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
459 }
460 return n, nil
461 }
462 if wtyp != protowire.Fixed32Type {
463 return 0, errUnknown
464 }
465 v, n := protowire.ConsumeFixed32(b)
466 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000467 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200468 }
469 list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
470 return n, nil
471 case protoreflect.Sfixed64Kind:
472 if wtyp == protowire.BytesType {
473 buf, n := protowire.ConsumeBytes(b)
474 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000475 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200476 }
477 for len(buf) > 0 {
478 v, n := protowire.ConsumeFixed64(buf)
479 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000480 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200481 }
482 buf = buf[n:]
483 list.Append(protoreflect.ValueOfInt64(int64(v)))
484 }
485 return n, nil
486 }
487 if wtyp != protowire.Fixed64Type {
488 return 0, errUnknown
489 }
490 v, n := protowire.ConsumeFixed64(b)
491 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000492 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200493 }
494 list.Append(protoreflect.ValueOfInt64(int64(v)))
495 return n, nil
496 case protoreflect.Fixed64Kind:
497 if wtyp == protowire.BytesType {
498 buf, n := protowire.ConsumeBytes(b)
499 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000500 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200501 }
502 for len(buf) > 0 {
503 v, n := protowire.ConsumeFixed64(buf)
504 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000505 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200506 }
507 buf = buf[n:]
508 list.Append(protoreflect.ValueOfUint64(v))
509 }
510 return n, nil
511 }
512 if wtyp != protowire.Fixed64Type {
513 return 0, errUnknown
514 }
515 v, n := protowire.ConsumeFixed64(b)
516 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000517 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200518 }
519 list.Append(protoreflect.ValueOfUint64(v))
520 return n, nil
521 case protoreflect.DoubleKind:
522 if wtyp == protowire.BytesType {
523 buf, n := protowire.ConsumeBytes(b)
524 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000525 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200526 }
527 for len(buf) > 0 {
528 v, n := protowire.ConsumeFixed64(buf)
529 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000530 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200531 }
532 buf = buf[n:]
533 list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
534 }
535 return n, nil
536 }
537 if wtyp != protowire.Fixed64Type {
538 return 0, errUnknown
539 }
540 v, n := protowire.ConsumeFixed64(b)
541 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000542 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200543 }
544 list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
545 return n, nil
546 case protoreflect.StringKind:
547 if wtyp != protowire.BytesType {
548 return 0, errUnknown
549 }
550 v, n := protowire.ConsumeBytes(b)
551 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000552 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200553 }
554 if strs.EnforceUTF8(fd) && !utf8.Valid(v) {
555 return 0, errors.InvalidUTF8(string(fd.FullName()))
556 }
557 list.Append(protoreflect.ValueOfString(string(v)))
558 return n, nil
559 case protoreflect.BytesKind:
560 if wtyp != protowire.BytesType {
561 return 0, errUnknown
562 }
563 v, n := protowire.ConsumeBytes(b)
564 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000565 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200566 }
567 list.Append(protoreflect.ValueOfBytes(append(emptyBuf[:], v...)))
568 return n, nil
569 case protoreflect.MessageKind:
570 if wtyp != protowire.BytesType {
571 return 0, errUnknown
572 }
573 v, n := protowire.ConsumeBytes(b)
574 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000575 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200576 }
577 m := list.NewElement()
578 if err := o.unmarshalMessage(v, m.Message()); err != nil {
579 return 0, err
580 }
581 list.Append(m)
582 return n, nil
583 case protoreflect.GroupKind:
584 if wtyp != protowire.StartGroupType {
585 return 0, errUnknown
586 }
587 v, n := protowire.ConsumeGroup(fd.Number(), b)
588 if n < 0 {
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000589 return 0, errDecode
amit.ghosh258d14c2020-10-02 15:13:38 +0200590 }
591 m := list.NewElement()
592 if err := o.unmarshalMessage(v, m.Message()); err != nil {
593 return 0, err
594 }
595 list.Append(m)
596 return n, nil
597 default:
598 return 0, errUnknown
599 }
600}
601
602// We append to an empty array rather than a nil []byte to get non-nil zero-length byte slices.
603var emptyBuf [0]byte