khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame^] | 1 | // 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 | |
| 7 | package impl |
| 8 | |
| 9 | import ( |
| 10 | "math" |
| 11 | "unicode/utf8" |
| 12 | |
| 13 | "google.golang.org/protobuf/encoding/protowire" |
| 14 | "google.golang.org/protobuf/reflect/protoreflect" |
| 15 | ) |
| 16 | |
| 17 | // sizeBool returns the size of wire encoding a bool pointer as a Bool. |
| 18 | func sizeBool(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 19 | v := *p.Bool() |
| 20 | return f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v)) |
| 21 | } |
| 22 | |
| 23 | // appendBool wire encodes a bool pointer as a Bool. |
| 24 | func appendBool(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 25 | v := *p.Bool() |
| 26 | b = protowire.AppendVarint(b, f.wiretag) |
| 27 | b = protowire.AppendVarint(b, protowire.EncodeBool(v)) |
| 28 | return b, nil |
| 29 | } |
| 30 | |
| 31 | // consumeBool wire decodes a bool pointer as a Bool. |
| 32 | func consumeBool(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 33 | if wtyp != protowire.VarintType { |
| 34 | return out, errUnknown |
| 35 | } |
| 36 | var v uint64 |
| 37 | var n int |
| 38 | if len(b) >= 1 && b[0] < 0x80 { |
| 39 | v = uint64(b[0]) |
| 40 | n = 1 |
| 41 | } else if len(b) >= 2 && b[1] < 128 { |
| 42 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 43 | n = 2 |
| 44 | } else { |
| 45 | v, n = protowire.ConsumeVarint(b) |
| 46 | } |
| 47 | if n < 0 { |
| 48 | return out, errDecode |
| 49 | } |
| 50 | *p.Bool() = protowire.DecodeBool(v) |
| 51 | out.n = n |
| 52 | return out, nil |
| 53 | } |
| 54 | |
| 55 | var coderBool = pointerCoderFuncs{ |
| 56 | size: sizeBool, |
| 57 | marshal: appendBool, |
| 58 | unmarshal: consumeBool, |
| 59 | merge: mergeBool, |
| 60 | } |
| 61 | |
| 62 | // sizeBoolNoZero returns the size of wire encoding a bool pointer as a Bool. |
| 63 | // The zero value is not encoded. |
| 64 | func sizeBoolNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 65 | v := *p.Bool() |
| 66 | if v == false { |
| 67 | return 0 |
| 68 | } |
| 69 | return f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v)) |
| 70 | } |
| 71 | |
| 72 | // appendBoolNoZero wire encodes a bool pointer as a Bool. |
| 73 | // The zero value is not encoded. |
| 74 | func appendBoolNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 75 | v := *p.Bool() |
| 76 | if v == false { |
| 77 | return b, nil |
| 78 | } |
| 79 | b = protowire.AppendVarint(b, f.wiretag) |
| 80 | b = protowire.AppendVarint(b, protowire.EncodeBool(v)) |
| 81 | return b, nil |
| 82 | } |
| 83 | |
| 84 | var coderBoolNoZero = pointerCoderFuncs{ |
| 85 | size: sizeBoolNoZero, |
| 86 | marshal: appendBoolNoZero, |
| 87 | unmarshal: consumeBool, |
| 88 | merge: mergeBoolNoZero, |
| 89 | } |
| 90 | |
| 91 | // sizeBoolPtr returns the size of wire encoding a *bool pointer as a Bool. |
| 92 | // It panics if the pointer is nil. |
| 93 | func sizeBoolPtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 94 | v := **p.BoolPtr() |
| 95 | return f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v)) |
| 96 | } |
| 97 | |
| 98 | // appendBoolPtr wire encodes a *bool pointer as a Bool. |
| 99 | // It panics if the pointer is nil. |
| 100 | func appendBoolPtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 101 | v := **p.BoolPtr() |
| 102 | b = protowire.AppendVarint(b, f.wiretag) |
| 103 | b = protowire.AppendVarint(b, protowire.EncodeBool(v)) |
| 104 | return b, nil |
| 105 | } |
| 106 | |
| 107 | // consumeBoolPtr wire decodes a *bool pointer as a Bool. |
| 108 | func consumeBoolPtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 109 | if wtyp != protowire.VarintType { |
| 110 | return out, errUnknown |
| 111 | } |
| 112 | var v uint64 |
| 113 | var n int |
| 114 | if len(b) >= 1 && b[0] < 0x80 { |
| 115 | v = uint64(b[0]) |
| 116 | n = 1 |
| 117 | } else if len(b) >= 2 && b[1] < 128 { |
| 118 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 119 | n = 2 |
| 120 | } else { |
| 121 | v, n = protowire.ConsumeVarint(b) |
| 122 | } |
| 123 | if n < 0 { |
| 124 | return out, errDecode |
| 125 | } |
| 126 | vp := p.BoolPtr() |
| 127 | if *vp == nil { |
| 128 | *vp = new(bool) |
| 129 | } |
| 130 | **vp = protowire.DecodeBool(v) |
| 131 | out.n = n |
| 132 | return out, nil |
| 133 | } |
| 134 | |
| 135 | var coderBoolPtr = pointerCoderFuncs{ |
| 136 | size: sizeBoolPtr, |
| 137 | marshal: appendBoolPtr, |
| 138 | unmarshal: consumeBoolPtr, |
| 139 | merge: mergeBoolPtr, |
| 140 | } |
| 141 | |
| 142 | // sizeBoolSlice returns the size of wire encoding a []bool pointer as a repeated Bool. |
| 143 | func sizeBoolSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 144 | s := *p.BoolSlice() |
| 145 | for _, v := range s { |
| 146 | size += f.tagsize + protowire.SizeVarint(protowire.EncodeBool(v)) |
| 147 | } |
| 148 | return size |
| 149 | } |
| 150 | |
| 151 | // appendBoolSlice encodes a []bool pointer as a repeated Bool. |
| 152 | func appendBoolSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 153 | s := *p.BoolSlice() |
| 154 | for _, v := range s { |
| 155 | b = protowire.AppendVarint(b, f.wiretag) |
| 156 | b = protowire.AppendVarint(b, protowire.EncodeBool(v)) |
| 157 | } |
| 158 | return b, nil |
| 159 | } |
| 160 | |
| 161 | // consumeBoolSlice wire decodes a []bool pointer as a repeated Bool. |
| 162 | func consumeBoolSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 163 | sp := p.BoolSlice() |
| 164 | if wtyp == protowire.BytesType { |
| 165 | s := *sp |
| 166 | b, n := protowire.ConsumeBytes(b) |
| 167 | if n < 0 { |
| 168 | return out, errDecode |
| 169 | } |
| 170 | for len(b) > 0 { |
| 171 | var v uint64 |
| 172 | var n int |
| 173 | if len(b) >= 1 && b[0] < 0x80 { |
| 174 | v = uint64(b[0]) |
| 175 | n = 1 |
| 176 | } else if len(b) >= 2 && b[1] < 128 { |
| 177 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 178 | n = 2 |
| 179 | } else { |
| 180 | v, n = protowire.ConsumeVarint(b) |
| 181 | } |
| 182 | if n < 0 { |
| 183 | return out, errDecode |
| 184 | } |
| 185 | s = append(s, protowire.DecodeBool(v)) |
| 186 | b = b[n:] |
| 187 | } |
| 188 | *sp = s |
| 189 | out.n = n |
| 190 | return out, nil |
| 191 | } |
| 192 | if wtyp != protowire.VarintType { |
| 193 | return out, errUnknown |
| 194 | } |
| 195 | var v uint64 |
| 196 | var n int |
| 197 | if len(b) >= 1 && b[0] < 0x80 { |
| 198 | v = uint64(b[0]) |
| 199 | n = 1 |
| 200 | } else if len(b) >= 2 && b[1] < 128 { |
| 201 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 202 | n = 2 |
| 203 | } else { |
| 204 | v, n = protowire.ConsumeVarint(b) |
| 205 | } |
| 206 | if n < 0 { |
| 207 | return out, errDecode |
| 208 | } |
| 209 | *sp = append(*sp, protowire.DecodeBool(v)) |
| 210 | out.n = n |
| 211 | return out, nil |
| 212 | } |
| 213 | |
| 214 | var coderBoolSlice = pointerCoderFuncs{ |
| 215 | size: sizeBoolSlice, |
| 216 | marshal: appendBoolSlice, |
| 217 | unmarshal: consumeBoolSlice, |
| 218 | merge: mergeBoolSlice, |
| 219 | } |
| 220 | |
| 221 | // sizeBoolPackedSlice returns the size of wire encoding a []bool pointer as a packed repeated Bool. |
| 222 | func sizeBoolPackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 223 | s := *p.BoolSlice() |
| 224 | if len(s) == 0 { |
| 225 | return 0 |
| 226 | } |
| 227 | n := 0 |
| 228 | for _, v := range s { |
| 229 | n += protowire.SizeVarint(protowire.EncodeBool(v)) |
| 230 | } |
| 231 | return f.tagsize + protowire.SizeBytes(n) |
| 232 | } |
| 233 | |
| 234 | // appendBoolPackedSlice encodes a []bool pointer as a packed repeated Bool. |
| 235 | func appendBoolPackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 236 | s := *p.BoolSlice() |
| 237 | if len(s) == 0 { |
| 238 | return b, nil |
| 239 | } |
| 240 | b = protowire.AppendVarint(b, f.wiretag) |
| 241 | n := 0 |
| 242 | for _, v := range s { |
| 243 | n += protowire.SizeVarint(protowire.EncodeBool(v)) |
| 244 | } |
| 245 | b = protowire.AppendVarint(b, uint64(n)) |
| 246 | for _, v := range s { |
| 247 | b = protowire.AppendVarint(b, protowire.EncodeBool(v)) |
| 248 | } |
| 249 | return b, nil |
| 250 | } |
| 251 | |
| 252 | var coderBoolPackedSlice = pointerCoderFuncs{ |
| 253 | size: sizeBoolPackedSlice, |
| 254 | marshal: appendBoolPackedSlice, |
| 255 | unmarshal: consumeBoolSlice, |
| 256 | merge: mergeBoolSlice, |
| 257 | } |
| 258 | |
| 259 | // sizeBoolValue returns the size of wire encoding a bool value as a Bool. |
| 260 | func sizeBoolValue(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 261 | return tagsize + protowire.SizeVarint(protowire.EncodeBool(v.Bool())) |
| 262 | } |
| 263 | |
| 264 | // appendBoolValue encodes a bool value as a Bool. |
| 265 | func appendBoolValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 266 | b = protowire.AppendVarint(b, wiretag) |
| 267 | b = protowire.AppendVarint(b, protowire.EncodeBool(v.Bool())) |
| 268 | return b, nil |
| 269 | } |
| 270 | |
| 271 | // consumeBoolValue decodes a bool value as a Bool. |
| 272 | func consumeBoolValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 273 | if wtyp != protowire.VarintType { |
| 274 | return protoreflect.Value{}, out, errUnknown |
| 275 | } |
| 276 | var v uint64 |
| 277 | var n int |
| 278 | if len(b) >= 1 && b[0] < 0x80 { |
| 279 | v = uint64(b[0]) |
| 280 | n = 1 |
| 281 | } else if len(b) >= 2 && b[1] < 128 { |
| 282 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 283 | n = 2 |
| 284 | } else { |
| 285 | v, n = protowire.ConsumeVarint(b) |
| 286 | } |
| 287 | if n < 0 { |
| 288 | return protoreflect.Value{}, out, errDecode |
| 289 | } |
| 290 | out.n = n |
| 291 | return protoreflect.ValueOfBool(protowire.DecodeBool(v)), out, nil |
| 292 | } |
| 293 | |
| 294 | var coderBoolValue = valueCoderFuncs{ |
| 295 | size: sizeBoolValue, |
| 296 | marshal: appendBoolValue, |
| 297 | unmarshal: consumeBoolValue, |
| 298 | merge: mergeScalarValue, |
| 299 | } |
| 300 | |
| 301 | // sizeBoolSliceValue returns the size of wire encoding a []bool value as a repeated Bool. |
| 302 | func sizeBoolSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 303 | list := listv.List() |
| 304 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 305 | v := list.Get(i) |
| 306 | size += tagsize + protowire.SizeVarint(protowire.EncodeBool(v.Bool())) |
| 307 | } |
| 308 | return size |
| 309 | } |
| 310 | |
| 311 | // appendBoolSliceValue encodes a []bool value as a repeated Bool. |
| 312 | func appendBoolSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 313 | list := listv.List() |
| 314 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 315 | v := list.Get(i) |
| 316 | b = protowire.AppendVarint(b, wiretag) |
| 317 | b = protowire.AppendVarint(b, protowire.EncodeBool(v.Bool())) |
| 318 | } |
| 319 | return b, nil |
| 320 | } |
| 321 | |
| 322 | // consumeBoolSliceValue wire decodes a []bool value as a repeated Bool. |
| 323 | func consumeBoolSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 324 | list := listv.List() |
| 325 | if wtyp == protowire.BytesType { |
| 326 | b, n := protowire.ConsumeBytes(b) |
| 327 | if n < 0 { |
| 328 | return protoreflect.Value{}, out, errDecode |
| 329 | } |
| 330 | for len(b) > 0 { |
| 331 | var v uint64 |
| 332 | var n int |
| 333 | if len(b) >= 1 && b[0] < 0x80 { |
| 334 | v = uint64(b[0]) |
| 335 | n = 1 |
| 336 | } else if len(b) >= 2 && b[1] < 128 { |
| 337 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 338 | n = 2 |
| 339 | } else { |
| 340 | v, n = protowire.ConsumeVarint(b) |
| 341 | } |
| 342 | if n < 0 { |
| 343 | return protoreflect.Value{}, out, errDecode |
| 344 | } |
| 345 | list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v))) |
| 346 | b = b[n:] |
| 347 | } |
| 348 | out.n = n |
| 349 | return listv, out, nil |
| 350 | } |
| 351 | if wtyp != protowire.VarintType { |
| 352 | return protoreflect.Value{}, out, errUnknown |
| 353 | } |
| 354 | var v uint64 |
| 355 | var n int |
| 356 | if len(b) >= 1 && b[0] < 0x80 { |
| 357 | v = uint64(b[0]) |
| 358 | n = 1 |
| 359 | } else if len(b) >= 2 && b[1] < 128 { |
| 360 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 361 | n = 2 |
| 362 | } else { |
| 363 | v, n = protowire.ConsumeVarint(b) |
| 364 | } |
| 365 | if n < 0 { |
| 366 | return protoreflect.Value{}, out, errDecode |
| 367 | } |
| 368 | list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v))) |
| 369 | out.n = n |
| 370 | return listv, out, nil |
| 371 | } |
| 372 | |
| 373 | var coderBoolSliceValue = valueCoderFuncs{ |
| 374 | size: sizeBoolSliceValue, |
| 375 | marshal: appendBoolSliceValue, |
| 376 | unmarshal: consumeBoolSliceValue, |
| 377 | merge: mergeListValue, |
| 378 | } |
| 379 | |
| 380 | // sizeBoolPackedSliceValue returns the size of wire encoding a []bool value as a packed repeated Bool. |
| 381 | func sizeBoolPackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 382 | list := listv.List() |
| 383 | llen := list.Len() |
| 384 | if llen == 0 { |
| 385 | return 0 |
| 386 | } |
| 387 | n := 0 |
| 388 | for i, llen := 0, llen; i < llen; i++ { |
| 389 | v := list.Get(i) |
| 390 | n += protowire.SizeVarint(protowire.EncodeBool(v.Bool())) |
| 391 | } |
| 392 | return tagsize + protowire.SizeBytes(n) |
| 393 | } |
| 394 | |
| 395 | // appendBoolPackedSliceValue encodes a []bool value as a packed repeated Bool. |
| 396 | func appendBoolPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 397 | list := listv.List() |
| 398 | llen := list.Len() |
| 399 | if llen == 0 { |
| 400 | return b, nil |
| 401 | } |
| 402 | b = protowire.AppendVarint(b, wiretag) |
| 403 | n := 0 |
| 404 | for i := 0; i < llen; i++ { |
| 405 | v := list.Get(i) |
| 406 | n += protowire.SizeVarint(protowire.EncodeBool(v.Bool())) |
| 407 | } |
| 408 | b = protowire.AppendVarint(b, uint64(n)) |
| 409 | for i := 0; i < llen; i++ { |
| 410 | v := list.Get(i) |
| 411 | b = protowire.AppendVarint(b, protowire.EncodeBool(v.Bool())) |
| 412 | } |
| 413 | return b, nil |
| 414 | } |
| 415 | |
| 416 | var coderBoolPackedSliceValue = valueCoderFuncs{ |
| 417 | size: sizeBoolPackedSliceValue, |
| 418 | marshal: appendBoolPackedSliceValue, |
| 419 | unmarshal: consumeBoolSliceValue, |
| 420 | merge: mergeListValue, |
| 421 | } |
| 422 | |
| 423 | // sizeEnumValue returns the size of wire encoding a value as a Enum. |
| 424 | func sizeEnumValue(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 425 | return tagsize + protowire.SizeVarint(uint64(v.Enum())) |
| 426 | } |
| 427 | |
| 428 | // appendEnumValue encodes a value as a Enum. |
| 429 | func appendEnumValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 430 | b = protowire.AppendVarint(b, wiretag) |
| 431 | b = protowire.AppendVarint(b, uint64(v.Enum())) |
| 432 | return b, nil |
| 433 | } |
| 434 | |
| 435 | // consumeEnumValue decodes a value as a Enum. |
| 436 | func consumeEnumValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 437 | if wtyp != protowire.VarintType { |
| 438 | return protoreflect.Value{}, out, errUnknown |
| 439 | } |
| 440 | var v uint64 |
| 441 | var n int |
| 442 | if len(b) >= 1 && b[0] < 0x80 { |
| 443 | v = uint64(b[0]) |
| 444 | n = 1 |
| 445 | } else if len(b) >= 2 && b[1] < 128 { |
| 446 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 447 | n = 2 |
| 448 | } else { |
| 449 | v, n = protowire.ConsumeVarint(b) |
| 450 | } |
| 451 | if n < 0 { |
| 452 | return protoreflect.Value{}, out, errDecode |
| 453 | } |
| 454 | out.n = n |
| 455 | return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), out, nil |
| 456 | } |
| 457 | |
| 458 | var coderEnumValue = valueCoderFuncs{ |
| 459 | size: sizeEnumValue, |
| 460 | marshal: appendEnumValue, |
| 461 | unmarshal: consumeEnumValue, |
| 462 | merge: mergeScalarValue, |
| 463 | } |
| 464 | |
| 465 | // sizeEnumSliceValue returns the size of wire encoding a [] value as a repeated Enum. |
| 466 | func sizeEnumSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 467 | list := listv.List() |
| 468 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 469 | v := list.Get(i) |
| 470 | size += tagsize + protowire.SizeVarint(uint64(v.Enum())) |
| 471 | } |
| 472 | return size |
| 473 | } |
| 474 | |
| 475 | // appendEnumSliceValue encodes a [] value as a repeated Enum. |
| 476 | func appendEnumSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 477 | list := listv.List() |
| 478 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 479 | v := list.Get(i) |
| 480 | b = protowire.AppendVarint(b, wiretag) |
| 481 | b = protowire.AppendVarint(b, uint64(v.Enum())) |
| 482 | } |
| 483 | return b, nil |
| 484 | } |
| 485 | |
| 486 | // consumeEnumSliceValue wire decodes a [] value as a repeated Enum. |
| 487 | func consumeEnumSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 488 | list := listv.List() |
| 489 | if wtyp == protowire.BytesType { |
| 490 | b, n := protowire.ConsumeBytes(b) |
| 491 | if n < 0 { |
| 492 | return protoreflect.Value{}, out, errDecode |
| 493 | } |
| 494 | for len(b) > 0 { |
| 495 | var v uint64 |
| 496 | var n int |
| 497 | if len(b) >= 1 && b[0] < 0x80 { |
| 498 | v = uint64(b[0]) |
| 499 | n = 1 |
| 500 | } else if len(b) >= 2 && b[1] < 128 { |
| 501 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 502 | n = 2 |
| 503 | } else { |
| 504 | v, n = protowire.ConsumeVarint(b) |
| 505 | } |
| 506 | if n < 0 { |
| 507 | return protoreflect.Value{}, out, errDecode |
| 508 | } |
| 509 | list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v))) |
| 510 | b = b[n:] |
| 511 | } |
| 512 | out.n = n |
| 513 | return listv, out, nil |
| 514 | } |
| 515 | if wtyp != protowire.VarintType { |
| 516 | return protoreflect.Value{}, out, errUnknown |
| 517 | } |
| 518 | var v uint64 |
| 519 | var n int |
| 520 | if len(b) >= 1 && b[0] < 0x80 { |
| 521 | v = uint64(b[0]) |
| 522 | n = 1 |
| 523 | } else if len(b) >= 2 && b[1] < 128 { |
| 524 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 525 | n = 2 |
| 526 | } else { |
| 527 | v, n = protowire.ConsumeVarint(b) |
| 528 | } |
| 529 | if n < 0 { |
| 530 | return protoreflect.Value{}, out, errDecode |
| 531 | } |
| 532 | list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v))) |
| 533 | out.n = n |
| 534 | return listv, out, nil |
| 535 | } |
| 536 | |
| 537 | var coderEnumSliceValue = valueCoderFuncs{ |
| 538 | size: sizeEnumSliceValue, |
| 539 | marshal: appendEnumSliceValue, |
| 540 | unmarshal: consumeEnumSliceValue, |
| 541 | merge: mergeListValue, |
| 542 | } |
| 543 | |
| 544 | // sizeEnumPackedSliceValue returns the size of wire encoding a [] value as a packed repeated Enum. |
| 545 | func sizeEnumPackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 546 | list := listv.List() |
| 547 | llen := list.Len() |
| 548 | if llen == 0 { |
| 549 | return 0 |
| 550 | } |
| 551 | n := 0 |
| 552 | for i, llen := 0, llen; i < llen; i++ { |
| 553 | v := list.Get(i) |
| 554 | n += protowire.SizeVarint(uint64(v.Enum())) |
| 555 | } |
| 556 | return tagsize + protowire.SizeBytes(n) |
| 557 | } |
| 558 | |
| 559 | // appendEnumPackedSliceValue encodes a [] value as a packed repeated Enum. |
| 560 | func appendEnumPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 561 | list := listv.List() |
| 562 | llen := list.Len() |
| 563 | if llen == 0 { |
| 564 | return b, nil |
| 565 | } |
| 566 | b = protowire.AppendVarint(b, wiretag) |
| 567 | n := 0 |
| 568 | for i := 0; i < llen; i++ { |
| 569 | v := list.Get(i) |
| 570 | n += protowire.SizeVarint(uint64(v.Enum())) |
| 571 | } |
| 572 | b = protowire.AppendVarint(b, uint64(n)) |
| 573 | for i := 0; i < llen; i++ { |
| 574 | v := list.Get(i) |
| 575 | b = protowire.AppendVarint(b, uint64(v.Enum())) |
| 576 | } |
| 577 | return b, nil |
| 578 | } |
| 579 | |
| 580 | var coderEnumPackedSliceValue = valueCoderFuncs{ |
| 581 | size: sizeEnumPackedSliceValue, |
| 582 | marshal: appendEnumPackedSliceValue, |
| 583 | unmarshal: consumeEnumSliceValue, |
| 584 | merge: mergeListValue, |
| 585 | } |
| 586 | |
| 587 | // sizeInt32 returns the size of wire encoding a int32 pointer as a Int32. |
| 588 | func sizeInt32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 589 | v := *p.Int32() |
| 590 | return f.tagsize + protowire.SizeVarint(uint64(v)) |
| 591 | } |
| 592 | |
| 593 | // appendInt32 wire encodes a int32 pointer as a Int32. |
| 594 | func appendInt32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 595 | v := *p.Int32() |
| 596 | b = protowire.AppendVarint(b, f.wiretag) |
| 597 | b = protowire.AppendVarint(b, uint64(v)) |
| 598 | return b, nil |
| 599 | } |
| 600 | |
| 601 | // consumeInt32 wire decodes a int32 pointer as a Int32. |
| 602 | func consumeInt32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 603 | if wtyp != protowire.VarintType { |
| 604 | return out, errUnknown |
| 605 | } |
| 606 | var v uint64 |
| 607 | var n int |
| 608 | if len(b) >= 1 && b[0] < 0x80 { |
| 609 | v = uint64(b[0]) |
| 610 | n = 1 |
| 611 | } else if len(b) >= 2 && b[1] < 128 { |
| 612 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 613 | n = 2 |
| 614 | } else { |
| 615 | v, n = protowire.ConsumeVarint(b) |
| 616 | } |
| 617 | if n < 0 { |
| 618 | return out, errDecode |
| 619 | } |
| 620 | *p.Int32() = int32(v) |
| 621 | out.n = n |
| 622 | return out, nil |
| 623 | } |
| 624 | |
| 625 | var coderInt32 = pointerCoderFuncs{ |
| 626 | size: sizeInt32, |
| 627 | marshal: appendInt32, |
| 628 | unmarshal: consumeInt32, |
| 629 | merge: mergeInt32, |
| 630 | } |
| 631 | |
| 632 | // sizeInt32NoZero returns the size of wire encoding a int32 pointer as a Int32. |
| 633 | // The zero value is not encoded. |
| 634 | func sizeInt32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 635 | v := *p.Int32() |
| 636 | if v == 0 { |
| 637 | return 0 |
| 638 | } |
| 639 | return f.tagsize + protowire.SizeVarint(uint64(v)) |
| 640 | } |
| 641 | |
| 642 | // appendInt32NoZero wire encodes a int32 pointer as a Int32. |
| 643 | // The zero value is not encoded. |
| 644 | func appendInt32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 645 | v := *p.Int32() |
| 646 | if v == 0 { |
| 647 | return b, nil |
| 648 | } |
| 649 | b = protowire.AppendVarint(b, f.wiretag) |
| 650 | b = protowire.AppendVarint(b, uint64(v)) |
| 651 | return b, nil |
| 652 | } |
| 653 | |
| 654 | var coderInt32NoZero = pointerCoderFuncs{ |
| 655 | size: sizeInt32NoZero, |
| 656 | marshal: appendInt32NoZero, |
| 657 | unmarshal: consumeInt32, |
| 658 | merge: mergeInt32NoZero, |
| 659 | } |
| 660 | |
| 661 | // sizeInt32Ptr returns the size of wire encoding a *int32 pointer as a Int32. |
| 662 | // It panics if the pointer is nil. |
| 663 | func sizeInt32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 664 | v := **p.Int32Ptr() |
| 665 | return f.tagsize + protowire.SizeVarint(uint64(v)) |
| 666 | } |
| 667 | |
| 668 | // appendInt32Ptr wire encodes a *int32 pointer as a Int32. |
| 669 | // It panics if the pointer is nil. |
| 670 | func appendInt32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 671 | v := **p.Int32Ptr() |
| 672 | b = protowire.AppendVarint(b, f.wiretag) |
| 673 | b = protowire.AppendVarint(b, uint64(v)) |
| 674 | return b, nil |
| 675 | } |
| 676 | |
| 677 | // consumeInt32Ptr wire decodes a *int32 pointer as a Int32. |
| 678 | func consumeInt32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 679 | if wtyp != protowire.VarintType { |
| 680 | return out, errUnknown |
| 681 | } |
| 682 | var v uint64 |
| 683 | var n int |
| 684 | if len(b) >= 1 && b[0] < 0x80 { |
| 685 | v = uint64(b[0]) |
| 686 | n = 1 |
| 687 | } else if len(b) >= 2 && b[1] < 128 { |
| 688 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 689 | n = 2 |
| 690 | } else { |
| 691 | v, n = protowire.ConsumeVarint(b) |
| 692 | } |
| 693 | if n < 0 { |
| 694 | return out, errDecode |
| 695 | } |
| 696 | vp := p.Int32Ptr() |
| 697 | if *vp == nil { |
| 698 | *vp = new(int32) |
| 699 | } |
| 700 | **vp = int32(v) |
| 701 | out.n = n |
| 702 | return out, nil |
| 703 | } |
| 704 | |
| 705 | var coderInt32Ptr = pointerCoderFuncs{ |
| 706 | size: sizeInt32Ptr, |
| 707 | marshal: appendInt32Ptr, |
| 708 | unmarshal: consumeInt32Ptr, |
| 709 | merge: mergeInt32Ptr, |
| 710 | } |
| 711 | |
| 712 | // sizeInt32Slice returns the size of wire encoding a []int32 pointer as a repeated Int32. |
| 713 | func sizeInt32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 714 | s := *p.Int32Slice() |
| 715 | for _, v := range s { |
| 716 | size += f.tagsize + protowire.SizeVarint(uint64(v)) |
| 717 | } |
| 718 | return size |
| 719 | } |
| 720 | |
| 721 | // appendInt32Slice encodes a []int32 pointer as a repeated Int32. |
| 722 | func appendInt32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 723 | s := *p.Int32Slice() |
| 724 | for _, v := range s { |
| 725 | b = protowire.AppendVarint(b, f.wiretag) |
| 726 | b = protowire.AppendVarint(b, uint64(v)) |
| 727 | } |
| 728 | return b, nil |
| 729 | } |
| 730 | |
| 731 | // consumeInt32Slice wire decodes a []int32 pointer as a repeated Int32. |
| 732 | func consumeInt32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 733 | sp := p.Int32Slice() |
| 734 | if wtyp == protowire.BytesType { |
| 735 | s := *sp |
| 736 | b, n := protowire.ConsumeBytes(b) |
| 737 | if n < 0 { |
| 738 | return out, errDecode |
| 739 | } |
| 740 | for len(b) > 0 { |
| 741 | var v uint64 |
| 742 | var n int |
| 743 | if len(b) >= 1 && b[0] < 0x80 { |
| 744 | v = uint64(b[0]) |
| 745 | n = 1 |
| 746 | } else if len(b) >= 2 && b[1] < 128 { |
| 747 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 748 | n = 2 |
| 749 | } else { |
| 750 | v, n = protowire.ConsumeVarint(b) |
| 751 | } |
| 752 | if n < 0 { |
| 753 | return out, errDecode |
| 754 | } |
| 755 | s = append(s, int32(v)) |
| 756 | b = b[n:] |
| 757 | } |
| 758 | *sp = s |
| 759 | out.n = n |
| 760 | return out, nil |
| 761 | } |
| 762 | if wtyp != protowire.VarintType { |
| 763 | return out, errUnknown |
| 764 | } |
| 765 | var v uint64 |
| 766 | var n int |
| 767 | if len(b) >= 1 && b[0] < 0x80 { |
| 768 | v = uint64(b[0]) |
| 769 | n = 1 |
| 770 | } else if len(b) >= 2 && b[1] < 128 { |
| 771 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 772 | n = 2 |
| 773 | } else { |
| 774 | v, n = protowire.ConsumeVarint(b) |
| 775 | } |
| 776 | if n < 0 { |
| 777 | return out, errDecode |
| 778 | } |
| 779 | *sp = append(*sp, int32(v)) |
| 780 | out.n = n |
| 781 | return out, nil |
| 782 | } |
| 783 | |
| 784 | var coderInt32Slice = pointerCoderFuncs{ |
| 785 | size: sizeInt32Slice, |
| 786 | marshal: appendInt32Slice, |
| 787 | unmarshal: consumeInt32Slice, |
| 788 | merge: mergeInt32Slice, |
| 789 | } |
| 790 | |
| 791 | // sizeInt32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Int32. |
| 792 | func sizeInt32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 793 | s := *p.Int32Slice() |
| 794 | if len(s) == 0 { |
| 795 | return 0 |
| 796 | } |
| 797 | n := 0 |
| 798 | for _, v := range s { |
| 799 | n += protowire.SizeVarint(uint64(v)) |
| 800 | } |
| 801 | return f.tagsize + protowire.SizeBytes(n) |
| 802 | } |
| 803 | |
| 804 | // appendInt32PackedSlice encodes a []int32 pointer as a packed repeated Int32. |
| 805 | func appendInt32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 806 | s := *p.Int32Slice() |
| 807 | if len(s) == 0 { |
| 808 | return b, nil |
| 809 | } |
| 810 | b = protowire.AppendVarint(b, f.wiretag) |
| 811 | n := 0 |
| 812 | for _, v := range s { |
| 813 | n += protowire.SizeVarint(uint64(v)) |
| 814 | } |
| 815 | b = protowire.AppendVarint(b, uint64(n)) |
| 816 | for _, v := range s { |
| 817 | b = protowire.AppendVarint(b, uint64(v)) |
| 818 | } |
| 819 | return b, nil |
| 820 | } |
| 821 | |
| 822 | var coderInt32PackedSlice = pointerCoderFuncs{ |
| 823 | size: sizeInt32PackedSlice, |
| 824 | marshal: appendInt32PackedSlice, |
| 825 | unmarshal: consumeInt32Slice, |
| 826 | merge: mergeInt32Slice, |
| 827 | } |
| 828 | |
| 829 | // sizeInt32Value returns the size of wire encoding a int32 value as a Int32. |
| 830 | func sizeInt32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 831 | return tagsize + protowire.SizeVarint(uint64(int32(v.Int()))) |
| 832 | } |
| 833 | |
| 834 | // appendInt32Value encodes a int32 value as a Int32. |
| 835 | func appendInt32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 836 | b = protowire.AppendVarint(b, wiretag) |
| 837 | b = protowire.AppendVarint(b, uint64(int32(v.Int()))) |
| 838 | return b, nil |
| 839 | } |
| 840 | |
| 841 | // consumeInt32Value decodes a int32 value as a Int32. |
| 842 | func consumeInt32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 843 | if wtyp != protowire.VarintType { |
| 844 | return protoreflect.Value{}, out, errUnknown |
| 845 | } |
| 846 | var v uint64 |
| 847 | var n int |
| 848 | if len(b) >= 1 && b[0] < 0x80 { |
| 849 | v = uint64(b[0]) |
| 850 | n = 1 |
| 851 | } else if len(b) >= 2 && b[1] < 128 { |
| 852 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 853 | n = 2 |
| 854 | } else { |
| 855 | v, n = protowire.ConsumeVarint(b) |
| 856 | } |
| 857 | if n < 0 { |
| 858 | return protoreflect.Value{}, out, errDecode |
| 859 | } |
| 860 | out.n = n |
| 861 | return protoreflect.ValueOfInt32(int32(v)), out, nil |
| 862 | } |
| 863 | |
| 864 | var coderInt32Value = valueCoderFuncs{ |
| 865 | size: sizeInt32Value, |
| 866 | marshal: appendInt32Value, |
| 867 | unmarshal: consumeInt32Value, |
| 868 | merge: mergeScalarValue, |
| 869 | } |
| 870 | |
| 871 | // sizeInt32SliceValue returns the size of wire encoding a []int32 value as a repeated Int32. |
| 872 | func sizeInt32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 873 | list := listv.List() |
| 874 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 875 | v := list.Get(i) |
| 876 | size += tagsize + protowire.SizeVarint(uint64(int32(v.Int()))) |
| 877 | } |
| 878 | return size |
| 879 | } |
| 880 | |
| 881 | // appendInt32SliceValue encodes a []int32 value as a repeated Int32. |
| 882 | func appendInt32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 883 | list := listv.List() |
| 884 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 885 | v := list.Get(i) |
| 886 | b = protowire.AppendVarint(b, wiretag) |
| 887 | b = protowire.AppendVarint(b, uint64(int32(v.Int()))) |
| 888 | } |
| 889 | return b, nil |
| 890 | } |
| 891 | |
| 892 | // consumeInt32SliceValue wire decodes a []int32 value as a repeated Int32. |
| 893 | func consumeInt32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 894 | list := listv.List() |
| 895 | if wtyp == protowire.BytesType { |
| 896 | b, n := protowire.ConsumeBytes(b) |
| 897 | if n < 0 { |
| 898 | return protoreflect.Value{}, out, errDecode |
| 899 | } |
| 900 | for len(b) > 0 { |
| 901 | var v uint64 |
| 902 | var n int |
| 903 | if len(b) >= 1 && b[0] < 0x80 { |
| 904 | v = uint64(b[0]) |
| 905 | n = 1 |
| 906 | } else if len(b) >= 2 && b[1] < 128 { |
| 907 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 908 | n = 2 |
| 909 | } else { |
| 910 | v, n = protowire.ConsumeVarint(b) |
| 911 | } |
| 912 | if n < 0 { |
| 913 | return protoreflect.Value{}, out, errDecode |
| 914 | } |
| 915 | list.Append(protoreflect.ValueOfInt32(int32(v))) |
| 916 | b = b[n:] |
| 917 | } |
| 918 | out.n = n |
| 919 | return listv, out, nil |
| 920 | } |
| 921 | if wtyp != protowire.VarintType { |
| 922 | return protoreflect.Value{}, out, errUnknown |
| 923 | } |
| 924 | var v uint64 |
| 925 | var n int |
| 926 | if len(b) >= 1 && b[0] < 0x80 { |
| 927 | v = uint64(b[0]) |
| 928 | n = 1 |
| 929 | } else if len(b) >= 2 && b[1] < 128 { |
| 930 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 931 | n = 2 |
| 932 | } else { |
| 933 | v, n = protowire.ConsumeVarint(b) |
| 934 | } |
| 935 | if n < 0 { |
| 936 | return protoreflect.Value{}, out, errDecode |
| 937 | } |
| 938 | list.Append(protoreflect.ValueOfInt32(int32(v))) |
| 939 | out.n = n |
| 940 | return listv, out, nil |
| 941 | } |
| 942 | |
| 943 | var coderInt32SliceValue = valueCoderFuncs{ |
| 944 | size: sizeInt32SliceValue, |
| 945 | marshal: appendInt32SliceValue, |
| 946 | unmarshal: consumeInt32SliceValue, |
| 947 | merge: mergeListValue, |
| 948 | } |
| 949 | |
| 950 | // sizeInt32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Int32. |
| 951 | func sizeInt32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 952 | list := listv.List() |
| 953 | llen := list.Len() |
| 954 | if llen == 0 { |
| 955 | return 0 |
| 956 | } |
| 957 | n := 0 |
| 958 | for i, llen := 0, llen; i < llen; i++ { |
| 959 | v := list.Get(i) |
| 960 | n += protowire.SizeVarint(uint64(int32(v.Int()))) |
| 961 | } |
| 962 | return tagsize + protowire.SizeBytes(n) |
| 963 | } |
| 964 | |
| 965 | // appendInt32PackedSliceValue encodes a []int32 value as a packed repeated Int32. |
| 966 | func appendInt32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 967 | list := listv.List() |
| 968 | llen := list.Len() |
| 969 | if llen == 0 { |
| 970 | return b, nil |
| 971 | } |
| 972 | b = protowire.AppendVarint(b, wiretag) |
| 973 | n := 0 |
| 974 | for i := 0; i < llen; i++ { |
| 975 | v := list.Get(i) |
| 976 | n += protowire.SizeVarint(uint64(int32(v.Int()))) |
| 977 | } |
| 978 | b = protowire.AppendVarint(b, uint64(n)) |
| 979 | for i := 0; i < llen; i++ { |
| 980 | v := list.Get(i) |
| 981 | b = protowire.AppendVarint(b, uint64(int32(v.Int()))) |
| 982 | } |
| 983 | return b, nil |
| 984 | } |
| 985 | |
| 986 | var coderInt32PackedSliceValue = valueCoderFuncs{ |
| 987 | size: sizeInt32PackedSliceValue, |
| 988 | marshal: appendInt32PackedSliceValue, |
| 989 | unmarshal: consumeInt32SliceValue, |
| 990 | merge: mergeListValue, |
| 991 | } |
| 992 | |
| 993 | // sizeSint32 returns the size of wire encoding a int32 pointer as a Sint32. |
| 994 | func sizeSint32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 995 | v := *p.Int32() |
| 996 | return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v))) |
| 997 | } |
| 998 | |
| 999 | // appendSint32 wire encodes a int32 pointer as a Sint32. |
| 1000 | func appendSint32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1001 | v := *p.Int32() |
| 1002 | b = protowire.AppendVarint(b, f.wiretag) |
| 1003 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v))) |
| 1004 | return b, nil |
| 1005 | } |
| 1006 | |
| 1007 | // consumeSint32 wire decodes a int32 pointer as a Sint32. |
| 1008 | func consumeSint32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 1009 | if wtyp != protowire.VarintType { |
| 1010 | return out, errUnknown |
| 1011 | } |
| 1012 | var v uint64 |
| 1013 | var n int |
| 1014 | if len(b) >= 1 && b[0] < 0x80 { |
| 1015 | v = uint64(b[0]) |
| 1016 | n = 1 |
| 1017 | } else if len(b) >= 2 && b[1] < 128 { |
| 1018 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1019 | n = 2 |
| 1020 | } else { |
| 1021 | v, n = protowire.ConsumeVarint(b) |
| 1022 | } |
| 1023 | if n < 0 { |
| 1024 | return out, errDecode |
| 1025 | } |
| 1026 | *p.Int32() = int32(protowire.DecodeZigZag(v & math.MaxUint32)) |
| 1027 | out.n = n |
| 1028 | return out, nil |
| 1029 | } |
| 1030 | |
| 1031 | var coderSint32 = pointerCoderFuncs{ |
| 1032 | size: sizeSint32, |
| 1033 | marshal: appendSint32, |
| 1034 | unmarshal: consumeSint32, |
| 1035 | merge: mergeInt32, |
| 1036 | } |
| 1037 | |
| 1038 | // sizeSint32NoZero returns the size of wire encoding a int32 pointer as a Sint32. |
| 1039 | // The zero value is not encoded. |
| 1040 | func sizeSint32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1041 | v := *p.Int32() |
| 1042 | if v == 0 { |
| 1043 | return 0 |
| 1044 | } |
| 1045 | return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v))) |
| 1046 | } |
| 1047 | |
| 1048 | // appendSint32NoZero wire encodes a int32 pointer as a Sint32. |
| 1049 | // The zero value is not encoded. |
| 1050 | func appendSint32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1051 | v := *p.Int32() |
| 1052 | if v == 0 { |
| 1053 | return b, nil |
| 1054 | } |
| 1055 | b = protowire.AppendVarint(b, f.wiretag) |
| 1056 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v))) |
| 1057 | return b, nil |
| 1058 | } |
| 1059 | |
| 1060 | var coderSint32NoZero = pointerCoderFuncs{ |
| 1061 | size: sizeSint32NoZero, |
| 1062 | marshal: appendSint32NoZero, |
| 1063 | unmarshal: consumeSint32, |
| 1064 | merge: mergeInt32NoZero, |
| 1065 | } |
| 1066 | |
| 1067 | // sizeSint32Ptr returns the size of wire encoding a *int32 pointer as a Sint32. |
| 1068 | // It panics if the pointer is nil. |
| 1069 | func sizeSint32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1070 | v := **p.Int32Ptr() |
| 1071 | return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v))) |
| 1072 | } |
| 1073 | |
| 1074 | // appendSint32Ptr wire encodes a *int32 pointer as a Sint32. |
| 1075 | // It panics if the pointer is nil. |
| 1076 | func appendSint32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1077 | v := **p.Int32Ptr() |
| 1078 | b = protowire.AppendVarint(b, f.wiretag) |
| 1079 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v))) |
| 1080 | return b, nil |
| 1081 | } |
| 1082 | |
| 1083 | // consumeSint32Ptr wire decodes a *int32 pointer as a Sint32. |
| 1084 | func consumeSint32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 1085 | if wtyp != protowire.VarintType { |
| 1086 | return out, errUnknown |
| 1087 | } |
| 1088 | var v uint64 |
| 1089 | var n int |
| 1090 | if len(b) >= 1 && b[0] < 0x80 { |
| 1091 | v = uint64(b[0]) |
| 1092 | n = 1 |
| 1093 | } else if len(b) >= 2 && b[1] < 128 { |
| 1094 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1095 | n = 2 |
| 1096 | } else { |
| 1097 | v, n = protowire.ConsumeVarint(b) |
| 1098 | } |
| 1099 | if n < 0 { |
| 1100 | return out, errDecode |
| 1101 | } |
| 1102 | vp := p.Int32Ptr() |
| 1103 | if *vp == nil { |
| 1104 | *vp = new(int32) |
| 1105 | } |
| 1106 | **vp = int32(protowire.DecodeZigZag(v & math.MaxUint32)) |
| 1107 | out.n = n |
| 1108 | return out, nil |
| 1109 | } |
| 1110 | |
| 1111 | var coderSint32Ptr = pointerCoderFuncs{ |
| 1112 | size: sizeSint32Ptr, |
| 1113 | marshal: appendSint32Ptr, |
| 1114 | unmarshal: consumeSint32Ptr, |
| 1115 | merge: mergeInt32Ptr, |
| 1116 | } |
| 1117 | |
| 1118 | // sizeSint32Slice returns the size of wire encoding a []int32 pointer as a repeated Sint32. |
| 1119 | func sizeSint32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1120 | s := *p.Int32Slice() |
| 1121 | for _, v := range s { |
| 1122 | size += f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(v))) |
| 1123 | } |
| 1124 | return size |
| 1125 | } |
| 1126 | |
| 1127 | // appendSint32Slice encodes a []int32 pointer as a repeated Sint32. |
| 1128 | func appendSint32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1129 | s := *p.Int32Slice() |
| 1130 | for _, v := range s { |
| 1131 | b = protowire.AppendVarint(b, f.wiretag) |
| 1132 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v))) |
| 1133 | } |
| 1134 | return b, nil |
| 1135 | } |
| 1136 | |
| 1137 | // consumeSint32Slice wire decodes a []int32 pointer as a repeated Sint32. |
| 1138 | func consumeSint32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 1139 | sp := p.Int32Slice() |
| 1140 | if wtyp == protowire.BytesType { |
| 1141 | s := *sp |
| 1142 | b, n := protowire.ConsumeBytes(b) |
| 1143 | if n < 0 { |
| 1144 | return out, errDecode |
| 1145 | } |
| 1146 | for len(b) > 0 { |
| 1147 | var v uint64 |
| 1148 | var n int |
| 1149 | if len(b) >= 1 && b[0] < 0x80 { |
| 1150 | v = uint64(b[0]) |
| 1151 | n = 1 |
| 1152 | } else if len(b) >= 2 && b[1] < 128 { |
| 1153 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1154 | n = 2 |
| 1155 | } else { |
| 1156 | v, n = protowire.ConsumeVarint(b) |
| 1157 | } |
| 1158 | if n < 0 { |
| 1159 | return out, errDecode |
| 1160 | } |
| 1161 | s = append(s, int32(protowire.DecodeZigZag(v&math.MaxUint32))) |
| 1162 | b = b[n:] |
| 1163 | } |
| 1164 | *sp = s |
| 1165 | out.n = n |
| 1166 | return out, nil |
| 1167 | } |
| 1168 | if wtyp != protowire.VarintType { |
| 1169 | return out, errUnknown |
| 1170 | } |
| 1171 | var v uint64 |
| 1172 | var n int |
| 1173 | if len(b) >= 1 && b[0] < 0x80 { |
| 1174 | v = uint64(b[0]) |
| 1175 | n = 1 |
| 1176 | } else if len(b) >= 2 && b[1] < 128 { |
| 1177 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1178 | n = 2 |
| 1179 | } else { |
| 1180 | v, n = protowire.ConsumeVarint(b) |
| 1181 | } |
| 1182 | if n < 0 { |
| 1183 | return out, errDecode |
| 1184 | } |
| 1185 | *sp = append(*sp, int32(protowire.DecodeZigZag(v&math.MaxUint32))) |
| 1186 | out.n = n |
| 1187 | return out, nil |
| 1188 | } |
| 1189 | |
| 1190 | var coderSint32Slice = pointerCoderFuncs{ |
| 1191 | size: sizeSint32Slice, |
| 1192 | marshal: appendSint32Slice, |
| 1193 | unmarshal: consumeSint32Slice, |
| 1194 | merge: mergeInt32Slice, |
| 1195 | } |
| 1196 | |
| 1197 | // sizeSint32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sint32. |
| 1198 | func sizeSint32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1199 | s := *p.Int32Slice() |
| 1200 | if len(s) == 0 { |
| 1201 | return 0 |
| 1202 | } |
| 1203 | n := 0 |
| 1204 | for _, v := range s { |
| 1205 | n += protowire.SizeVarint(protowire.EncodeZigZag(int64(v))) |
| 1206 | } |
| 1207 | return f.tagsize + protowire.SizeBytes(n) |
| 1208 | } |
| 1209 | |
| 1210 | // appendSint32PackedSlice encodes a []int32 pointer as a packed repeated Sint32. |
| 1211 | func appendSint32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1212 | s := *p.Int32Slice() |
| 1213 | if len(s) == 0 { |
| 1214 | return b, nil |
| 1215 | } |
| 1216 | b = protowire.AppendVarint(b, f.wiretag) |
| 1217 | n := 0 |
| 1218 | for _, v := range s { |
| 1219 | n += protowire.SizeVarint(protowire.EncodeZigZag(int64(v))) |
| 1220 | } |
| 1221 | b = protowire.AppendVarint(b, uint64(n)) |
| 1222 | for _, v := range s { |
| 1223 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(v))) |
| 1224 | } |
| 1225 | return b, nil |
| 1226 | } |
| 1227 | |
| 1228 | var coderSint32PackedSlice = pointerCoderFuncs{ |
| 1229 | size: sizeSint32PackedSlice, |
| 1230 | marshal: appendSint32PackedSlice, |
| 1231 | unmarshal: consumeSint32Slice, |
| 1232 | merge: mergeInt32Slice, |
| 1233 | } |
| 1234 | |
| 1235 | // sizeSint32Value returns the size of wire encoding a int32 value as a Sint32. |
| 1236 | func sizeSint32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 1237 | return tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int())))) |
| 1238 | } |
| 1239 | |
| 1240 | // appendSint32Value encodes a int32 value as a Sint32. |
| 1241 | func appendSint32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 1242 | b = protowire.AppendVarint(b, wiretag) |
| 1243 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(int32(v.Int())))) |
| 1244 | return b, nil |
| 1245 | } |
| 1246 | |
| 1247 | // consumeSint32Value decodes a int32 value as a Sint32. |
| 1248 | func consumeSint32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 1249 | if wtyp != protowire.VarintType { |
| 1250 | return protoreflect.Value{}, out, errUnknown |
| 1251 | } |
| 1252 | var v uint64 |
| 1253 | var n int |
| 1254 | if len(b) >= 1 && b[0] < 0x80 { |
| 1255 | v = uint64(b[0]) |
| 1256 | n = 1 |
| 1257 | } else if len(b) >= 2 && b[1] < 128 { |
| 1258 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1259 | n = 2 |
| 1260 | } else { |
| 1261 | v, n = protowire.ConsumeVarint(b) |
| 1262 | } |
| 1263 | if n < 0 { |
| 1264 | return protoreflect.Value{}, out, errDecode |
| 1265 | } |
| 1266 | out.n = n |
| 1267 | return protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))), out, nil |
| 1268 | } |
| 1269 | |
| 1270 | var coderSint32Value = valueCoderFuncs{ |
| 1271 | size: sizeSint32Value, |
| 1272 | marshal: appendSint32Value, |
| 1273 | unmarshal: consumeSint32Value, |
| 1274 | merge: mergeScalarValue, |
| 1275 | } |
| 1276 | |
| 1277 | // sizeSint32SliceValue returns the size of wire encoding a []int32 value as a repeated Sint32. |
| 1278 | func sizeSint32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 1279 | list := listv.List() |
| 1280 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1281 | v := list.Get(i) |
| 1282 | size += tagsize + protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int())))) |
| 1283 | } |
| 1284 | return size |
| 1285 | } |
| 1286 | |
| 1287 | // appendSint32SliceValue encodes a []int32 value as a repeated Sint32. |
| 1288 | func appendSint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 1289 | list := listv.List() |
| 1290 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1291 | v := list.Get(i) |
| 1292 | b = protowire.AppendVarint(b, wiretag) |
| 1293 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(int32(v.Int())))) |
| 1294 | } |
| 1295 | return b, nil |
| 1296 | } |
| 1297 | |
| 1298 | // consumeSint32SliceValue wire decodes a []int32 value as a repeated Sint32. |
| 1299 | func consumeSint32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 1300 | list := listv.List() |
| 1301 | if wtyp == protowire.BytesType { |
| 1302 | b, n := protowire.ConsumeBytes(b) |
| 1303 | if n < 0 { |
| 1304 | return protoreflect.Value{}, out, errDecode |
| 1305 | } |
| 1306 | for len(b) > 0 { |
| 1307 | var v uint64 |
| 1308 | var n int |
| 1309 | if len(b) >= 1 && b[0] < 0x80 { |
| 1310 | v = uint64(b[0]) |
| 1311 | n = 1 |
| 1312 | } else if len(b) >= 2 && b[1] < 128 { |
| 1313 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1314 | n = 2 |
| 1315 | } else { |
| 1316 | v, n = protowire.ConsumeVarint(b) |
| 1317 | } |
| 1318 | if n < 0 { |
| 1319 | return protoreflect.Value{}, out, errDecode |
| 1320 | } |
| 1321 | list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32)))) |
| 1322 | b = b[n:] |
| 1323 | } |
| 1324 | out.n = n |
| 1325 | return listv, out, nil |
| 1326 | } |
| 1327 | if wtyp != protowire.VarintType { |
| 1328 | return protoreflect.Value{}, out, errUnknown |
| 1329 | } |
| 1330 | var v uint64 |
| 1331 | var n int |
| 1332 | if len(b) >= 1 && b[0] < 0x80 { |
| 1333 | v = uint64(b[0]) |
| 1334 | n = 1 |
| 1335 | } else if len(b) >= 2 && b[1] < 128 { |
| 1336 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1337 | n = 2 |
| 1338 | } else { |
| 1339 | v, n = protowire.ConsumeVarint(b) |
| 1340 | } |
| 1341 | if n < 0 { |
| 1342 | return protoreflect.Value{}, out, errDecode |
| 1343 | } |
| 1344 | list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32)))) |
| 1345 | out.n = n |
| 1346 | return listv, out, nil |
| 1347 | } |
| 1348 | |
| 1349 | var coderSint32SliceValue = valueCoderFuncs{ |
| 1350 | size: sizeSint32SliceValue, |
| 1351 | marshal: appendSint32SliceValue, |
| 1352 | unmarshal: consumeSint32SliceValue, |
| 1353 | merge: mergeListValue, |
| 1354 | } |
| 1355 | |
| 1356 | // sizeSint32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sint32. |
| 1357 | func sizeSint32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 1358 | list := listv.List() |
| 1359 | llen := list.Len() |
| 1360 | if llen == 0 { |
| 1361 | return 0 |
| 1362 | } |
| 1363 | n := 0 |
| 1364 | for i, llen := 0, llen; i < llen; i++ { |
| 1365 | v := list.Get(i) |
| 1366 | n += protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int())))) |
| 1367 | } |
| 1368 | return tagsize + protowire.SizeBytes(n) |
| 1369 | } |
| 1370 | |
| 1371 | // appendSint32PackedSliceValue encodes a []int32 value as a packed repeated Sint32. |
| 1372 | func appendSint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 1373 | list := listv.List() |
| 1374 | llen := list.Len() |
| 1375 | if llen == 0 { |
| 1376 | return b, nil |
| 1377 | } |
| 1378 | b = protowire.AppendVarint(b, wiretag) |
| 1379 | n := 0 |
| 1380 | for i := 0; i < llen; i++ { |
| 1381 | v := list.Get(i) |
| 1382 | n += protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int())))) |
| 1383 | } |
| 1384 | b = protowire.AppendVarint(b, uint64(n)) |
| 1385 | for i := 0; i < llen; i++ { |
| 1386 | v := list.Get(i) |
| 1387 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(int64(int32(v.Int())))) |
| 1388 | } |
| 1389 | return b, nil |
| 1390 | } |
| 1391 | |
| 1392 | var coderSint32PackedSliceValue = valueCoderFuncs{ |
| 1393 | size: sizeSint32PackedSliceValue, |
| 1394 | marshal: appendSint32PackedSliceValue, |
| 1395 | unmarshal: consumeSint32SliceValue, |
| 1396 | merge: mergeListValue, |
| 1397 | } |
| 1398 | |
| 1399 | // sizeUint32 returns the size of wire encoding a uint32 pointer as a Uint32. |
| 1400 | func sizeUint32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1401 | v := *p.Uint32() |
| 1402 | return f.tagsize + protowire.SizeVarint(uint64(v)) |
| 1403 | } |
| 1404 | |
| 1405 | // appendUint32 wire encodes a uint32 pointer as a Uint32. |
| 1406 | func appendUint32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1407 | v := *p.Uint32() |
| 1408 | b = protowire.AppendVarint(b, f.wiretag) |
| 1409 | b = protowire.AppendVarint(b, uint64(v)) |
| 1410 | return b, nil |
| 1411 | } |
| 1412 | |
| 1413 | // consumeUint32 wire decodes a uint32 pointer as a Uint32. |
| 1414 | func consumeUint32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 1415 | if wtyp != protowire.VarintType { |
| 1416 | return out, errUnknown |
| 1417 | } |
| 1418 | var v uint64 |
| 1419 | var n int |
| 1420 | if len(b) >= 1 && b[0] < 0x80 { |
| 1421 | v = uint64(b[0]) |
| 1422 | n = 1 |
| 1423 | } else if len(b) >= 2 && b[1] < 128 { |
| 1424 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1425 | n = 2 |
| 1426 | } else { |
| 1427 | v, n = protowire.ConsumeVarint(b) |
| 1428 | } |
| 1429 | if n < 0 { |
| 1430 | return out, errDecode |
| 1431 | } |
| 1432 | *p.Uint32() = uint32(v) |
| 1433 | out.n = n |
| 1434 | return out, nil |
| 1435 | } |
| 1436 | |
| 1437 | var coderUint32 = pointerCoderFuncs{ |
| 1438 | size: sizeUint32, |
| 1439 | marshal: appendUint32, |
| 1440 | unmarshal: consumeUint32, |
| 1441 | merge: mergeUint32, |
| 1442 | } |
| 1443 | |
| 1444 | // sizeUint32NoZero returns the size of wire encoding a uint32 pointer as a Uint32. |
| 1445 | // The zero value is not encoded. |
| 1446 | func sizeUint32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1447 | v := *p.Uint32() |
| 1448 | if v == 0 { |
| 1449 | return 0 |
| 1450 | } |
| 1451 | return f.tagsize + protowire.SizeVarint(uint64(v)) |
| 1452 | } |
| 1453 | |
| 1454 | // appendUint32NoZero wire encodes a uint32 pointer as a Uint32. |
| 1455 | // The zero value is not encoded. |
| 1456 | func appendUint32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1457 | v := *p.Uint32() |
| 1458 | if v == 0 { |
| 1459 | return b, nil |
| 1460 | } |
| 1461 | b = protowire.AppendVarint(b, f.wiretag) |
| 1462 | b = protowire.AppendVarint(b, uint64(v)) |
| 1463 | return b, nil |
| 1464 | } |
| 1465 | |
| 1466 | var coderUint32NoZero = pointerCoderFuncs{ |
| 1467 | size: sizeUint32NoZero, |
| 1468 | marshal: appendUint32NoZero, |
| 1469 | unmarshal: consumeUint32, |
| 1470 | merge: mergeUint32NoZero, |
| 1471 | } |
| 1472 | |
| 1473 | // sizeUint32Ptr returns the size of wire encoding a *uint32 pointer as a Uint32. |
| 1474 | // It panics if the pointer is nil. |
| 1475 | func sizeUint32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1476 | v := **p.Uint32Ptr() |
| 1477 | return f.tagsize + protowire.SizeVarint(uint64(v)) |
| 1478 | } |
| 1479 | |
| 1480 | // appendUint32Ptr wire encodes a *uint32 pointer as a Uint32. |
| 1481 | // It panics if the pointer is nil. |
| 1482 | func appendUint32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1483 | v := **p.Uint32Ptr() |
| 1484 | b = protowire.AppendVarint(b, f.wiretag) |
| 1485 | b = protowire.AppendVarint(b, uint64(v)) |
| 1486 | return b, nil |
| 1487 | } |
| 1488 | |
| 1489 | // consumeUint32Ptr wire decodes a *uint32 pointer as a Uint32. |
| 1490 | func consumeUint32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 1491 | if wtyp != protowire.VarintType { |
| 1492 | return out, errUnknown |
| 1493 | } |
| 1494 | var v uint64 |
| 1495 | var n int |
| 1496 | if len(b) >= 1 && b[0] < 0x80 { |
| 1497 | v = uint64(b[0]) |
| 1498 | n = 1 |
| 1499 | } else if len(b) >= 2 && b[1] < 128 { |
| 1500 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1501 | n = 2 |
| 1502 | } else { |
| 1503 | v, n = protowire.ConsumeVarint(b) |
| 1504 | } |
| 1505 | if n < 0 { |
| 1506 | return out, errDecode |
| 1507 | } |
| 1508 | vp := p.Uint32Ptr() |
| 1509 | if *vp == nil { |
| 1510 | *vp = new(uint32) |
| 1511 | } |
| 1512 | **vp = uint32(v) |
| 1513 | out.n = n |
| 1514 | return out, nil |
| 1515 | } |
| 1516 | |
| 1517 | var coderUint32Ptr = pointerCoderFuncs{ |
| 1518 | size: sizeUint32Ptr, |
| 1519 | marshal: appendUint32Ptr, |
| 1520 | unmarshal: consumeUint32Ptr, |
| 1521 | merge: mergeUint32Ptr, |
| 1522 | } |
| 1523 | |
| 1524 | // sizeUint32Slice returns the size of wire encoding a []uint32 pointer as a repeated Uint32. |
| 1525 | func sizeUint32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1526 | s := *p.Uint32Slice() |
| 1527 | for _, v := range s { |
| 1528 | size += f.tagsize + protowire.SizeVarint(uint64(v)) |
| 1529 | } |
| 1530 | return size |
| 1531 | } |
| 1532 | |
| 1533 | // appendUint32Slice encodes a []uint32 pointer as a repeated Uint32. |
| 1534 | func appendUint32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1535 | s := *p.Uint32Slice() |
| 1536 | for _, v := range s { |
| 1537 | b = protowire.AppendVarint(b, f.wiretag) |
| 1538 | b = protowire.AppendVarint(b, uint64(v)) |
| 1539 | } |
| 1540 | return b, nil |
| 1541 | } |
| 1542 | |
| 1543 | // consumeUint32Slice wire decodes a []uint32 pointer as a repeated Uint32. |
| 1544 | func consumeUint32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 1545 | sp := p.Uint32Slice() |
| 1546 | if wtyp == protowire.BytesType { |
| 1547 | s := *sp |
| 1548 | b, n := protowire.ConsumeBytes(b) |
| 1549 | if n < 0 { |
| 1550 | return out, errDecode |
| 1551 | } |
| 1552 | for len(b) > 0 { |
| 1553 | var v uint64 |
| 1554 | var n int |
| 1555 | if len(b) >= 1 && b[0] < 0x80 { |
| 1556 | v = uint64(b[0]) |
| 1557 | n = 1 |
| 1558 | } else if len(b) >= 2 && b[1] < 128 { |
| 1559 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1560 | n = 2 |
| 1561 | } else { |
| 1562 | v, n = protowire.ConsumeVarint(b) |
| 1563 | } |
| 1564 | if n < 0 { |
| 1565 | return out, errDecode |
| 1566 | } |
| 1567 | s = append(s, uint32(v)) |
| 1568 | b = b[n:] |
| 1569 | } |
| 1570 | *sp = s |
| 1571 | out.n = n |
| 1572 | return out, nil |
| 1573 | } |
| 1574 | if wtyp != protowire.VarintType { |
| 1575 | return out, errUnknown |
| 1576 | } |
| 1577 | var v uint64 |
| 1578 | var n int |
| 1579 | if len(b) >= 1 && b[0] < 0x80 { |
| 1580 | v = uint64(b[0]) |
| 1581 | n = 1 |
| 1582 | } else if len(b) >= 2 && b[1] < 128 { |
| 1583 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1584 | n = 2 |
| 1585 | } else { |
| 1586 | v, n = protowire.ConsumeVarint(b) |
| 1587 | } |
| 1588 | if n < 0 { |
| 1589 | return out, errDecode |
| 1590 | } |
| 1591 | *sp = append(*sp, uint32(v)) |
| 1592 | out.n = n |
| 1593 | return out, nil |
| 1594 | } |
| 1595 | |
| 1596 | var coderUint32Slice = pointerCoderFuncs{ |
| 1597 | size: sizeUint32Slice, |
| 1598 | marshal: appendUint32Slice, |
| 1599 | unmarshal: consumeUint32Slice, |
| 1600 | merge: mergeUint32Slice, |
| 1601 | } |
| 1602 | |
| 1603 | // sizeUint32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Uint32. |
| 1604 | func sizeUint32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1605 | s := *p.Uint32Slice() |
| 1606 | if len(s) == 0 { |
| 1607 | return 0 |
| 1608 | } |
| 1609 | n := 0 |
| 1610 | for _, v := range s { |
| 1611 | n += protowire.SizeVarint(uint64(v)) |
| 1612 | } |
| 1613 | return f.tagsize + protowire.SizeBytes(n) |
| 1614 | } |
| 1615 | |
| 1616 | // appendUint32PackedSlice encodes a []uint32 pointer as a packed repeated Uint32. |
| 1617 | func appendUint32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1618 | s := *p.Uint32Slice() |
| 1619 | if len(s) == 0 { |
| 1620 | return b, nil |
| 1621 | } |
| 1622 | b = protowire.AppendVarint(b, f.wiretag) |
| 1623 | n := 0 |
| 1624 | for _, v := range s { |
| 1625 | n += protowire.SizeVarint(uint64(v)) |
| 1626 | } |
| 1627 | b = protowire.AppendVarint(b, uint64(n)) |
| 1628 | for _, v := range s { |
| 1629 | b = protowire.AppendVarint(b, uint64(v)) |
| 1630 | } |
| 1631 | return b, nil |
| 1632 | } |
| 1633 | |
| 1634 | var coderUint32PackedSlice = pointerCoderFuncs{ |
| 1635 | size: sizeUint32PackedSlice, |
| 1636 | marshal: appendUint32PackedSlice, |
| 1637 | unmarshal: consumeUint32Slice, |
| 1638 | merge: mergeUint32Slice, |
| 1639 | } |
| 1640 | |
| 1641 | // sizeUint32Value returns the size of wire encoding a uint32 value as a Uint32. |
| 1642 | func sizeUint32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 1643 | return tagsize + protowire.SizeVarint(uint64(uint32(v.Uint()))) |
| 1644 | } |
| 1645 | |
| 1646 | // appendUint32Value encodes a uint32 value as a Uint32. |
| 1647 | func appendUint32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 1648 | b = protowire.AppendVarint(b, wiretag) |
| 1649 | b = protowire.AppendVarint(b, uint64(uint32(v.Uint()))) |
| 1650 | return b, nil |
| 1651 | } |
| 1652 | |
| 1653 | // consumeUint32Value decodes a uint32 value as a Uint32. |
| 1654 | func consumeUint32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 1655 | if wtyp != protowire.VarintType { |
| 1656 | return protoreflect.Value{}, out, errUnknown |
| 1657 | } |
| 1658 | var v uint64 |
| 1659 | var n int |
| 1660 | if len(b) >= 1 && b[0] < 0x80 { |
| 1661 | v = uint64(b[0]) |
| 1662 | n = 1 |
| 1663 | } else if len(b) >= 2 && b[1] < 128 { |
| 1664 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1665 | n = 2 |
| 1666 | } else { |
| 1667 | v, n = protowire.ConsumeVarint(b) |
| 1668 | } |
| 1669 | if n < 0 { |
| 1670 | return protoreflect.Value{}, out, errDecode |
| 1671 | } |
| 1672 | out.n = n |
| 1673 | return protoreflect.ValueOfUint32(uint32(v)), out, nil |
| 1674 | } |
| 1675 | |
| 1676 | var coderUint32Value = valueCoderFuncs{ |
| 1677 | size: sizeUint32Value, |
| 1678 | marshal: appendUint32Value, |
| 1679 | unmarshal: consumeUint32Value, |
| 1680 | merge: mergeScalarValue, |
| 1681 | } |
| 1682 | |
| 1683 | // sizeUint32SliceValue returns the size of wire encoding a []uint32 value as a repeated Uint32. |
| 1684 | func sizeUint32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 1685 | list := listv.List() |
| 1686 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1687 | v := list.Get(i) |
| 1688 | size += tagsize + protowire.SizeVarint(uint64(uint32(v.Uint()))) |
| 1689 | } |
| 1690 | return size |
| 1691 | } |
| 1692 | |
| 1693 | // appendUint32SliceValue encodes a []uint32 value as a repeated Uint32. |
| 1694 | func appendUint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 1695 | list := listv.List() |
| 1696 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1697 | v := list.Get(i) |
| 1698 | b = protowire.AppendVarint(b, wiretag) |
| 1699 | b = protowire.AppendVarint(b, uint64(uint32(v.Uint()))) |
| 1700 | } |
| 1701 | return b, nil |
| 1702 | } |
| 1703 | |
| 1704 | // consumeUint32SliceValue wire decodes a []uint32 value as a repeated Uint32. |
| 1705 | func consumeUint32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 1706 | list := listv.List() |
| 1707 | if wtyp == protowire.BytesType { |
| 1708 | b, n := protowire.ConsumeBytes(b) |
| 1709 | if n < 0 { |
| 1710 | return protoreflect.Value{}, out, errDecode |
| 1711 | } |
| 1712 | for len(b) > 0 { |
| 1713 | var v uint64 |
| 1714 | var n int |
| 1715 | if len(b) >= 1 && b[0] < 0x80 { |
| 1716 | v = uint64(b[0]) |
| 1717 | n = 1 |
| 1718 | } else if len(b) >= 2 && b[1] < 128 { |
| 1719 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1720 | n = 2 |
| 1721 | } else { |
| 1722 | v, n = protowire.ConsumeVarint(b) |
| 1723 | } |
| 1724 | if n < 0 { |
| 1725 | return protoreflect.Value{}, out, errDecode |
| 1726 | } |
| 1727 | list.Append(protoreflect.ValueOfUint32(uint32(v))) |
| 1728 | b = b[n:] |
| 1729 | } |
| 1730 | out.n = n |
| 1731 | return listv, out, nil |
| 1732 | } |
| 1733 | if wtyp != protowire.VarintType { |
| 1734 | return protoreflect.Value{}, out, errUnknown |
| 1735 | } |
| 1736 | var v uint64 |
| 1737 | var n int |
| 1738 | if len(b) >= 1 && b[0] < 0x80 { |
| 1739 | v = uint64(b[0]) |
| 1740 | n = 1 |
| 1741 | } else if len(b) >= 2 && b[1] < 128 { |
| 1742 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1743 | n = 2 |
| 1744 | } else { |
| 1745 | v, n = protowire.ConsumeVarint(b) |
| 1746 | } |
| 1747 | if n < 0 { |
| 1748 | return protoreflect.Value{}, out, errDecode |
| 1749 | } |
| 1750 | list.Append(protoreflect.ValueOfUint32(uint32(v))) |
| 1751 | out.n = n |
| 1752 | return listv, out, nil |
| 1753 | } |
| 1754 | |
| 1755 | var coderUint32SliceValue = valueCoderFuncs{ |
| 1756 | size: sizeUint32SliceValue, |
| 1757 | marshal: appendUint32SliceValue, |
| 1758 | unmarshal: consumeUint32SliceValue, |
| 1759 | merge: mergeListValue, |
| 1760 | } |
| 1761 | |
| 1762 | // sizeUint32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Uint32. |
| 1763 | func sizeUint32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 1764 | list := listv.List() |
| 1765 | llen := list.Len() |
| 1766 | if llen == 0 { |
| 1767 | return 0 |
| 1768 | } |
| 1769 | n := 0 |
| 1770 | for i, llen := 0, llen; i < llen; i++ { |
| 1771 | v := list.Get(i) |
| 1772 | n += protowire.SizeVarint(uint64(uint32(v.Uint()))) |
| 1773 | } |
| 1774 | return tagsize + protowire.SizeBytes(n) |
| 1775 | } |
| 1776 | |
| 1777 | // appendUint32PackedSliceValue encodes a []uint32 value as a packed repeated Uint32. |
| 1778 | func appendUint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 1779 | list := listv.List() |
| 1780 | llen := list.Len() |
| 1781 | if llen == 0 { |
| 1782 | return b, nil |
| 1783 | } |
| 1784 | b = protowire.AppendVarint(b, wiretag) |
| 1785 | n := 0 |
| 1786 | for i := 0; i < llen; i++ { |
| 1787 | v := list.Get(i) |
| 1788 | n += protowire.SizeVarint(uint64(uint32(v.Uint()))) |
| 1789 | } |
| 1790 | b = protowire.AppendVarint(b, uint64(n)) |
| 1791 | for i := 0; i < llen; i++ { |
| 1792 | v := list.Get(i) |
| 1793 | b = protowire.AppendVarint(b, uint64(uint32(v.Uint()))) |
| 1794 | } |
| 1795 | return b, nil |
| 1796 | } |
| 1797 | |
| 1798 | var coderUint32PackedSliceValue = valueCoderFuncs{ |
| 1799 | size: sizeUint32PackedSliceValue, |
| 1800 | marshal: appendUint32PackedSliceValue, |
| 1801 | unmarshal: consumeUint32SliceValue, |
| 1802 | merge: mergeListValue, |
| 1803 | } |
| 1804 | |
| 1805 | // sizeInt64 returns the size of wire encoding a int64 pointer as a Int64. |
| 1806 | func sizeInt64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1807 | v := *p.Int64() |
| 1808 | return f.tagsize + protowire.SizeVarint(uint64(v)) |
| 1809 | } |
| 1810 | |
| 1811 | // appendInt64 wire encodes a int64 pointer as a Int64. |
| 1812 | func appendInt64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1813 | v := *p.Int64() |
| 1814 | b = protowire.AppendVarint(b, f.wiretag) |
| 1815 | b = protowire.AppendVarint(b, uint64(v)) |
| 1816 | return b, nil |
| 1817 | } |
| 1818 | |
| 1819 | // consumeInt64 wire decodes a int64 pointer as a Int64. |
| 1820 | func consumeInt64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 1821 | if wtyp != protowire.VarintType { |
| 1822 | return out, errUnknown |
| 1823 | } |
| 1824 | var v uint64 |
| 1825 | var n int |
| 1826 | if len(b) >= 1 && b[0] < 0x80 { |
| 1827 | v = uint64(b[0]) |
| 1828 | n = 1 |
| 1829 | } else if len(b) >= 2 && b[1] < 128 { |
| 1830 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1831 | n = 2 |
| 1832 | } else { |
| 1833 | v, n = protowire.ConsumeVarint(b) |
| 1834 | } |
| 1835 | if n < 0 { |
| 1836 | return out, errDecode |
| 1837 | } |
| 1838 | *p.Int64() = int64(v) |
| 1839 | out.n = n |
| 1840 | return out, nil |
| 1841 | } |
| 1842 | |
| 1843 | var coderInt64 = pointerCoderFuncs{ |
| 1844 | size: sizeInt64, |
| 1845 | marshal: appendInt64, |
| 1846 | unmarshal: consumeInt64, |
| 1847 | merge: mergeInt64, |
| 1848 | } |
| 1849 | |
| 1850 | // sizeInt64NoZero returns the size of wire encoding a int64 pointer as a Int64. |
| 1851 | // The zero value is not encoded. |
| 1852 | func sizeInt64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1853 | v := *p.Int64() |
| 1854 | if v == 0 { |
| 1855 | return 0 |
| 1856 | } |
| 1857 | return f.tagsize + protowire.SizeVarint(uint64(v)) |
| 1858 | } |
| 1859 | |
| 1860 | // appendInt64NoZero wire encodes a int64 pointer as a Int64. |
| 1861 | // The zero value is not encoded. |
| 1862 | func appendInt64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1863 | v := *p.Int64() |
| 1864 | if v == 0 { |
| 1865 | return b, nil |
| 1866 | } |
| 1867 | b = protowire.AppendVarint(b, f.wiretag) |
| 1868 | b = protowire.AppendVarint(b, uint64(v)) |
| 1869 | return b, nil |
| 1870 | } |
| 1871 | |
| 1872 | var coderInt64NoZero = pointerCoderFuncs{ |
| 1873 | size: sizeInt64NoZero, |
| 1874 | marshal: appendInt64NoZero, |
| 1875 | unmarshal: consumeInt64, |
| 1876 | merge: mergeInt64NoZero, |
| 1877 | } |
| 1878 | |
| 1879 | // sizeInt64Ptr returns the size of wire encoding a *int64 pointer as a Int64. |
| 1880 | // It panics if the pointer is nil. |
| 1881 | func sizeInt64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1882 | v := **p.Int64Ptr() |
| 1883 | return f.tagsize + protowire.SizeVarint(uint64(v)) |
| 1884 | } |
| 1885 | |
| 1886 | // appendInt64Ptr wire encodes a *int64 pointer as a Int64. |
| 1887 | // It panics if the pointer is nil. |
| 1888 | func appendInt64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1889 | v := **p.Int64Ptr() |
| 1890 | b = protowire.AppendVarint(b, f.wiretag) |
| 1891 | b = protowire.AppendVarint(b, uint64(v)) |
| 1892 | return b, nil |
| 1893 | } |
| 1894 | |
| 1895 | // consumeInt64Ptr wire decodes a *int64 pointer as a Int64. |
| 1896 | func consumeInt64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 1897 | if wtyp != protowire.VarintType { |
| 1898 | return out, errUnknown |
| 1899 | } |
| 1900 | var v uint64 |
| 1901 | var n int |
| 1902 | if len(b) >= 1 && b[0] < 0x80 { |
| 1903 | v = uint64(b[0]) |
| 1904 | n = 1 |
| 1905 | } else if len(b) >= 2 && b[1] < 128 { |
| 1906 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1907 | n = 2 |
| 1908 | } else { |
| 1909 | v, n = protowire.ConsumeVarint(b) |
| 1910 | } |
| 1911 | if n < 0 { |
| 1912 | return out, errDecode |
| 1913 | } |
| 1914 | vp := p.Int64Ptr() |
| 1915 | if *vp == nil { |
| 1916 | *vp = new(int64) |
| 1917 | } |
| 1918 | **vp = int64(v) |
| 1919 | out.n = n |
| 1920 | return out, nil |
| 1921 | } |
| 1922 | |
| 1923 | var coderInt64Ptr = pointerCoderFuncs{ |
| 1924 | size: sizeInt64Ptr, |
| 1925 | marshal: appendInt64Ptr, |
| 1926 | unmarshal: consumeInt64Ptr, |
| 1927 | merge: mergeInt64Ptr, |
| 1928 | } |
| 1929 | |
| 1930 | // sizeInt64Slice returns the size of wire encoding a []int64 pointer as a repeated Int64. |
| 1931 | func sizeInt64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 1932 | s := *p.Int64Slice() |
| 1933 | for _, v := range s { |
| 1934 | size += f.tagsize + protowire.SizeVarint(uint64(v)) |
| 1935 | } |
| 1936 | return size |
| 1937 | } |
| 1938 | |
| 1939 | // appendInt64Slice encodes a []int64 pointer as a repeated Int64. |
| 1940 | func appendInt64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 1941 | s := *p.Int64Slice() |
| 1942 | for _, v := range s { |
| 1943 | b = protowire.AppendVarint(b, f.wiretag) |
| 1944 | b = protowire.AppendVarint(b, uint64(v)) |
| 1945 | } |
| 1946 | return b, nil |
| 1947 | } |
| 1948 | |
| 1949 | // consumeInt64Slice wire decodes a []int64 pointer as a repeated Int64. |
| 1950 | func consumeInt64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 1951 | sp := p.Int64Slice() |
| 1952 | if wtyp == protowire.BytesType { |
| 1953 | s := *sp |
| 1954 | b, n := protowire.ConsumeBytes(b) |
| 1955 | if n < 0 { |
| 1956 | return out, errDecode |
| 1957 | } |
| 1958 | for len(b) > 0 { |
| 1959 | var v uint64 |
| 1960 | var n int |
| 1961 | if len(b) >= 1 && b[0] < 0x80 { |
| 1962 | v = uint64(b[0]) |
| 1963 | n = 1 |
| 1964 | } else if len(b) >= 2 && b[1] < 128 { |
| 1965 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1966 | n = 2 |
| 1967 | } else { |
| 1968 | v, n = protowire.ConsumeVarint(b) |
| 1969 | } |
| 1970 | if n < 0 { |
| 1971 | return out, errDecode |
| 1972 | } |
| 1973 | s = append(s, int64(v)) |
| 1974 | b = b[n:] |
| 1975 | } |
| 1976 | *sp = s |
| 1977 | out.n = n |
| 1978 | return out, nil |
| 1979 | } |
| 1980 | if wtyp != protowire.VarintType { |
| 1981 | return out, errUnknown |
| 1982 | } |
| 1983 | var v uint64 |
| 1984 | var n int |
| 1985 | if len(b) >= 1 && b[0] < 0x80 { |
| 1986 | v = uint64(b[0]) |
| 1987 | n = 1 |
| 1988 | } else if len(b) >= 2 && b[1] < 128 { |
| 1989 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 1990 | n = 2 |
| 1991 | } else { |
| 1992 | v, n = protowire.ConsumeVarint(b) |
| 1993 | } |
| 1994 | if n < 0 { |
| 1995 | return out, errDecode |
| 1996 | } |
| 1997 | *sp = append(*sp, int64(v)) |
| 1998 | out.n = n |
| 1999 | return out, nil |
| 2000 | } |
| 2001 | |
| 2002 | var coderInt64Slice = pointerCoderFuncs{ |
| 2003 | size: sizeInt64Slice, |
| 2004 | marshal: appendInt64Slice, |
| 2005 | unmarshal: consumeInt64Slice, |
| 2006 | merge: mergeInt64Slice, |
| 2007 | } |
| 2008 | |
| 2009 | // sizeInt64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Int64. |
| 2010 | func sizeInt64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 2011 | s := *p.Int64Slice() |
| 2012 | if len(s) == 0 { |
| 2013 | return 0 |
| 2014 | } |
| 2015 | n := 0 |
| 2016 | for _, v := range s { |
| 2017 | n += protowire.SizeVarint(uint64(v)) |
| 2018 | } |
| 2019 | return f.tagsize + protowire.SizeBytes(n) |
| 2020 | } |
| 2021 | |
| 2022 | // appendInt64PackedSlice encodes a []int64 pointer as a packed repeated Int64. |
| 2023 | func appendInt64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 2024 | s := *p.Int64Slice() |
| 2025 | if len(s) == 0 { |
| 2026 | return b, nil |
| 2027 | } |
| 2028 | b = protowire.AppendVarint(b, f.wiretag) |
| 2029 | n := 0 |
| 2030 | for _, v := range s { |
| 2031 | n += protowire.SizeVarint(uint64(v)) |
| 2032 | } |
| 2033 | b = protowire.AppendVarint(b, uint64(n)) |
| 2034 | for _, v := range s { |
| 2035 | b = protowire.AppendVarint(b, uint64(v)) |
| 2036 | } |
| 2037 | return b, nil |
| 2038 | } |
| 2039 | |
| 2040 | var coderInt64PackedSlice = pointerCoderFuncs{ |
| 2041 | size: sizeInt64PackedSlice, |
| 2042 | marshal: appendInt64PackedSlice, |
| 2043 | unmarshal: consumeInt64Slice, |
| 2044 | merge: mergeInt64Slice, |
| 2045 | } |
| 2046 | |
| 2047 | // sizeInt64Value returns the size of wire encoding a int64 value as a Int64. |
| 2048 | func sizeInt64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 2049 | return tagsize + protowire.SizeVarint(uint64(v.Int())) |
| 2050 | } |
| 2051 | |
| 2052 | // appendInt64Value encodes a int64 value as a Int64. |
| 2053 | func appendInt64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 2054 | b = protowire.AppendVarint(b, wiretag) |
| 2055 | b = protowire.AppendVarint(b, uint64(v.Int())) |
| 2056 | return b, nil |
| 2057 | } |
| 2058 | |
| 2059 | // consumeInt64Value decodes a int64 value as a Int64. |
| 2060 | func consumeInt64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 2061 | if wtyp != protowire.VarintType { |
| 2062 | return protoreflect.Value{}, out, errUnknown |
| 2063 | } |
| 2064 | var v uint64 |
| 2065 | var n int |
| 2066 | if len(b) >= 1 && b[0] < 0x80 { |
| 2067 | v = uint64(b[0]) |
| 2068 | n = 1 |
| 2069 | } else if len(b) >= 2 && b[1] < 128 { |
| 2070 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2071 | n = 2 |
| 2072 | } else { |
| 2073 | v, n = protowire.ConsumeVarint(b) |
| 2074 | } |
| 2075 | if n < 0 { |
| 2076 | return protoreflect.Value{}, out, errDecode |
| 2077 | } |
| 2078 | out.n = n |
| 2079 | return protoreflect.ValueOfInt64(int64(v)), out, nil |
| 2080 | } |
| 2081 | |
| 2082 | var coderInt64Value = valueCoderFuncs{ |
| 2083 | size: sizeInt64Value, |
| 2084 | marshal: appendInt64Value, |
| 2085 | unmarshal: consumeInt64Value, |
| 2086 | merge: mergeScalarValue, |
| 2087 | } |
| 2088 | |
| 2089 | // sizeInt64SliceValue returns the size of wire encoding a []int64 value as a repeated Int64. |
| 2090 | func sizeInt64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 2091 | list := listv.List() |
| 2092 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2093 | v := list.Get(i) |
| 2094 | size += tagsize + protowire.SizeVarint(uint64(v.Int())) |
| 2095 | } |
| 2096 | return size |
| 2097 | } |
| 2098 | |
| 2099 | // appendInt64SliceValue encodes a []int64 value as a repeated Int64. |
| 2100 | func appendInt64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 2101 | list := listv.List() |
| 2102 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2103 | v := list.Get(i) |
| 2104 | b = protowire.AppendVarint(b, wiretag) |
| 2105 | b = protowire.AppendVarint(b, uint64(v.Int())) |
| 2106 | } |
| 2107 | return b, nil |
| 2108 | } |
| 2109 | |
| 2110 | // consumeInt64SliceValue wire decodes a []int64 value as a repeated Int64. |
| 2111 | func consumeInt64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 2112 | list := listv.List() |
| 2113 | if wtyp == protowire.BytesType { |
| 2114 | b, n := protowire.ConsumeBytes(b) |
| 2115 | if n < 0 { |
| 2116 | return protoreflect.Value{}, out, errDecode |
| 2117 | } |
| 2118 | for len(b) > 0 { |
| 2119 | var v uint64 |
| 2120 | var n int |
| 2121 | if len(b) >= 1 && b[0] < 0x80 { |
| 2122 | v = uint64(b[0]) |
| 2123 | n = 1 |
| 2124 | } else if len(b) >= 2 && b[1] < 128 { |
| 2125 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2126 | n = 2 |
| 2127 | } else { |
| 2128 | v, n = protowire.ConsumeVarint(b) |
| 2129 | } |
| 2130 | if n < 0 { |
| 2131 | return protoreflect.Value{}, out, errDecode |
| 2132 | } |
| 2133 | list.Append(protoreflect.ValueOfInt64(int64(v))) |
| 2134 | b = b[n:] |
| 2135 | } |
| 2136 | out.n = n |
| 2137 | return listv, out, nil |
| 2138 | } |
| 2139 | if wtyp != protowire.VarintType { |
| 2140 | return protoreflect.Value{}, out, errUnknown |
| 2141 | } |
| 2142 | var v uint64 |
| 2143 | var n int |
| 2144 | if len(b) >= 1 && b[0] < 0x80 { |
| 2145 | v = uint64(b[0]) |
| 2146 | n = 1 |
| 2147 | } else if len(b) >= 2 && b[1] < 128 { |
| 2148 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2149 | n = 2 |
| 2150 | } else { |
| 2151 | v, n = protowire.ConsumeVarint(b) |
| 2152 | } |
| 2153 | if n < 0 { |
| 2154 | return protoreflect.Value{}, out, errDecode |
| 2155 | } |
| 2156 | list.Append(protoreflect.ValueOfInt64(int64(v))) |
| 2157 | out.n = n |
| 2158 | return listv, out, nil |
| 2159 | } |
| 2160 | |
| 2161 | var coderInt64SliceValue = valueCoderFuncs{ |
| 2162 | size: sizeInt64SliceValue, |
| 2163 | marshal: appendInt64SliceValue, |
| 2164 | unmarshal: consumeInt64SliceValue, |
| 2165 | merge: mergeListValue, |
| 2166 | } |
| 2167 | |
| 2168 | // sizeInt64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Int64. |
| 2169 | func sizeInt64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 2170 | list := listv.List() |
| 2171 | llen := list.Len() |
| 2172 | if llen == 0 { |
| 2173 | return 0 |
| 2174 | } |
| 2175 | n := 0 |
| 2176 | for i, llen := 0, llen; i < llen; i++ { |
| 2177 | v := list.Get(i) |
| 2178 | n += protowire.SizeVarint(uint64(v.Int())) |
| 2179 | } |
| 2180 | return tagsize + protowire.SizeBytes(n) |
| 2181 | } |
| 2182 | |
| 2183 | // appendInt64PackedSliceValue encodes a []int64 value as a packed repeated Int64. |
| 2184 | func appendInt64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 2185 | list := listv.List() |
| 2186 | llen := list.Len() |
| 2187 | if llen == 0 { |
| 2188 | return b, nil |
| 2189 | } |
| 2190 | b = protowire.AppendVarint(b, wiretag) |
| 2191 | n := 0 |
| 2192 | for i := 0; i < llen; i++ { |
| 2193 | v := list.Get(i) |
| 2194 | n += protowire.SizeVarint(uint64(v.Int())) |
| 2195 | } |
| 2196 | b = protowire.AppendVarint(b, uint64(n)) |
| 2197 | for i := 0; i < llen; i++ { |
| 2198 | v := list.Get(i) |
| 2199 | b = protowire.AppendVarint(b, uint64(v.Int())) |
| 2200 | } |
| 2201 | return b, nil |
| 2202 | } |
| 2203 | |
| 2204 | var coderInt64PackedSliceValue = valueCoderFuncs{ |
| 2205 | size: sizeInt64PackedSliceValue, |
| 2206 | marshal: appendInt64PackedSliceValue, |
| 2207 | unmarshal: consumeInt64SliceValue, |
| 2208 | merge: mergeListValue, |
| 2209 | } |
| 2210 | |
| 2211 | // sizeSint64 returns the size of wire encoding a int64 pointer as a Sint64. |
| 2212 | func sizeSint64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 2213 | v := *p.Int64() |
| 2214 | return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v)) |
| 2215 | } |
| 2216 | |
| 2217 | // appendSint64 wire encodes a int64 pointer as a Sint64. |
| 2218 | func appendSint64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 2219 | v := *p.Int64() |
| 2220 | b = protowire.AppendVarint(b, f.wiretag) |
| 2221 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(v)) |
| 2222 | return b, nil |
| 2223 | } |
| 2224 | |
| 2225 | // consumeSint64 wire decodes a int64 pointer as a Sint64. |
| 2226 | func consumeSint64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 2227 | if wtyp != protowire.VarintType { |
| 2228 | return out, errUnknown |
| 2229 | } |
| 2230 | var v uint64 |
| 2231 | var n int |
| 2232 | if len(b) >= 1 && b[0] < 0x80 { |
| 2233 | v = uint64(b[0]) |
| 2234 | n = 1 |
| 2235 | } else if len(b) >= 2 && b[1] < 128 { |
| 2236 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2237 | n = 2 |
| 2238 | } else { |
| 2239 | v, n = protowire.ConsumeVarint(b) |
| 2240 | } |
| 2241 | if n < 0 { |
| 2242 | return out, errDecode |
| 2243 | } |
| 2244 | *p.Int64() = protowire.DecodeZigZag(v) |
| 2245 | out.n = n |
| 2246 | return out, nil |
| 2247 | } |
| 2248 | |
| 2249 | var coderSint64 = pointerCoderFuncs{ |
| 2250 | size: sizeSint64, |
| 2251 | marshal: appendSint64, |
| 2252 | unmarshal: consumeSint64, |
| 2253 | merge: mergeInt64, |
| 2254 | } |
| 2255 | |
| 2256 | // sizeSint64NoZero returns the size of wire encoding a int64 pointer as a Sint64. |
| 2257 | // The zero value is not encoded. |
| 2258 | func sizeSint64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 2259 | v := *p.Int64() |
| 2260 | if v == 0 { |
| 2261 | return 0 |
| 2262 | } |
| 2263 | return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v)) |
| 2264 | } |
| 2265 | |
| 2266 | // appendSint64NoZero wire encodes a int64 pointer as a Sint64. |
| 2267 | // The zero value is not encoded. |
| 2268 | func appendSint64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 2269 | v := *p.Int64() |
| 2270 | if v == 0 { |
| 2271 | return b, nil |
| 2272 | } |
| 2273 | b = protowire.AppendVarint(b, f.wiretag) |
| 2274 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(v)) |
| 2275 | return b, nil |
| 2276 | } |
| 2277 | |
| 2278 | var coderSint64NoZero = pointerCoderFuncs{ |
| 2279 | size: sizeSint64NoZero, |
| 2280 | marshal: appendSint64NoZero, |
| 2281 | unmarshal: consumeSint64, |
| 2282 | merge: mergeInt64NoZero, |
| 2283 | } |
| 2284 | |
| 2285 | // sizeSint64Ptr returns the size of wire encoding a *int64 pointer as a Sint64. |
| 2286 | // It panics if the pointer is nil. |
| 2287 | func sizeSint64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 2288 | v := **p.Int64Ptr() |
| 2289 | return f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v)) |
| 2290 | } |
| 2291 | |
| 2292 | // appendSint64Ptr wire encodes a *int64 pointer as a Sint64. |
| 2293 | // It panics if the pointer is nil. |
| 2294 | func appendSint64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 2295 | v := **p.Int64Ptr() |
| 2296 | b = protowire.AppendVarint(b, f.wiretag) |
| 2297 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(v)) |
| 2298 | return b, nil |
| 2299 | } |
| 2300 | |
| 2301 | // consumeSint64Ptr wire decodes a *int64 pointer as a Sint64. |
| 2302 | func consumeSint64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 2303 | if wtyp != protowire.VarintType { |
| 2304 | return out, errUnknown |
| 2305 | } |
| 2306 | var v uint64 |
| 2307 | var n int |
| 2308 | if len(b) >= 1 && b[0] < 0x80 { |
| 2309 | v = uint64(b[0]) |
| 2310 | n = 1 |
| 2311 | } else if len(b) >= 2 && b[1] < 128 { |
| 2312 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2313 | n = 2 |
| 2314 | } else { |
| 2315 | v, n = protowire.ConsumeVarint(b) |
| 2316 | } |
| 2317 | if n < 0 { |
| 2318 | return out, errDecode |
| 2319 | } |
| 2320 | vp := p.Int64Ptr() |
| 2321 | if *vp == nil { |
| 2322 | *vp = new(int64) |
| 2323 | } |
| 2324 | **vp = protowire.DecodeZigZag(v) |
| 2325 | out.n = n |
| 2326 | return out, nil |
| 2327 | } |
| 2328 | |
| 2329 | var coderSint64Ptr = pointerCoderFuncs{ |
| 2330 | size: sizeSint64Ptr, |
| 2331 | marshal: appendSint64Ptr, |
| 2332 | unmarshal: consumeSint64Ptr, |
| 2333 | merge: mergeInt64Ptr, |
| 2334 | } |
| 2335 | |
| 2336 | // sizeSint64Slice returns the size of wire encoding a []int64 pointer as a repeated Sint64. |
| 2337 | func sizeSint64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 2338 | s := *p.Int64Slice() |
| 2339 | for _, v := range s { |
| 2340 | size += f.tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v)) |
| 2341 | } |
| 2342 | return size |
| 2343 | } |
| 2344 | |
| 2345 | // appendSint64Slice encodes a []int64 pointer as a repeated Sint64. |
| 2346 | func appendSint64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 2347 | s := *p.Int64Slice() |
| 2348 | for _, v := range s { |
| 2349 | b = protowire.AppendVarint(b, f.wiretag) |
| 2350 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(v)) |
| 2351 | } |
| 2352 | return b, nil |
| 2353 | } |
| 2354 | |
| 2355 | // consumeSint64Slice wire decodes a []int64 pointer as a repeated Sint64. |
| 2356 | func consumeSint64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 2357 | sp := p.Int64Slice() |
| 2358 | if wtyp == protowire.BytesType { |
| 2359 | s := *sp |
| 2360 | b, n := protowire.ConsumeBytes(b) |
| 2361 | if n < 0 { |
| 2362 | return out, errDecode |
| 2363 | } |
| 2364 | for len(b) > 0 { |
| 2365 | var v uint64 |
| 2366 | var n int |
| 2367 | if len(b) >= 1 && b[0] < 0x80 { |
| 2368 | v = uint64(b[0]) |
| 2369 | n = 1 |
| 2370 | } else if len(b) >= 2 && b[1] < 128 { |
| 2371 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2372 | n = 2 |
| 2373 | } else { |
| 2374 | v, n = protowire.ConsumeVarint(b) |
| 2375 | } |
| 2376 | if n < 0 { |
| 2377 | return out, errDecode |
| 2378 | } |
| 2379 | s = append(s, protowire.DecodeZigZag(v)) |
| 2380 | b = b[n:] |
| 2381 | } |
| 2382 | *sp = s |
| 2383 | out.n = n |
| 2384 | return out, nil |
| 2385 | } |
| 2386 | if wtyp != protowire.VarintType { |
| 2387 | return out, errUnknown |
| 2388 | } |
| 2389 | var v uint64 |
| 2390 | var n int |
| 2391 | if len(b) >= 1 && b[0] < 0x80 { |
| 2392 | v = uint64(b[0]) |
| 2393 | n = 1 |
| 2394 | } else if len(b) >= 2 && b[1] < 128 { |
| 2395 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2396 | n = 2 |
| 2397 | } else { |
| 2398 | v, n = protowire.ConsumeVarint(b) |
| 2399 | } |
| 2400 | if n < 0 { |
| 2401 | return out, errDecode |
| 2402 | } |
| 2403 | *sp = append(*sp, protowire.DecodeZigZag(v)) |
| 2404 | out.n = n |
| 2405 | return out, nil |
| 2406 | } |
| 2407 | |
| 2408 | var coderSint64Slice = pointerCoderFuncs{ |
| 2409 | size: sizeSint64Slice, |
| 2410 | marshal: appendSint64Slice, |
| 2411 | unmarshal: consumeSint64Slice, |
| 2412 | merge: mergeInt64Slice, |
| 2413 | } |
| 2414 | |
| 2415 | // sizeSint64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sint64. |
| 2416 | func sizeSint64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 2417 | s := *p.Int64Slice() |
| 2418 | if len(s) == 0 { |
| 2419 | return 0 |
| 2420 | } |
| 2421 | n := 0 |
| 2422 | for _, v := range s { |
| 2423 | n += protowire.SizeVarint(protowire.EncodeZigZag(v)) |
| 2424 | } |
| 2425 | return f.tagsize + protowire.SizeBytes(n) |
| 2426 | } |
| 2427 | |
| 2428 | // appendSint64PackedSlice encodes a []int64 pointer as a packed repeated Sint64. |
| 2429 | func appendSint64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 2430 | s := *p.Int64Slice() |
| 2431 | if len(s) == 0 { |
| 2432 | return b, nil |
| 2433 | } |
| 2434 | b = protowire.AppendVarint(b, f.wiretag) |
| 2435 | n := 0 |
| 2436 | for _, v := range s { |
| 2437 | n += protowire.SizeVarint(protowire.EncodeZigZag(v)) |
| 2438 | } |
| 2439 | b = protowire.AppendVarint(b, uint64(n)) |
| 2440 | for _, v := range s { |
| 2441 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(v)) |
| 2442 | } |
| 2443 | return b, nil |
| 2444 | } |
| 2445 | |
| 2446 | var coderSint64PackedSlice = pointerCoderFuncs{ |
| 2447 | size: sizeSint64PackedSlice, |
| 2448 | marshal: appendSint64PackedSlice, |
| 2449 | unmarshal: consumeSint64Slice, |
| 2450 | merge: mergeInt64Slice, |
| 2451 | } |
| 2452 | |
| 2453 | // sizeSint64Value returns the size of wire encoding a int64 value as a Sint64. |
| 2454 | func sizeSint64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 2455 | return tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v.Int())) |
| 2456 | } |
| 2457 | |
| 2458 | // appendSint64Value encodes a int64 value as a Sint64. |
| 2459 | func appendSint64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 2460 | b = protowire.AppendVarint(b, wiretag) |
| 2461 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(v.Int())) |
| 2462 | return b, nil |
| 2463 | } |
| 2464 | |
| 2465 | // consumeSint64Value decodes a int64 value as a Sint64. |
| 2466 | func consumeSint64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 2467 | if wtyp != protowire.VarintType { |
| 2468 | return protoreflect.Value{}, out, errUnknown |
| 2469 | } |
| 2470 | var v uint64 |
| 2471 | var n int |
| 2472 | if len(b) >= 1 && b[0] < 0x80 { |
| 2473 | v = uint64(b[0]) |
| 2474 | n = 1 |
| 2475 | } else if len(b) >= 2 && b[1] < 128 { |
| 2476 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2477 | n = 2 |
| 2478 | } else { |
| 2479 | v, n = protowire.ConsumeVarint(b) |
| 2480 | } |
| 2481 | if n < 0 { |
| 2482 | return protoreflect.Value{}, out, errDecode |
| 2483 | } |
| 2484 | out.n = n |
| 2485 | return protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)), out, nil |
| 2486 | } |
| 2487 | |
| 2488 | var coderSint64Value = valueCoderFuncs{ |
| 2489 | size: sizeSint64Value, |
| 2490 | marshal: appendSint64Value, |
| 2491 | unmarshal: consumeSint64Value, |
| 2492 | merge: mergeScalarValue, |
| 2493 | } |
| 2494 | |
| 2495 | // sizeSint64SliceValue returns the size of wire encoding a []int64 value as a repeated Sint64. |
| 2496 | func sizeSint64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 2497 | list := listv.List() |
| 2498 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2499 | v := list.Get(i) |
| 2500 | size += tagsize + protowire.SizeVarint(protowire.EncodeZigZag(v.Int())) |
| 2501 | } |
| 2502 | return size |
| 2503 | } |
| 2504 | |
| 2505 | // appendSint64SliceValue encodes a []int64 value as a repeated Sint64. |
| 2506 | func appendSint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 2507 | list := listv.List() |
| 2508 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2509 | v := list.Get(i) |
| 2510 | b = protowire.AppendVarint(b, wiretag) |
| 2511 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(v.Int())) |
| 2512 | } |
| 2513 | return b, nil |
| 2514 | } |
| 2515 | |
| 2516 | // consumeSint64SliceValue wire decodes a []int64 value as a repeated Sint64. |
| 2517 | func consumeSint64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 2518 | list := listv.List() |
| 2519 | if wtyp == protowire.BytesType { |
| 2520 | b, n := protowire.ConsumeBytes(b) |
| 2521 | if n < 0 { |
| 2522 | return protoreflect.Value{}, out, errDecode |
| 2523 | } |
| 2524 | for len(b) > 0 { |
| 2525 | var v uint64 |
| 2526 | var n int |
| 2527 | if len(b) >= 1 && b[0] < 0x80 { |
| 2528 | v = uint64(b[0]) |
| 2529 | n = 1 |
| 2530 | } else if len(b) >= 2 && b[1] < 128 { |
| 2531 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2532 | n = 2 |
| 2533 | } else { |
| 2534 | v, n = protowire.ConsumeVarint(b) |
| 2535 | } |
| 2536 | if n < 0 { |
| 2537 | return protoreflect.Value{}, out, errDecode |
| 2538 | } |
| 2539 | list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v))) |
| 2540 | b = b[n:] |
| 2541 | } |
| 2542 | out.n = n |
| 2543 | return listv, out, nil |
| 2544 | } |
| 2545 | if wtyp != protowire.VarintType { |
| 2546 | return protoreflect.Value{}, out, errUnknown |
| 2547 | } |
| 2548 | var v uint64 |
| 2549 | var n int |
| 2550 | if len(b) >= 1 && b[0] < 0x80 { |
| 2551 | v = uint64(b[0]) |
| 2552 | n = 1 |
| 2553 | } else if len(b) >= 2 && b[1] < 128 { |
| 2554 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2555 | n = 2 |
| 2556 | } else { |
| 2557 | v, n = protowire.ConsumeVarint(b) |
| 2558 | } |
| 2559 | if n < 0 { |
| 2560 | return protoreflect.Value{}, out, errDecode |
| 2561 | } |
| 2562 | list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v))) |
| 2563 | out.n = n |
| 2564 | return listv, out, nil |
| 2565 | } |
| 2566 | |
| 2567 | var coderSint64SliceValue = valueCoderFuncs{ |
| 2568 | size: sizeSint64SliceValue, |
| 2569 | marshal: appendSint64SliceValue, |
| 2570 | unmarshal: consumeSint64SliceValue, |
| 2571 | merge: mergeListValue, |
| 2572 | } |
| 2573 | |
| 2574 | // sizeSint64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sint64. |
| 2575 | func sizeSint64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 2576 | list := listv.List() |
| 2577 | llen := list.Len() |
| 2578 | if llen == 0 { |
| 2579 | return 0 |
| 2580 | } |
| 2581 | n := 0 |
| 2582 | for i, llen := 0, llen; i < llen; i++ { |
| 2583 | v := list.Get(i) |
| 2584 | n += protowire.SizeVarint(protowire.EncodeZigZag(v.Int())) |
| 2585 | } |
| 2586 | return tagsize + protowire.SizeBytes(n) |
| 2587 | } |
| 2588 | |
| 2589 | // appendSint64PackedSliceValue encodes a []int64 value as a packed repeated Sint64. |
| 2590 | func appendSint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 2591 | list := listv.List() |
| 2592 | llen := list.Len() |
| 2593 | if llen == 0 { |
| 2594 | return b, nil |
| 2595 | } |
| 2596 | b = protowire.AppendVarint(b, wiretag) |
| 2597 | n := 0 |
| 2598 | for i := 0; i < llen; i++ { |
| 2599 | v := list.Get(i) |
| 2600 | n += protowire.SizeVarint(protowire.EncodeZigZag(v.Int())) |
| 2601 | } |
| 2602 | b = protowire.AppendVarint(b, uint64(n)) |
| 2603 | for i := 0; i < llen; i++ { |
| 2604 | v := list.Get(i) |
| 2605 | b = protowire.AppendVarint(b, protowire.EncodeZigZag(v.Int())) |
| 2606 | } |
| 2607 | return b, nil |
| 2608 | } |
| 2609 | |
| 2610 | var coderSint64PackedSliceValue = valueCoderFuncs{ |
| 2611 | size: sizeSint64PackedSliceValue, |
| 2612 | marshal: appendSint64PackedSliceValue, |
| 2613 | unmarshal: consumeSint64SliceValue, |
| 2614 | merge: mergeListValue, |
| 2615 | } |
| 2616 | |
| 2617 | // sizeUint64 returns the size of wire encoding a uint64 pointer as a Uint64. |
| 2618 | func sizeUint64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 2619 | v := *p.Uint64() |
| 2620 | return f.tagsize + protowire.SizeVarint(v) |
| 2621 | } |
| 2622 | |
| 2623 | // appendUint64 wire encodes a uint64 pointer as a Uint64. |
| 2624 | func appendUint64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 2625 | v := *p.Uint64() |
| 2626 | b = protowire.AppendVarint(b, f.wiretag) |
| 2627 | b = protowire.AppendVarint(b, v) |
| 2628 | return b, nil |
| 2629 | } |
| 2630 | |
| 2631 | // consumeUint64 wire decodes a uint64 pointer as a Uint64. |
| 2632 | func consumeUint64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 2633 | if wtyp != protowire.VarintType { |
| 2634 | return out, errUnknown |
| 2635 | } |
| 2636 | var v uint64 |
| 2637 | var n int |
| 2638 | if len(b) >= 1 && b[0] < 0x80 { |
| 2639 | v = uint64(b[0]) |
| 2640 | n = 1 |
| 2641 | } else if len(b) >= 2 && b[1] < 128 { |
| 2642 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2643 | n = 2 |
| 2644 | } else { |
| 2645 | v, n = protowire.ConsumeVarint(b) |
| 2646 | } |
| 2647 | if n < 0 { |
| 2648 | return out, errDecode |
| 2649 | } |
| 2650 | *p.Uint64() = v |
| 2651 | out.n = n |
| 2652 | return out, nil |
| 2653 | } |
| 2654 | |
| 2655 | var coderUint64 = pointerCoderFuncs{ |
| 2656 | size: sizeUint64, |
| 2657 | marshal: appendUint64, |
| 2658 | unmarshal: consumeUint64, |
| 2659 | merge: mergeUint64, |
| 2660 | } |
| 2661 | |
| 2662 | // sizeUint64NoZero returns the size of wire encoding a uint64 pointer as a Uint64. |
| 2663 | // The zero value is not encoded. |
| 2664 | func sizeUint64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 2665 | v := *p.Uint64() |
| 2666 | if v == 0 { |
| 2667 | return 0 |
| 2668 | } |
| 2669 | return f.tagsize + protowire.SizeVarint(v) |
| 2670 | } |
| 2671 | |
| 2672 | // appendUint64NoZero wire encodes a uint64 pointer as a Uint64. |
| 2673 | // The zero value is not encoded. |
| 2674 | func appendUint64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 2675 | v := *p.Uint64() |
| 2676 | if v == 0 { |
| 2677 | return b, nil |
| 2678 | } |
| 2679 | b = protowire.AppendVarint(b, f.wiretag) |
| 2680 | b = protowire.AppendVarint(b, v) |
| 2681 | return b, nil |
| 2682 | } |
| 2683 | |
| 2684 | var coderUint64NoZero = pointerCoderFuncs{ |
| 2685 | size: sizeUint64NoZero, |
| 2686 | marshal: appendUint64NoZero, |
| 2687 | unmarshal: consumeUint64, |
| 2688 | merge: mergeUint64NoZero, |
| 2689 | } |
| 2690 | |
| 2691 | // sizeUint64Ptr returns the size of wire encoding a *uint64 pointer as a Uint64. |
| 2692 | // It panics if the pointer is nil. |
| 2693 | func sizeUint64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 2694 | v := **p.Uint64Ptr() |
| 2695 | return f.tagsize + protowire.SizeVarint(v) |
| 2696 | } |
| 2697 | |
| 2698 | // appendUint64Ptr wire encodes a *uint64 pointer as a Uint64. |
| 2699 | // It panics if the pointer is nil. |
| 2700 | func appendUint64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 2701 | v := **p.Uint64Ptr() |
| 2702 | b = protowire.AppendVarint(b, f.wiretag) |
| 2703 | b = protowire.AppendVarint(b, v) |
| 2704 | return b, nil |
| 2705 | } |
| 2706 | |
| 2707 | // consumeUint64Ptr wire decodes a *uint64 pointer as a Uint64. |
| 2708 | func consumeUint64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 2709 | if wtyp != protowire.VarintType { |
| 2710 | return out, errUnknown |
| 2711 | } |
| 2712 | var v uint64 |
| 2713 | var n int |
| 2714 | if len(b) >= 1 && b[0] < 0x80 { |
| 2715 | v = uint64(b[0]) |
| 2716 | n = 1 |
| 2717 | } else if len(b) >= 2 && b[1] < 128 { |
| 2718 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2719 | n = 2 |
| 2720 | } else { |
| 2721 | v, n = protowire.ConsumeVarint(b) |
| 2722 | } |
| 2723 | if n < 0 { |
| 2724 | return out, errDecode |
| 2725 | } |
| 2726 | vp := p.Uint64Ptr() |
| 2727 | if *vp == nil { |
| 2728 | *vp = new(uint64) |
| 2729 | } |
| 2730 | **vp = v |
| 2731 | out.n = n |
| 2732 | return out, nil |
| 2733 | } |
| 2734 | |
| 2735 | var coderUint64Ptr = pointerCoderFuncs{ |
| 2736 | size: sizeUint64Ptr, |
| 2737 | marshal: appendUint64Ptr, |
| 2738 | unmarshal: consumeUint64Ptr, |
| 2739 | merge: mergeUint64Ptr, |
| 2740 | } |
| 2741 | |
| 2742 | // sizeUint64Slice returns the size of wire encoding a []uint64 pointer as a repeated Uint64. |
| 2743 | func sizeUint64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 2744 | s := *p.Uint64Slice() |
| 2745 | for _, v := range s { |
| 2746 | size += f.tagsize + protowire.SizeVarint(v) |
| 2747 | } |
| 2748 | return size |
| 2749 | } |
| 2750 | |
| 2751 | // appendUint64Slice encodes a []uint64 pointer as a repeated Uint64. |
| 2752 | func appendUint64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 2753 | s := *p.Uint64Slice() |
| 2754 | for _, v := range s { |
| 2755 | b = protowire.AppendVarint(b, f.wiretag) |
| 2756 | b = protowire.AppendVarint(b, v) |
| 2757 | } |
| 2758 | return b, nil |
| 2759 | } |
| 2760 | |
| 2761 | // consumeUint64Slice wire decodes a []uint64 pointer as a repeated Uint64. |
| 2762 | func consumeUint64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 2763 | sp := p.Uint64Slice() |
| 2764 | if wtyp == protowire.BytesType { |
| 2765 | s := *sp |
| 2766 | b, n := protowire.ConsumeBytes(b) |
| 2767 | if n < 0 { |
| 2768 | return out, errDecode |
| 2769 | } |
| 2770 | for len(b) > 0 { |
| 2771 | var v uint64 |
| 2772 | var n int |
| 2773 | if len(b) >= 1 && b[0] < 0x80 { |
| 2774 | v = uint64(b[0]) |
| 2775 | n = 1 |
| 2776 | } else if len(b) >= 2 && b[1] < 128 { |
| 2777 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2778 | n = 2 |
| 2779 | } else { |
| 2780 | v, n = protowire.ConsumeVarint(b) |
| 2781 | } |
| 2782 | if n < 0 { |
| 2783 | return out, errDecode |
| 2784 | } |
| 2785 | s = append(s, v) |
| 2786 | b = b[n:] |
| 2787 | } |
| 2788 | *sp = s |
| 2789 | out.n = n |
| 2790 | return out, nil |
| 2791 | } |
| 2792 | if wtyp != protowire.VarintType { |
| 2793 | return out, errUnknown |
| 2794 | } |
| 2795 | var v uint64 |
| 2796 | var n int |
| 2797 | if len(b) >= 1 && b[0] < 0x80 { |
| 2798 | v = uint64(b[0]) |
| 2799 | n = 1 |
| 2800 | } else if len(b) >= 2 && b[1] < 128 { |
| 2801 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2802 | n = 2 |
| 2803 | } else { |
| 2804 | v, n = protowire.ConsumeVarint(b) |
| 2805 | } |
| 2806 | if n < 0 { |
| 2807 | return out, errDecode |
| 2808 | } |
| 2809 | *sp = append(*sp, v) |
| 2810 | out.n = n |
| 2811 | return out, nil |
| 2812 | } |
| 2813 | |
| 2814 | var coderUint64Slice = pointerCoderFuncs{ |
| 2815 | size: sizeUint64Slice, |
| 2816 | marshal: appendUint64Slice, |
| 2817 | unmarshal: consumeUint64Slice, |
| 2818 | merge: mergeUint64Slice, |
| 2819 | } |
| 2820 | |
| 2821 | // sizeUint64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Uint64. |
| 2822 | func sizeUint64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 2823 | s := *p.Uint64Slice() |
| 2824 | if len(s) == 0 { |
| 2825 | return 0 |
| 2826 | } |
| 2827 | n := 0 |
| 2828 | for _, v := range s { |
| 2829 | n += protowire.SizeVarint(v) |
| 2830 | } |
| 2831 | return f.tagsize + protowire.SizeBytes(n) |
| 2832 | } |
| 2833 | |
| 2834 | // appendUint64PackedSlice encodes a []uint64 pointer as a packed repeated Uint64. |
| 2835 | func appendUint64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 2836 | s := *p.Uint64Slice() |
| 2837 | if len(s) == 0 { |
| 2838 | return b, nil |
| 2839 | } |
| 2840 | b = protowire.AppendVarint(b, f.wiretag) |
| 2841 | n := 0 |
| 2842 | for _, v := range s { |
| 2843 | n += protowire.SizeVarint(v) |
| 2844 | } |
| 2845 | b = protowire.AppendVarint(b, uint64(n)) |
| 2846 | for _, v := range s { |
| 2847 | b = protowire.AppendVarint(b, v) |
| 2848 | } |
| 2849 | return b, nil |
| 2850 | } |
| 2851 | |
| 2852 | var coderUint64PackedSlice = pointerCoderFuncs{ |
| 2853 | size: sizeUint64PackedSlice, |
| 2854 | marshal: appendUint64PackedSlice, |
| 2855 | unmarshal: consumeUint64Slice, |
| 2856 | merge: mergeUint64Slice, |
| 2857 | } |
| 2858 | |
| 2859 | // sizeUint64Value returns the size of wire encoding a uint64 value as a Uint64. |
| 2860 | func sizeUint64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 2861 | return tagsize + protowire.SizeVarint(v.Uint()) |
| 2862 | } |
| 2863 | |
| 2864 | // appendUint64Value encodes a uint64 value as a Uint64. |
| 2865 | func appendUint64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 2866 | b = protowire.AppendVarint(b, wiretag) |
| 2867 | b = protowire.AppendVarint(b, v.Uint()) |
| 2868 | return b, nil |
| 2869 | } |
| 2870 | |
| 2871 | // consumeUint64Value decodes a uint64 value as a Uint64. |
| 2872 | func consumeUint64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 2873 | if wtyp != protowire.VarintType { |
| 2874 | return protoreflect.Value{}, out, errUnknown |
| 2875 | } |
| 2876 | var v uint64 |
| 2877 | var n int |
| 2878 | if len(b) >= 1 && b[0] < 0x80 { |
| 2879 | v = uint64(b[0]) |
| 2880 | n = 1 |
| 2881 | } else if len(b) >= 2 && b[1] < 128 { |
| 2882 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2883 | n = 2 |
| 2884 | } else { |
| 2885 | v, n = protowire.ConsumeVarint(b) |
| 2886 | } |
| 2887 | if n < 0 { |
| 2888 | return protoreflect.Value{}, out, errDecode |
| 2889 | } |
| 2890 | out.n = n |
| 2891 | return protoreflect.ValueOfUint64(v), out, nil |
| 2892 | } |
| 2893 | |
| 2894 | var coderUint64Value = valueCoderFuncs{ |
| 2895 | size: sizeUint64Value, |
| 2896 | marshal: appendUint64Value, |
| 2897 | unmarshal: consumeUint64Value, |
| 2898 | merge: mergeScalarValue, |
| 2899 | } |
| 2900 | |
| 2901 | // sizeUint64SliceValue returns the size of wire encoding a []uint64 value as a repeated Uint64. |
| 2902 | func sizeUint64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 2903 | list := listv.List() |
| 2904 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2905 | v := list.Get(i) |
| 2906 | size += tagsize + protowire.SizeVarint(v.Uint()) |
| 2907 | } |
| 2908 | return size |
| 2909 | } |
| 2910 | |
| 2911 | // appendUint64SliceValue encodes a []uint64 value as a repeated Uint64. |
| 2912 | func appendUint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 2913 | list := listv.List() |
| 2914 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2915 | v := list.Get(i) |
| 2916 | b = protowire.AppendVarint(b, wiretag) |
| 2917 | b = protowire.AppendVarint(b, v.Uint()) |
| 2918 | } |
| 2919 | return b, nil |
| 2920 | } |
| 2921 | |
| 2922 | // consumeUint64SliceValue wire decodes a []uint64 value as a repeated Uint64. |
| 2923 | func consumeUint64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 2924 | list := listv.List() |
| 2925 | if wtyp == protowire.BytesType { |
| 2926 | b, n := protowire.ConsumeBytes(b) |
| 2927 | if n < 0 { |
| 2928 | return protoreflect.Value{}, out, errDecode |
| 2929 | } |
| 2930 | for len(b) > 0 { |
| 2931 | var v uint64 |
| 2932 | var n int |
| 2933 | if len(b) >= 1 && b[0] < 0x80 { |
| 2934 | v = uint64(b[0]) |
| 2935 | n = 1 |
| 2936 | } else if len(b) >= 2 && b[1] < 128 { |
| 2937 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2938 | n = 2 |
| 2939 | } else { |
| 2940 | v, n = protowire.ConsumeVarint(b) |
| 2941 | } |
| 2942 | if n < 0 { |
| 2943 | return protoreflect.Value{}, out, errDecode |
| 2944 | } |
| 2945 | list.Append(protoreflect.ValueOfUint64(v)) |
| 2946 | b = b[n:] |
| 2947 | } |
| 2948 | out.n = n |
| 2949 | return listv, out, nil |
| 2950 | } |
| 2951 | if wtyp != protowire.VarintType { |
| 2952 | return protoreflect.Value{}, out, errUnknown |
| 2953 | } |
| 2954 | var v uint64 |
| 2955 | var n int |
| 2956 | if len(b) >= 1 && b[0] < 0x80 { |
| 2957 | v = uint64(b[0]) |
| 2958 | n = 1 |
| 2959 | } else if len(b) >= 2 && b[1] < 128 { |
| 2960 | v = uint64(b[0]&0x7f) + uint64(b[1])<<7 |
| 2961 | n = 2 |
| 2962 | } else { |
| 2963 | v, n = protowire.ConsumeVarint(b) |
| 2964 | } |
| 2965 | if n < 0 { |
| 2966 | return protoreflect.Value{}, out, errDecode |
| 2967 | } |
| 2968 | list.Append(protoreflect.ValueOfUint64(v)) |
| 2969 | out.n = n |
| 2970 | return listv, out, nil |
| 2971 | } |
| 2972 | |
| 2973 | var coderUint64SliceValue = valueCoderFuncs{ |
| 2974 | size: sizeUint64SliceValue, |
| 2975 | marshal: appendUint64SliceValue, |
| 2976 | unmarshal: consumeUint64SliceValue, |
| 2977 | merge: mergeListValue, |
| 2978 | } |
| 2979 | |
| 2980 | // sizeUint64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Uint64. |
| 2981 | func sizeUint64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 2982 | list := listv.List() |
| 2983 | llen := list.Len() |
| 2984 | if llen == 0 { |
| 2985 | return 0 |
| 2986 | } |
| 2987 | n := 0 |
| 2988 | for i, llen := 0, llen; i < llen; i++ { |
| 2989 | v := list.Get(i) |
| 2990 | n += protowire.SizeVarint(v.Uint()) |
| 2991 | } |
| 2992 | return tagsize + protowire.SizeBytes(n) |
| 2993 | } |
| 2994 | |
| 2995 | // appendUint64PackedSliceValue encodes a []uint64 value as a packed repeated Uint64. |
| 2996 | func appendUint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 2997 | list := listv.List() |
| 2998 | llen := list.Len() |
| 2999 | if llen == 0 { |
| 3000 | return b, nil |
| 3001 | } |
| 3002 | b = protowire.AppendVarint(b, wiretag) |
| 3003 | n := 0 |
| 3004 | for i := 0; i < llen; i++ { |
| 3005 | v := list.Get(i) |
| 3006 | n += protowire.SizeVarint(v.Uint()) |
| 3007 | } |
| 3008 | b = protowire.AppendVarint(b, uint64(n)) |
| 3009 | for i := 0; i < llen; i++ { |
| 3010 | v := list.Get(i) |
| 3011 | b = protowire.AppendVarint(b, v.Uint()) |
| 3012 | } |
| 3013 | return b, nil |
| 3014 | } |
| 3015 | |
| 3016 | var coderUint64PackedSliceValue = valueCoderFuncs{ |
| 3017 | size: sizeUint64PackedSliceValue, |
| 3018 | marshal: appendUint64PackedSliceValue, |
| 3019 | unmarshal: consumeUint64SliceValue, |
| 3020 | merge: mergeListValue, |
| 3021 | } |
| 3022 | |
| 3023 | // sizeSfixed32 returns the size of wire encoding a int32 pointer as a Sfixed32. |
| 3024 | func sizeSfixed32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3025 | |
| 3026 | return f.tagsize + protowire.SizeFixed32() |
| 3027 | } |
| 3028 | |
| 3029 | // appendSfixed32 wire encodes a int32 pointer as a Sfixed32. |
| 3030 | func appendSfixed32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3031 | v := *p.Int32() |
| 3032 | b = protowire.AppendVarint(b, f.wiretag) |
| 3033 | b = protowire.AppendFixed32(b, uint32(v)) |
| 3034 | return b, nil |
| 3035 | } |
| 3036 | |
| 3037 | // consumeSfixed32 wire decodes a int32 pointer as a Sfixed32. |
| 3038 | func consumeSfixed32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 3039 | if wtyp != protowire.Fixed32Type { |
| 3040 | return out, errUnknown |
| 3041 | } |
| 3042 | v, n := protowire.ConsumeFixed32(b) |
| 3043 | if n < 0 { |
| 3044 | return out, errDecode |
| 3045 | } |
| 3046 | *p.Int32() = int32(v) |
| 3047 | out.n = n |
| 3048 | return out, nil |
| 3049 | } |
| 3050 | |
| 3051 | var coderSfixed32 = pointerCoderFuncs{ |
| 3052 | size: sizeSfixed32, |
| 3053 | marshal: appendSfixed32, |
| 3054 | unmarshal: consumeSfixed32, |
| 3055 | merge: mergeInt32, |
| 3056 | } |
| 3057 | |
| 3058 | // sizeSfixed32NoZero returns the size of wire encoding a int32 pointer as a Sfixed32. |
| 3059 | // The zero value is not encoded. |
| 3060 | func sizeSfixed32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3061 | v := *p.Int32() |
| 3062 | if v == 0 { |
| 3063 | return 0 |
| 3064 | } |
| 3065 | return f.tagsize + protowire.SizeFixed32() |
| 3066 | } |
| 3067 | |
| 3068 | // appendSfixed32NoZero wire encodes a int32 pointer as a Sfixed32. |
| 3069 | // The zero value is not encoded. |
| 3070 | func appendSfixed32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3071 | v := *p.Int32() |
| 3072 | if v == 0 { |
| 3073 | return b, nil |
| 3074 | } |
| 3075 | b = protowire.AppendVarint(b, f.wiretag) |
| 3076 | b = protowire.AppendFixed32(b, uint32(v)) |
| 3077 | return b, nil |
| 3078 | } |
| 3079 | |
| 3080 | var coderSfixed32NoZero = pointerCoderFuncs{ |
| 3081 | size: sizeSfixed32NoZero, |
| 3082 | marshal: appendSfixed32NoZero, |
| 3083 | unmarshal: consumeSfixed32, |
| 3084 | merge: mergeInt32NoZero, |
| 3085 | } |
| 3086 | |
| 3087 | // sizeSfixed32Ptr returns the size of wire encoding a *int32 pointer as a Sfixed32. |
| 3088 | // It panics if the pointer is nil. |
| 3089 | func sizeSfixed32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3090 | return f.tagsize + protowire.SizeFixed32() |
| 3091 | } |
| 3092 | |
| 3093 | // appendSfixed32Ptr wire encodes a *int32 pointer as a Sfixed32. |
| 3094 | // It panics if the pointer is nil. |
| 3095 | func appendSfixed32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3096 | v := **p.Int32Ptr() |
| 3097 | b = protowire.AppendVarint(b, f.wiretag) |
| 3098 | b = protowire.AppendFixed32(b, uint32(v)) |
| 3099 | return b, nil |
| 3100 | } |
| 3101 | |
| 3102 | // consumeSfixed32Ptr wire decodes a *int32 pointer as a Sfixed32. |
| 3103 | func consumeSfixed32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 3104 | if wtyp != protowire.Fixed32Type { |
| 3105 | return out, errUnknown |
| 3106 | } |
| 3107 | v, n := protowire.ConsumeFixed32(b) |
| 3108 | if n < 0 { |
| 3109 | return out, errDecode |
| 3110 | } |
| 3111 | vp := p.Int32Ptr() |
| 3112 | if *vp == nil { |
| 3113 | *vp = new(int32) |
| 3114 | } |
| 3115 | **vp = int32(v) |
| 3116 | out.n = n |
| 3117 | return out, nil |
| 3118 | } |
| 3119 | |
| 3120 | var coderSfixed32Ptr = pointerCoderFuncs{ |
| 3121 | size: sizeSfixed32Ptr, |
| 3122 | marshal: appendSfixed32Ptr, |
| 3123 | unmarshal: consumeSfixed32Ptr, |
| 3124 | merge: mergeInt32Ptr, |
| 3125 | } |
| 3126 | |
| 3127 | // sizeSfixed32Slice returns the size of wire encoding a []int32 pointer as a repeated Sfixed32. |
| 3128 | func sizeSfixed32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3129 | s := *p.Int32Slice() |
| 3130 | size = len(s) * (f.tagsize + protowire.SizeFixed32()) |
| 3131 | return size |
| 3132 | } |
| 3133 | |
| 3134 | // appendSfixed32Slice encodes a []int32 pointer as a repeated Sfixed32. |
| 3135 | func appendSfixed32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3136 | s := *p.Int32Slice() |
| 3137 | for _, v := range s { |
| 3138 | b = protowire.AppendVarint(b, f.wiretag) |
| 3139 | b = protowire.AppendFixed32(b, uint32(v)) |
| 3140 | } |
| 3141 | return b, nil |
| 3142 | } |
| 3143 | |
| 3144 | // consumeSfixed32Slice wire decodes a []int32 pointer as a repeated Sfixed32. |
| 3145 | func consumeSfixed32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 3146 | sp := p.Int32Slice() |
| 3147 | if wtyp == protowire.BytesType { |
| 3148 | s := *sp |
| 3149 | b, n := protowire.ConsumeBytes(b) |
| 3150 | if n < 0 { |
| 3151 | return out, errDecode |
| 3152 | } |
| 3153 | for len(b) > 0 { |
| 3154 | v, n := protowire.ConsumeFixed32(b) |
| 3155 | if n < 0 { |
| 3156 | return out, errDecode |
| 3157 | } |
| 3158 | s = append(s, int32(v)) |
| 3159 | b = b[n:] |
| 3160 | } |
| 3161 | *sp = s |
| 3162 | out.n = n |
| 3163 | return out, nil |
| 3164 | } |
| 3165 | if wtyp != protowire.Fixed32Type { |
| 3166 | return out, errUnknown |
| 3167 | } |
| 3168 | v, n := protowire.ConsumeFixed32(b) |
| 3169 | if n < 0 { |
| 3170 | return out, errDecode |
| 3171 | } |
| 3172 | *sp = append(*sp, int32(v)) |
| 3173 | out.n = n |
| 3174 | return out, nil |
| 3175 | } |
| 3176 | |
| 3177 | var coderSfixed32Slice = pointerCoderFuncs{ |
| 3178 | size: sizeSfixed32Slice, |
| 3179 | marshal: appendSfixed32Slice, |
| 3180 | unmarshal: consumeSfixed32Slice, |
| 3181 | merge: mergeInt32Slice, |
| 3182 | } |
| 3183 | |
| 3184 | // sizeSfixed32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sfixed32. |
| 3185 | func sizeSfixed32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3186 | s := *p.Int32Slice() |
| 3187 | if len(s) == 0 { |
| 3188 | return 0 |
| 3189 | } |
| 3190 | n := len(s) * protowire.SizeFixed32() |
| 3191 | return f.tagsize + protowire.SizeBytes(n) |
| 3192 | } |
| 3193 | |
| 3194 | // appendSfixed32PackedSlice encodes a []int32 pointer as a packed repeated Sfixed32. |
| 3195 | func appendSfixed32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3196 | s := *p.Int32Slice() |
| 3197 | if len(s) == 0 { |
| 3198 | return b, nil |
| 3199 | } |
| 3200 | b = protowire.AppendVarint(b, f.wiretag) |
| 3201 | n := len(s) * protowire.SizeFixed32() |
| 3202 | b = protowire.AppendVarint(b, uint64(n)) |
| 3203 | for _, v := range s { |
| 3204 | b = protowire.AppendFixed32(b, uint32(v)) |
| 3205 | } |
| 3206 | return b, nil |
| 3207 | } |
| 3208 | |
| 3209 | var coderSfixed32PackedSlice = pointerCoderFuncs{ |
| 3210 | size: sizeSfixed32PackedSlice, |
| 3211 | marshal: appendSfixed32PackedSlice, |
| 3212 | unmarshal: consumeSfixed32Slice, |
| 3213 | merge: mergeInt32Slice, |
| 3214 | } |
| 3215 | |
| 3216 | // sizeSfixed32Value returns the size of wire encoding a int32 value as a Sfixed32. |
| 3217 | func sizeSfixed32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 3218 | return tagsize + protowire.SizeFixed32() |
| 3219 | } |
| 3220 | |
| 3221 | // appendSfixed32Value encodes a int32 value as a Sfixed32. |
| 3222 | func appendSfixed32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 3223 | b = protowire.AppendVarint(b, wiretag) |
| 3224 | b = protowire.AppendFixed32(b, uint32(v.Int())) |
| 3225 | return b, nil |
| 3226 | } |
| 3227 | |
| 3228 | // consumeSfixed32Value decodes a int32 value as a Sfixed32. |
| 3229 | func consumeSfixed32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 3230 | if wtyp != protowire.Fixed32Type { |
| 3231 | return protoreflect.Value{}, out, errUnknown |
| 3232 | } |
| 3233 | v, n := protowire.ConsumeFixed32(b) |
| 3234 | if n < 0 { |
| 3235 | return protoreflect.Value{}, out, errDecode |
| 3236 | } |
| 3237 | out.n = n |
| 3238 | return protoreflect.ValueOfInt32(int32(v)), out, nil |
| 3239 | } |
| 3240 | |
| 3241 | var coderSfixed32Value = valueCoderFuncs{ |
| 3242 | size: sizeSfixed32Value, |
| 3243 | marshal: appendSfixed32Value, |
| 3244 | unmarshal: consumeSfixed32Value, |
| 3245 | merge: mergeScalarValue, |
| 3246 | } |
| 3247 | |
| 3248 | // sizeSfixed32SliceValue returns the size of wire encoding a []int32 value as a repeated Sfixed32. |
| 3249 | func sizeSfixed32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 3250 | list := listv.List() |
| 3251 | size = list.Len() * (tagsize + protowire.SizeFixed32()) |
| 3252 | return size |
| 3253 | } |
| 3254 | |
| 3255 | // appendSfixed32SliceValue encodes a []int32 value as a repeated Sfixed32. |
| 3256 | func appendSfixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 3257 | list := listv.List() |
| 3258 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 3259 | v := list.Get(i) |
| 3260 | b = protowire.AppendVarint(b, wiretag) |
| 3261 | b = protowire.AppendFixed32(b, uint32(v.Int())) |
| 3262 | } |
| 3263 | return b, nil |
| 3264 | } |
| 3265 | |
| 3266 | // consumeSfixed32SliceValue wire decodes a []int32 value as a repeated Sfixed32. |
| 3267 | func consumeSfixed32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 3268 | list := listv.List() |
| 3269 | if wtyp == protowire.BytesType { |
| 3270 | b, n := protowire.ConsumeBytes(b) |
| 3271 | if n < 0 { |
| 3272 | return protoreflect.Value{}, out, errDecode |
| 3273 | } |
| 3274 | for len(b) > 0 { |
| 3275 | v, n := protowire.ConsumeFixed32(b) |
| 3276 | if n < 0 { |
| 3277 | return protoreflect.Value{}, out, errDecode |
| 3278 | } |
| 3279 | list.Append(protoreflect.ValueOfInt32(int32(v))) |
| 3280 | b = b[n:] |
| 3281 | } |
| 3282 | out.n = n |
| 3283 | return listv, out, nil |
| 3284 | } |
| 3285 | if wtyp != protowire.Fixed32Type { |
| 3286 | return protoreflect.Value{}, out, errUnknown |
| 3287 | } |
| 3288 | v, n := protowire.ConsumeFixed32(b) |
| 3289 | if n < 0 { |
| 3290 | return protoreflect.Value{}, out, errDecode |
| 3291 | } |
| 3292 | list.Append(protoreflect.ValueOfInt32(int32(v))) |
| 3293 | out.n = n |
| 3294 | return listv, out, nil |
| 3295 | } |
| 3296 | |
| 3297 | var coderSfixed32SliceValue = valueCoderFuncs{ |
| 3298 | size: sizeSfixed32SliceValue, |
| 3299 | marshal: appendSfixed32SliceValue, |
| 3300 | unmarshal: consumeSfixed32SliceValue, |
| 3301 | merge: mergeListValue, |
| 3302 | } |
| 3303 | |
| 3304 | // sizeSfixed32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sfixed32. |
| 3305 | func sizeSfixed32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 3306 | list := listv.List() |
| 3307 | llen := list.Len() |
| 3308 | if llen == 0 { |
| 3309 | return 0 |
| 3310 | } |
| 3311 | n := llen * protowire.SizeFixed32() |
| 3312 | return tagsize + protowire.SizeBytes(n) |
| 3313 | } |
| 3314 | |
| 3315 | // appendSfixed32PackedSliceValue encodes a []int32 value as a packed repeated Sfixed32. |
| 3316 | func appendSfixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 3317 | list := listv.List() |
| 3318 | llen := list.Len() |
| 3319 | if llen == 0 { |
| 3320 | return b, nil |
| 3321 | } |
| 3322 | b = protowire.AppendVarint(b, wiretag) |
| 3323 | n := llen * protowire.SizeFixed32() |
| 3324 | b = protowire.AppendVarint(b, uint64(n)) |
| 3325 | for i := 0; i < llen; i++ { |
| 3326 | v := list.Get(i) |
| 3327 | b = protowire.AppendFixed32(b, uint32(v.Int())) |
| 3328 | } |
| 3329 | return b, nil |
| 3330 | } |
| 3331 | |
| 3332 | var coderSfixed32PackedSliceValue = valueCoderFuncs{ |
| 3333 | size: sizeSfixed32PackedSliceValue, |
| 3334 | marshal: appendSfixed32PackedSliceValue, |
| 3335 | unmarshal: consumeSfixed32SliceValue, |
| 3336 | merge: mergeListValue, |
| 3337 | } |
| 3338 | |
| 3339 | // sizeFixed32 returns the size of wire encoding a uint32 pointer as a Fixed32. |
| 3340 | func sizeFixed32(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3341 | |
| 3342 | return f.tagsize + protowire.SizeFixed32() |
| 3343 | } |
| 3344 | |
| 3345 | // appendFixed32 wire encodes a uint32 pointer as a Fixed32. |
| 3346 | func appendFixed32(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3347 | v := *p.Uint32() |
| 3348 | b = protowire.AppendVarint(b, f.wiretag) |
| 3349 | b = protowire.AppendFixed32(b, v) |
| 3350 | return b, nil |
| 3351 | } |
| 3352 | |
| 3353 | // consumeFixed32 wire decodes a uint32 pointer as a Fixed32. |
| 3354 | func consumeFixed32(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 3355 | if wtyp != protowire.Fixed32Type { |
| 3356 | return out, errUnknown |
| 3357 | } |
| 3358 | v, n := protowire.ConsumeFixed32(b) |
| 3359 | if n < 0 { |
| 3360 | return out, errDecode |
| 3361 | } |
| 3362 | *p.Uint32() = v |
| 3363 | out.n = n |
| 3364 | return out, nil |
| 3365 | } |
| 3366 | |
| 3367 | var coderFixed32 = pointerCoderFuncs{ |
| 3368 | size: sizeFixed32, |
| 3369 | marshal: appendFixed32, |
| 3370 | unmarshal: consumeFixed32, |
| 3371 | merge: mergeUint32, |
| 3372 | } |
| 3373 | |
| 3374 | // sizeFixed32NoZero returns the size of wire encoding a uint32 pointer as a Fixed32. |
| 3375 | // The zero value is not encoded. |
| 3376 | func sizeFixed32NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3377 | v := *p.Uint32() |
| 3378 | if v == 0 { |
| 3379 | return 0 |
| 3380 | } |
| 3381 | return f.tagsize + protowire.SizeFixed32() |
| 3382 | } |
| 3383 | |
| 3384 | // appendFixed32NoZero wire encodes a uint32 pointer as a Fixed32. |
| 3385 | // The zero value is not encoded. |
| 3386 | func appendFixed32NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3387 | v := *p.Uint32() |
| 3388 | if v == 0 { |
| 3389 | return b, nil |
| 3390 | } |
| 3391 | b = protowire.AppendVarint(b, f.wiretag) |
| 3392 | b = protowire.AppendFixed32(b, v) |
| 3393 | return b, nil |
| 3394 | } |
| 3395 | |
| 3396 | var coderFixed32NoZero = pointerCoderFuncs{ |
| 3397 | size: sizeFixed32NoZero, |
| 3398 | marshal: appendFixed32NoZero, |
| 3399 | unmarshal: consumeFixed32, |
| 3400 | merge: mergeUint32NoZero, |
| 3401 | } |
| 3402 | |
| 3403 | // sizeFixed32Ptr returns the size of wire encoding a *uint32 pointer as a Fixed32. |
| 3404 | // It panics if the pointer is nil. |
| 3405 | func sizeFixed32Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3406 | return f.tagsize + protowire.SizeFixed32() |
| 3407 | } |
| 3408 | |
| 3409 | // appendFixed32Ptr wire encodes a *uint32 pointer as a Fixed32. |
| 3410 | // It panics if the pointer is nil. |
| 3411 | func appendFixed32Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3412 | v := **p.Uint32Ptr() |
| 3413 | b = protowire.AppendVarint(b, f.wiretag) |
| 3414 | b = protowire.AppendFixed32(b, v) |
| 3415 | return b, nil |
| 3416 | } |
| 3417 | |
| 3418 | // consumeFixed32Ptr wire decodes a *uint32 pointer as a Fixed32. |
| 3419 | func consumeFixed32Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 3420 | if wtyp != protowire.Fixed32Type { |
| 3421 | return out, errUnknown |
| 3422 | } |
| 3423 | v, n := protowire.ConsumeFixed32(b) |
| 3424 | if n < 0 { |
| 3425 | return out, errDecode |
| 3426 | } |
| 3427 | vp := p.Uint32Ptr() |
| 3428 | if *vp == nil { |
| 3429 | *vp = new(uint32) |
| 3430 | } |
| 3431 | **vp = v |
| 3432 | out.n = n |
| 3433 | return out, nil |
| 3434 | } |
| 3435 | |
| 3436 | var coderFixed32Ptr = pointerCoderFuncs{ |
| 3437 | size: sizeFixed32Ptr, |
| 3438 | marshal: appendFixed32Ptr, |
| 3439 | unmarshal: consumeFixed32Ptr, |
| 3440 | merge: mergeUint32Ptr, |
| 3441 | } |
| 3442 | |
| 3443 | // sizeFixed32Slice returns the size of wire encoding a []uint32 pointer as a repeated Fixed32. |
| 3444 | func sizeFixed32Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3445 | s := *p.Uint32Slice() |
| 3446 | size = len(s) * (f.tagsize + protowire.SizeFixed32()) |
| 3447 | return size |
| 3448 | } |
| 3449 | |
| 3450 | // appendFixed32Slice encodes a []uint32 pointer as a repeated Fixed32. |
| 3451 | func appendFixed32Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3452 | s := *p.Uint32Slice() |
| 3453 | for _, v := range s { |
| 3454 | b = protowire.AppendVarint(b, f.wiretag) |
| 3455 | b = protowire.AppendFixed32(b, v) |
| 3456 | } |
| 3457 | return b, nil |
| 3458 | } |
| 3459 | |
| 3460 | // consumeFixed32Slice wire decodes a []uint32 pointer as a repeated Fixed32. |
| 3461 | func consumeFixed32Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 3462 | sp := p.Uint32Slice() |
| 3463 | if wtyp == protowire.BytesType { |
| 3464 | s := *sp |
| 3465 | b, n := protowire.ConsumeBytes(b) |
| 3466 | if n < 0 { |
| 3467 | return out, errDecode |
| 3468 | } |
| 3469 | for len(b) > 0 { |
| 3470 | v, n := protowire.ConsumeFixed32(b) |
| 3471 | if n < 0 { |
| 3472 | return out, errDecode |
| 3473 | } |
| 3474 | s = append(s, v) |
| 3475 | b = b[n:] |
| 3476 | } |
| 3477 | *sp = s |
| 3478 | out.n = n |
| 3479 | return out, nil |
| 3480 | } |
| 3481 | if wtyp != protowire.Fixed32Type { |
| 3482 | return out, errUnknown |
| 3483 | } |
| 3484 | v, n := protowire.ConsumeFixed32(b) |
| 3485 | if n < 0 { |
| 3486 | return out, errDecode |
| 3487 | } |
| 3488 | *sp = append(*sp, v) |
| 3489 | out.n = n |
| 3490 | return out, nil |
| 3491 | } |
| 3492 | |
| 3493 | var coderFixed32Slice = pointerCoderFuncs{ |
| 3494 | size: sizeFixed32Slice, |
| 3495 | marshal: appendFixed32Slice, |
| 3496 | unmarshal: consumeFixed32Slice, |
| 3497 | merge: mergeUint32Slice, |
| 3498 | } |
| 3499 | |
| 3500 | // sizeFixed32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Fixed32. |
| 3501 | func sizeFixed32PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3502 | s := *p.Uint32Slice() |
| 3503 | if len(s) == 0 { |
| 3504 | return 0 |
| 3505 | } |
| 3506 | n := len(s) * protowire.SizeFixed32() |
| 3507 | return f.tagsize + protowire.SizeBytes(n) |
| 3508 | } |
| 3509 | |
| 3510 | // appendFixed32PackedSlice encodes a []uint32 pointer as a packed repeated Fixed32. |
| 3511 | func appendFixed32PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3512 | s := *p.Uint32Slice() |
| 3513 | if len(s) == 0 { |
| 3514 | return b, nil |
| 3515 | } |
| 3516 | b = protowire.AppendVarint(b, f.wiretag) |
| 3517 | n := len(s) * protowire.SizeFixed32() |
| 3518 | b = protowire.AppendVarint(b, uint64(n)) |
| 3519 | for _, v := range s { |
| 3520 | b = protowire.AppendFixed32(b, v) |
| 3521 | } |
| 3522 | return b, nil |
| 3523 | } |
| 3524 | |
| 3525 | var coderFixed32PackedSlice = pointerCoderFuncs{ |
| 3526 | size: sizeFixed32PackedSlice, |
| 3527 | marshal: appendFixed32PackedSlice, |
| 3528 | unmarshal: consumeFixed32Slice, |
| 3529 | merge: mergeUint32Slice, |
| 3530 | } |
| 3531 | |
| 3532 | // sizeFixed32Value returns the size of wire encoding a uint32 value as a Fixed32. |
| 3533 | func sizeFixed32Value(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 3534 | return tagsize + protowire.SizeFixed32() |
| 3535 | } |
| 3536 | |
| 3537 | // appendFixed32Value encodes a uint32 value as a Fixed32. |
| 3538 | func appendFixed32Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 3539 | b = protowire.AppendVarint(b, wiretag) |
| 3540 | b = protowire.AppendFixed32(b, uint32(v.Uint())) |
| 3541 | return b, nil |
| 3542 | } |
| 3543 | |
| 3544 | // consumeFixed32Value decodes a uint32 value as a Fixed32. |
| 3545 | func consumeFixed32Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 3546 | if wtyp != protowire.Fixed32Type { |
| 3547 | return protoreflect.Value{}, out, errUnknown |
| 3548 | } |
| 3549 | v, n := protowire.ConsumeFixed32(b) |
| 3550 | if n < 0 { |
| 3551 | return protoreflect.Value{}, out, errDecode |
| 3552 | } |
| 3553 | out.n = n |
| 3554 | return protoreflect.ValueOfUint32(uint32(v)), out, nil |
| 3555 | } |
| 3556 | |
| 3557 | var coderFixed32Value = valueCoderFuncs{ |
| 3558 | size: sizeFixed32Value, |
| 3559 | marshal: appendFixed32Value, |
| 3560 | unmarshal: consumeFixed32Value, |
| 3561 | merge: mergeScalarValue, |
| 3562 | } |
| 3563 | |
| 3564 | // sizeFixed32SliceValue returns the size of wire encoding a []uint32 value as a repeated Fixed32. |
| 3565 | func sizeFixed32SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 3566 | list := listv.List() |
| 3567 | size = list.Len() * (tagsize + protowire.SizeFixed32()) |
| 3568 | return size |
| 3569 | } |
| 3570 | |
| 3571 | // appendFixed32SliceValue encodes a []uint32 value as a repeated Fixed32. |
| 3572 | func appendFixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 3573 | list := listv.List() |
| 3574 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 3575 | v := list.Get(i) |
| 3576 | b = protowire.AppendVarint(b, wiretag) |
| 3577 | b = protowire.AppendFixed32(b, uint32(v.Uint())) |
| 3578 | } |
| 3579 | return b, nil |
| 3580 | } |
| 3581 | |
| 3582 | // consumeFixed32SliceValue wire decodes a []uint32 value as a repeated Fixed32. |
| 3583 | func consumeFixed32SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 3584 | list := listv.List() |
| 3585 | if wtyp == protowire.BytesType { |
| 3586 | b, n := protowire.ConsumeBytes(b) |
| 3587 | if n < 0 { |
| 3588 | return protoreflect.Value{}, out, errDecode |
| 3589 | } |
| 3590 | for len(b) > 0 { |
| 3591 | v, n := protowire.ConsumeFixed32(b) |
| 3592 | if n < 0 { |
| 3593 | return protoreflect.Value{}, out, errDecode |
| 3594 | } |
| 3595 | list.Append(protoreflect.ValueOfUint32(uint32(v))) |
| 3596 | b = b[n:] |
| 3597 | } |
| 3598 | out.n = n |
| 3599 | return listv, out, nil |
| 3600 | } |
| 3601 | if wtyp != protowire.Fixed32Type { |
| 3602 | return protoreflect.Value{}, out, errUnknown |
| 3603 | } |
| 3604 | v, n := protowire.ConsumeFixed32(b) |
| 3605 | if n < 0 { |
| 3606 | return protoreflect.Value{}, out, errDecode |
| 3607 | } |
| 3608 | list.Append(protoreflect.ValueOfUint32(uint32(v))) |
| 3609 | out.n = n |
| 3610 | return listv, out, nil |
| 3611 | } |
| 3612 | |
| 3613 | var coderFixed32SliceValue = valueCoderFuncs{ |
| 3614 | size: sizeFixed32SliceValue, |
| 3615 | marshal: appendFixed32SliceValue, |
| 3616 | unmarshal: consumeFixed32SliceValue, |
| 3617 | merge: mergeListValue, |
| 3618 | } |
| 3619 | |
| 3620 | // sizeFixed32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Fixed32. |
| 3621 | func sizeFixed32PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 3622 | list := listv.List() |
| 3623 | llen := list.Len() |
| 3624 | if llen == 0 { |
| 3625 | return 0 |
| 3626 | } |
| 3627 | n := llen * protowire.SizeFixed32() |
| 3628 | return tagsize + protowire.SizeBytes(n) |
| 3629 | } |
| 3630 | |
| 3631 | // appendFixed32PackedSliceValue encodes a []uint32 value as a packed repeated Fixed32. |
| 3632 | func appendFixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 3633 | list := listv.List() |
| 3634 | llen := list.Len() |
| 3635 | if llen == 0 { |
| 3636 | return b, nil |
| 3637 | } |
| 3638 | b = protowire.AppendVarint(b, wiretag) |
| 3639 | n := llen * protowire.SizeFixed32() |
| 3640 | b = protowire.AppendVarint(b, uint64(n)) |
| 3641 | for i := 0; i < llen; i++ { |
| 3642 | v := list.Get(i) |
| 3643 | b = protowire.AppendFixed32(b, uint32(v.Uint())) |
| 3644 | } |
| 3645 | return b, nil |
| 3646 | } |
| 3647 | |
| 3648 | var coderFixed32PackedSliceValue = valueCoderFuncs{ |
| 3649 | size: sizeFixed32PackedSliceValue, |
| 3650 | marshal: appendFixed32PackedSliceValue, |
| 3651 | unmarshal: consumeFixed32SliceValue, |
| 3652 | merge: mergeListValue, |
| 3653 | } |
| 3654 | |
| 3655 | // sizeFloat returns the size of wire encoding a float32 pointer as a Float. |
| 3656 | func sizeFloat(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3657 | |
| 3658 | return f.tagsize + protowire.SizeFixed32() |
| 3659 | } |
| 3660 | |
| 3661 | // appendFloat wire encodes a float32 pointer as a Float. |
| 3662 | func appendFloat(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3663 | v := *p.Float32() |
| 3664 | b = protowire.AppendVarint(b, f.wiretag) |
| 3665 | b = protowire.AppendFixed32(b, math.Float32bits(v)) |
| 3666 | return b, nil |
| 3667 | } |
| 3668 | |
| 3669 | // consumeFloat wire decodes a float32 pointer as a Float. |
| 3670 | func consumeFloat(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 3671 | if wtyp != protowire.Fixed32Type { |
| 3672 | return out, errUnknown |
| 3673 | } |
| 3674 | v, n := protowire.ConsumeFixed32(b) |
| 3675 | if n < 0 { |
| 3676 | return out, errDecode |
| 3677 | } |
| 3678 | *p.Float32() = math.Float32frombits(v) |
| 3679 | out.n = n |
| 3680 | return out, nil |
| 3681 | } |
| 3682 | |
| 3683 | var coderFloat = pointerCoderFuncs{ |
| 3684 | size: sizeFloat, |
| 3685 | marshal: appendFloat, |
| 3686 | unmarshal: consumeFloat, |
| 3687 | merge: mergeFloat32, |
| 3688 | } |
| 3689 | |
| 3690 | // sizeFloatNoZero returns the size of wire encoding a float32 pointer as a Float. |
| 3691 | // The zero value is not encoded. |
| 3692 | func sizeFloatNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3693 | v := *p.Float32() |
| 3694 | if v == 0 && !math.Signbit(float64(v)) { |
| 3695 | return 0 |
| 3696 | } |
| 3697 | return f.tagsize + protowire.SizeFixed32() |
| 3698 | } |
| 3699 | |
| 3700 | // appendFloatNoZero wire encodes a float32 pointer as a Float. |
| 3701 | // The zero value is not encoded. |
| 3702 | func appendFloatNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3703 | v := *p.Float32() |
| 3704 | if v == 0 && !math.Signbit(float64(v)) { |
| 3705 | return b, nil |
| 3706 | } |
| 3707 | b = protowire.AppendVarint(b, f.wiretag) |
| 3708 | b = protowire.AppendFixed32(b, math.Float32bits(v)) |
| 3709 | return b, nil |
| 3710 | } |
| 3711 | |
| 3712 | var coderFloatNoZero = pointerCoderFuncs{ |
| 3713 | size: sizeFloatNoZero, |
| 3714 | marshal: appendFloatNoZero, |
| 3715 | unmarshal: consumeFloat, |
| 3716 | merge: mergeFloat32NoZero, |
| 3717 | } |
| 3718 | |
| 3719 | // sizeFloatPtr returns the size of wire encoding a *float32 pointer as a Float. |
| 3720 | // It panics if the pointer is nil. |
| 3721 | func sizeFloatPtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3722 | return f.tagsize + protowire.SizeFixed32() |
| 3723 | } |
| 3724 | |
| 3725 | // appendFloatPtr wire encodes a *float32 pointer as a Float. |
| 3726 | // It panics if the pointer is nil. |
| 3727 | func appendFloatPtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3728 | v := **p.Float32Ptr() |
| 3729 | b = protowire.AppendVarint(b, f.wiretag) |
| 3730 | b = protowire.AppendFixed32(b, math.Float32bits(v)) |
| 3731 | return b, nil |
| 3732 | } |
| 3733 | |
| 3734 | // consumeFloatPtr wire decodes a *float32 pointer as a Float. |
| 3735 | func consumeFloatPtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 3736 | if wtyp != protowire.Fixed32Type { |
| 3737 | return out, errUnknown |
| 3738 | } |
| 3739 | v, n := protowire.ConsumeFixed32(b) |
| 3740 | if n < 0 { |
| 3741 | return out, errDecode |
| 3742 | } |
| 3743 | vp := p.Float32Ptr() |
| 3744 | if *vp == nil { |
| 3745 | *vp = new(float32) |
| 3746 | } |
| 3747 | **vp = math.Float32frombits(v) |
| 3748 | out.n = n |
| 3749 | return out, nil |
| 3750 | } |
| 3751 | |
| 3752 | var coderFloatPtr = pointerCoderFuncs{ |
| 3753 | size: sizeFloatPtr, |
| 3754 | marshal: appendFloatPtr, |
| 3755 | unmarshal: consumeFloatPtr, |
| 3756 | merge: mergeFloat32Ptr, |
| 3757 | } |
| 3758 | |
| 3759 | // sizeFloatSlice returns the size of wire encoding a []float32 pointer as a repeated Float. |
| 3760 | func sizeFloatSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3761 | s := *p.Float32Slice() |
| 3762 | size = len(s) * (f.tagsize + protowire.SizeFixed32()) |
| 3763 | return size |
| 3764 | } |
| 3765 | |
| 3766 | // appendFloatSlice encodes a []float32 pointer as a repeated Float. |
| 3767 | func appendFloatSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3768 | s := *p.Float32Slice() |
| 3769 | for _, v := range s { |
| 3770 | b = protowire.AppendVarint(b, f.wiretag) |
| 3771 | b = protowire.AppendFixed32(b, math.Float32bits(v)) |
| 3772 | } |
| 3773 | return b, nil |
| 3774 | } |
| 3775 | |
| 3776 | // consumeFloatSlice wire decodes a []float32 pointer as a repeated Float. |
| 3777 | func consumeFloatSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 3778 | sp := p.Float32Slice() |
| 3779 | if wtyp == protowire.BytesType { |
| 3780 | s := *sp |
| 3781 | b, n := protowire.ConsumeBytes(b) |
| 3782 | if n < 0 { |
| 3783 | return out, errDecode |
| 3784 | } |
| 3785 | for len(b) > 0 { |
| 3786 | v, n := protowire.ConsumeFixed32(b) |
| 3787 | if n < 0 { |
| 3788 | return out, errDecode |
| 3789 | } |
| 3790 | s = append(s, math.Float32frombits(v)) |
| 3791 | b = b[n:] |
| 3792 | } |
| 3793 | *sp = s |
| 3794 | out.n = n |
| 3795 | return out, nil |
| 3796 | } |
| 3797 | if wtyp != protowire.Fixed32Type { |
| 3798 | return out, errUnknown |
| 3799 | } |
| 3800 | v, n := protowire.ConsumeFixed32(b) |
| 3801 | if n < 0 { |
| 3802 | return out, errDecode |
| 3803 | } |
| 3804 | *sp = append(*sp, math.Float32frombits(v)) |
| 3805 | out.n = n |
| 3806 | return out, nil |
| 3807 | } |
| 3808 | |
| 3809 | var coderFloatSlice = pointerCoderFuncs{ |
| 3810 | size: sizeFloatSlice, |
| 3811 | marshal: appendFloatSlice, |
| 3812 | unmarshal: consumeFloatSlice, |
| 3813 | merge: mergeFloat32Slice, |
| 3814 | } |
| 3815 | |
| 3816 | // sizeFloatPackedSlice returns the size of wire encoding a []float32 pointer as a packed repeated Float. |
| 3817 | func sizeFloatPackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3818 | s := *p.Float32Slice() |
| 3819 | if len(s) == 0 { |
| 3820 | return 0 |
| 3821 | } |
| 3822 | n := len(s) * protowire.SizeFixed32() |
| 3823 | return f.tagsize + protowire.SizeBytes(n) |
| 3824 | } |
| 3825 | |
| 3826 | // appendFloatPackedSlice encodes a []float32 pointer as a packed repeated Float. |
| 3827 | func appendFloatPackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3828 | s := *p.Float32Slice() |
| 3829 | if len(s) == 0 { |
| 3830 | return b, nil |
| 3831 | } |
| 3832 | b = protowire.AppendVarint(b, f.wiretag) |
| 3833 | n := len(s) * protowire.SizeFixed32() |
| 3834 | b = protowire.AppendVarint(b, uint64(n)) |
| 3835 | for _, v := range s { |
| 3836 | b = protowire.AppendFixed32(b, math.Float32bits(v)) |
| 3837 | } |
| 3838 | return b, nil |
| 3839 | } |
| 3840 | |
| 3841 | var coderFloatPackedSlice = pointerCoderFuncs{ |
| 3842 | size: sizeFloatPackedSlice, |
| 3843 | marshal: appendFloatPackedSlice, |
| 3844 | unmarshal: consumeFloatSlice, |
| 3845 | merge: mergeFloat32Slice, |
| 3846 | } |
| 3847 | |
| 3848 | // sizeFloatValue returns the size of wire encoding a float32 value as a Float. |
| 3849 | func sizeFloatValue(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 3850 | return tagsize + protowire.SizeFixed32() |
| 3851 | } |
| 3852 | |
| 3853 | // appendFloatValue encodes a float32 value as a Float. |
| 3854 | func appendFloatValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 3855 | b = protowire.AppendVarint(b, wiretag) |
| 3856 | b = protowire.AppendFixed32(b, math.Float32bits(float32(v.Float()))) |
| 3857 | return b, nil |
| 3858 | } |
| 3859 | |
| 3860 | // consumeFloatValue decodes a float32 value as a Float. |
| 3861 | func consumeFloatValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 3862 | if wtyp != protowire.Fixed32Type { |
| 3863 | return protoreflect.Value{}, out, errUnknown |
| 3864 | } |
| 3865 | v, n := protowire.ConsumeFixed32(b) |
| 3866 | if n < 0 { |
| 3867 | return protoreflect.Value{}, out, errDecode |
| 3868 | } |
| 3869 | out.n = n |
| 3870 | return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), out, nil |
| 3871 | } |
| 3872 | |
| 3873 | var coderFloatValue = valueCoderFuncs{ |
| 3874 | size: sizeFloatValue, |
| 3875 | marshal: appendFloatValue, |
| 3876 | unmarshal: consumeFloatValue, |
| 3877 | merge: mergeScalarValue, |
| 3878 | } |
|