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 | } |
| 3879 | |
| 3880 | // sizeFloatSliceValue returns the size of wire encoding a []float32 value as a repeated Float. |
| 3881 | func sizeFloatSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 3882 | list := listv.List() |
| 3883 | size = list.Len() * (tagsize + protowire.SizeFixed32()) |
| 3884 | return size |
| 3885 | } |
| 3886 | |
| 3887 | // appendFloatSliceValue encodes a []float32 value as a repeated Float. |
| 3888 | func appendFloatSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 3889 | list := listv.List() |
| 3890 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 3891 | v := list.Get(i) |
| 3892 | b = protowire.AppendVarint(b, wiretag) |
| 3893 | b = protowire.AppendFixed32(b, math.Float32bits(float32(v.Float()))) |
| 3894 | } |
| 3895 | return b, nil |
| 3896 | } |
| 3897 | |
| 3898 | // consumeFloatSliceValue wire decodes a []float32 value as a repeated Float. |
| 3899 | func consumeFloatSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 3900 | list := listv.List() |
| 3901 | if wtyp == protowire.BytesType { |
| 3902 | b, n := protowire.ConsumeBytes(b) |
| 3903 | if n < 0 { |
| 3904 | return protoreflect.Value{}, out, errDecode |
| 3905 | } |
| 3906 | for len(b) > 0 { |
| 3907 | v, n := protowire.ConsumeFixed32(b) |
| 3908 | if n < 0 { |
| 3909 | return protoreflect.Value{}, out, errDecode |
| 3910 | } |
| 3911 | list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v)))) |
| 3912 | b = b[n:] |
| 3913 | } |
| 3914 | out.n = n |
| 3915 | return listv, out, nil |
| 3916 | } |
| 3917 | if wtyp != protowire.Fixed32Type { |
| 3918 | return protoreflect.Value{}, out, errUnknown |
| 3919 | } |
| 3920 | v, n := protowire.ConsumeFixed32(b) |
| 3921 | if n < 0 { |
| 3922 | return protoreflect.Value{}, out, errDecode |
| 3923 | } |
| 3924 | list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v)))) |
| 3925 | out.n = n |
| 3926 | return listv, out, nil |
| 3927 | } |
| 3928 | |
| 3929 | var coderFloatSliceValue = valueCoderFuncs{ |
| 3930 | size: sizeFloatSliceValue, |
| 3931 | marshal: appendFloatSliceValue, |
| 3932 | unmarshal: consumeFloatSliceValue, |
| 3933 | merge: mergeListValue, |
| 3934 | } |
| 3935 | |
| 3936 | // sizeFloatPackedSliceValue returns the size of wire encoding a []float32 value as a packed repeated Float. |
| 3937 | func sizeFloatPackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 3938 | list := listv.List() |
| 3939 | llen := list.Len() |
| 3940 | if llen == 0 { |
| 3941 | return 0 |
| 3942 | } |
| 3943 | n := llen * protowire.SizeFixed32() |
| 3944 | return tagsize + protowire.SizeBytes(n) |
| 3945 | } |
| 3946 | |
| 3947 | // appendFloatPackedSliceValue encodes a []float32 value as a packed repeated Float. |
| 3948 | func appendFloatPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 3949 | list := listv.List() |
| 3950 | llen := list.Len() |
| 3951 | if llen == 0 { |
| 3952 | return b, nil |
| 3953 | } |
| 3954 | b = protowire.AppendVarint(b, wiretag) |
| 3955 | n := llen * protowire.SizeFixed32() |
| 3956 | b = protowire.AppendVarint(b, uint64(n)) |
| 3957 | for i := 0; i < llen; i++ { |
| 3958 | v := list.Get(i) |
| 3959 | b = protowire.AppendFixed32(b, math.Float32bits(float32(v.Float()))) |
| 3960 | } |
| 3961 | return b, nil |
| 3962 | } |
| 3963 | |
| 3964 | var coderFloatPackedSliceValue = valueCoderFuncs{ |
| 3965 | size: sizeFloatPackedSliceValue, |
| 3966 | marshal: appendFloatPackedSliceValue, |
| 3967 | unmarshal: consumeFloatSliceValue, |
| 3968 | merge: mergeListValue, |
| 3969 | } |
| 3970 | |
| 3971 | // sizeSfixed64 returns the size of wire encoding a int64 pointer as a Sfixed64. |
| 3972 | func sizeSfixed64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 3973 | |
| 3974 | return f.tagsize + protowire.SizeFixed64() |
| 3975 | } |
| 3976 | |
| 3977 | // appendSfixed64 wire encodes a int64 pointer as a Sfixed64. |
| 3978 | func appendSfixed64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 3979 | v := *p.Int64() |
| 3980 | b = protowire.AppendVarint(b, f.wiretag) |
| 3981 | b = protowire.AppendFixed64(b, uint64(v)) |
| 3982 | return b, nil |
| 3983 | } |
| 3984 | |
| 3985 | // consumeSfixed64 wire decodes a int64 pointer as a Sfixed64. |
| 3986 | func consumeSfixed64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 3987 | if wtyp != protowire.Fixed64Type { |
| 3988 | return out, errUnknown |
| 3989 | } |
| 3990 | v, n := protowire.ConsumeFixed64(b) |
| 3991 | if n < 0 { |
| 3992 | return out, errDecode |
| 3993 | } |
| 3994 | *p.Int64() = int64(v) |
| 3995 | out.n = n |
| 3996 | return out, nil |
| 3997 | } |
| 3998 | |
| 3999 | var coderSfixed64 = pointerCoderFuncs{ |
| 4000 | size: sizeSfixed64, |
| 4001 | marshal: appendSfixed64, |
| 4002 | unmarshal: consumeSfixed64, |
| 4003 | merge: mergeInt64, |
| 4004 | } |
| 4005 | |
| 4006 | // sizeSfixed64NoZero returns the size of wire encoding a int64 pointer as a Sfixed64. |
| 4007 | // The zero value is not encoded. |
| 4008 | func sizeSfixed64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4009 | v := *p.Int64() |
| 4010 | if v == 0 { |
| 4011 | return 0 |
| 4012 | } |
| 4013 | return f.tagsize + protowire.SizeFixed64() |
| 4014 | } |
| 4015 | |
| 4016 | // appendSfixed64NoZero wire encodes a int64 pointer as a Sfixed64. |
| 4017 | // The zero value is not encoded. |
| 4018 | func appendSfixed64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4019 | v := *p.Int64() |
| 4020 | if v == 0 { |
| 4021 | return b, nil |
| 4022 | } |
| 4023 | b = protowire.AppendVarint(b, f.wiretag) |
| 4024 | b = protowire.AppendFixed64(b, uint64(v)) |
| 4025 | return b, nil |
| 4026 | } |
| 4027 | |
| 4028 | var coderSfixed64NoZero = pointerCoderFuncs{ |
| 4029 | size: sizeSfixed64NoZero, |
| 4030 | marshal: appendSfixed64NoZero, |
| 4031 | unmarshal: consumeSfixed64, |
| 4032 | merge: mergeInt64NoZero, |
| 4033 | } |
| 4034 | |
| 4035 | // sizeSfixed64Ptr returns the size of wire encoding a *int64 pointer as a Sfixed64. |
| 4036 | // It panics if the pointer is nil. |
| 4037 | func sizeSfixed64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4038 | return f.tagsize + protowire.SizeFixed64() |
| 4039 | } |
| 4040 | |
| 4041 | // appendSfixed64Ptr wire encodes a *int64 pointer as a Sfixed64. |
| 4042 | // It panics if the pointer is nil. |
| 4043 | func appendSfixed64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4044 | v := **p.Int64Ptr() |
| 4045 | b = protowire.AppendVarint(b, f.wiretag) |
| 4046 | b = protowire.AppendFixed64(b, uint64(v)) |
| 4047 | return b, nil |
| 4048 | } |
| 4049 | |
| 4050 | // consumeSfixed64Ptr wire decodes a *int64 pointer as a Sfixed64. |
| 4051 | func consumeSfixed64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 4052 | if wtyp != protowire.Fixed64Type { |
| 4053 | return out, errUnknown |
| 4054 | } |
| 4055 | v, n := protowire.ConsumeFixed64(b) |
| 4056 | if n < 0 { |
| 4057 | return out, errDecode |
| 4058 | } |
| 4059 | vp := p.Int64Ptr() |
| 4060 | if *vp == nil { |
| 4061 | *vp = new(int64) |
| 4062 | } |
| 4063 | **vp = int64(v) |
| 4064 | out.n = n |
| 4065 | return out, nil |
| 4066 | } |
| 4067 | |
| 4068 | var coderSfixed64Ptr = pointerCoderFuncs{ |
| 4069 | size: sizeSfixed64Ptr, |
| 4070 | marshal: appendSfixed64Ptr, |
| 4071 | unmarshal: consumeSfixed64Ptr, |
| 4072 | merge: mergeInt64Ptr, |
| 4073 | } |
| 4074 | |
| 4075 | // sizeSfixed64Slice returns the size of wire encoding a []int64 pointer as a repeated Sfixed64. |
| 4076 | func sizeSfixed64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4077 | s := *p.Int64Slice() |
| 4078 | size = len(s) * (f.tagsize + protowire.SizeFixed64()) |
| 4079 | return size |
| 4080 | } |
| 4081 | |
| 4082 | // appendSfixed64Slice encodes a []int64 pointer as a repeated Sfixed64. |
| 4083 | func appendSfixed64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4084 | s := *p.Int64Slice() |
| 4085 | for _, v := range s { |
| 4086 | b = protowire.AppendVarint(b, f.wiretag) |
| 4087 | b = protowire.AppendFixed64(b, uint64(v)) |
| 4088 | } |
| 4089 | return b, nil |
| 4090 | } |
| 4091 | |
| 4092 | // consumeSfixed64Slice wire decodes a []int64 pointer as a repeated Sfixed64. |
| 4093 | func consumeSfixed64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 4094 | sp := p.Int64Slice() |
| 4095 | if wtyp == protowire.BytesType { |
| 4096 | s := *sp |
| 4097 | b, n := protowire.ConsumeBytes(b) |
| 4098 | if n < 0 { |
| 4099 | return out, errDecode |
| 4100 | } |
| 4101 | for len(b) > 0 { |
| 4102 | v, n := protowire.ConsumeFixed64(b) |
| 4103 | if n < 0 { |
| 4104 | return out, errDecode |
| 4105 | } |
| 4106 | s = append(s, int64(v)) |
| 4107 | b = b[n:] |
| 4108 | } |
| 4109 | *sp = s |
| 4110 | out.n = n |
| 4111 | return out, nil |
| 4112 | } |
| 4113 | if wtyp != protowire.Fixed64Type { |
| 4114 | return out, errUnknown |
| 4115 | } |
| 4116 | v, n := protowire.ConsumeFixed64(b) |
| 4117 | if n < 0 { |
| 4118 | return out, errDecode |
| 4119 | } |
| 4120 | *sp = append(*sp, int64(v)) |
| 4121 | out.n = n |
| 4122 | return out, nil |
| 4123 | } |
| 4124 | |
| 4125 | var coderSfixed64Slice = pointerCoderFuncs{ |
| 4126 | size: sizeSfixed64Slice, |
| 4127 | marshal: appendSfixed64Slice, |
| 4128 | unmarshal: consumeSfixed64Slice, |
| 4129 | merge: mergeInt64Slice, |
| 4130 | } |
| 4131 | |
| 4132 | // sizeSfixed64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sfixed64. |
| 4133 | func sizeSfixed64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4134 | s := *p.Int64Slice() |
| 4135 | if len(s) == 0 { |
| 4136 | return 0 |
| 4137 | } |
| 4138 | n := len(s) * protowire.SizeFixed64() |
| 4139 | return f.tagsize + protowire.SizeBytes(n) |
| 4140 | } |
| 4141 | |
| 4142 | // appendSfixed64PackedSlice encodes a []int64 pointer as a packed repeated Sfixed64. |
| 4143 | func appendSfixed64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4144 | s := *p.Int64Slice() |
| 4145 | if len(s) == 0 { |
| 4146 | return b, nil |
| 4147 | } |
| 4148 | b = protowire.AppendVarint(b, f.wiretag) |
| 4149 | n := len(s) * protowire.SizeFixed64() |
| 4150 | b = protowire.AppendVarint(b, uint64(n)) |
| 4151 | for _, v := range s { |
| 4152 | b = protowire.AppendFixed64(b, uint64(v)) |
| 4153 | } |
| 4154 | return b, nil |
| 4155 | } |
| 4156 | |
| 4157 | var coderSfixed64PackedSlice = pointerCoderFuncs{ |
| 4158 | size: sizeSfixed64PackedSlice, |
| 4159 | marshal: appendSfixed64PackedSlice, |
| 4160 | unmarshal: consumeSfixed64Slice, |
| 4161 | merge: mergeInt64Slice, |
| 4162 | } |
| 4163 | |
| 4164 | // sizeSfixed64Value returns the size of wire encoding a int64 value as a Sfixed64. |
| 4165 | func sizeSfixed64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 4166 | return tagsize + protowire.SizeFixed64() |
| 4167 | } |
| 4168 | |
| 4169 | // appendSfixed64Value encodes a int64 value as a Sfixed64. |
| 4170 | func appendSfixed64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 4171 | b = protowire.AppendVarint(b, wiretag) |
| 4172 | b = protowire.AppendFixed64(b, uint64(v.Int())) |
| 4173 | return b, nil |
| 4174 | } |
| 4175 | |
| 4176 | // consumeSfixed64Value decodes a int64 value as a Sfixed64. |
| 4177 | func consumeSfixed64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 4178 | if wtyp != protowire.Fixed64Type { |
| 4179 | return protoreflect.Value{}, out, errUnknown |
| 4180 | } |
| 4181 | v, n := protowire.ConsumeFixed64(b) |
| 4182 | if n < 0 { |
| 4183 | return protoreflect.Value{}, out, errDecode |
| 4184 | } |
| 4185 | out.n = n |
| 4186 | return protoreflect.ValueOfInt64(int64(v)), out, nil |
| 4187 | } |
| 4188 | |
| 4189 | var coderSfixed64Value = valueCoderFuncs{ |
| 4190 | size: sizeSfixed64Value, |
| 4191 | marshal: appendSfixed64Value, |
| 4192 | unmarshal: consumeSfixed64Value, |
| 4193 | merge: mergeScalarValue, |
| 4194 | } |
| 4195 | |
| 4196 | // sizeSfixed64SliceValue returns the size of wire encoding a []int64 value as a repeated Sfixed64. |
| 4197 | func sizeSfixed64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 4198 | list := listv.List() |
| 4199 | size = list.Len() * (tagsize + protowire.SizeFixed64()) |
| 4200 | return size |
| 4201 | } |
| 4202 | |
| 4203 | // appendSfixed64SliceValue encodes a []int64 value as a repeated Sfixed64. |
| 4204 | func appendSfixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 4205 | list := listv.List() |
| 4206 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 4207 | v := list.Get(i) |
| 4208 | b = protowire.AppendVarint(b, wiretag) |
| 4209 | b = protowire.AppendFixed64(b, uint64(v.Int())) |
| 4210 | } |
| 4211 | return b, nil |
| 4212 | } |
| 4213 | |
| 4214 | // consumeSfixed64SliceValue wire decodes a []int64 value as a repeated Sfixed64. |
| 4215 | func consumeSfixed64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 4216 | list := listv.List() |
| 4217 | if wtyp == protowire.BytesType { |
| 4218 | b, n := protowire.ConsumeBytes(b) |
| 4219 | if n < 0 { |
| 4220 | return protoreflect.Value{}, out, errDecode |
| 4221 | } |
| 4222 | for len(b) > 0 { |
| 4223 | v, n := protowire.ConsumeFixed64(b) |
| 4224 | if n < 0 { |
| 4225 | return protoreflect.Value{}, out, errDecode |
| 4226 | } |
| 4227 | list.Append(protoreflect.ValueOfInt64(int64(v))) |
| 4228 | b = b[n:] |
| 4229 | } |
| 4230 | out.n = n |
| 4231 | return listv, out, nil |
| 4232 | } |
| 4233 | if wtyp != protowire.Fixed64Type { |
| 4234 | return protoreflect.Value{}, out, errUnknown |
| 4235 | } |
| 4236 | v, n := protowire.ConsumeFixed64(b) |
| 4237 | if n < 0 { |
| 4238 | return protoreflect.Value{}, out, errDecode |
| 4239 | } |
| 4240 | list.Append(protoreflect.ValueOfInt64(int64(v))) |
| 4241 | out.n = n |
| 4242 | return listv, out, nil |
| 4243 | } |
| 4244 | |
| 4245 | var coderSfixed64SliceValue = valueCoderFuncs{ |
| 4246 | size: sizeSfixed64SliceValue, |
| 4247 | marshal: appendSfixed64SliceValue, |
| 4248 | unmarshal: consumeSfixed64SliceValue, |
| 4249 | merge: mergeListValue, |
| 4250 | } |
| 4251 | |
| 4252 | // sizeSfixed64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sfixed64. |
| 4253 | func sizeSfixed64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 4254 | list := listv.List() |
| 4255 | llen := list.Len() |
| 4256 | if llen == 0 { |
| 4257 | return 0 |
| 4258 | } |
| 4259 | n := llen * protowire.SizeFixed64() |
| 4260 | return tagsize + protowire.SizeBytes(n) |
| 4261 | } |
| 4262 | |
| 4263 | // appendSfixed64PackedSliceValue encodes a []int64 value as a packed repeated Sfixed64. |
| 4264 | func appendSfixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 4265 | list := listv.List() |
| 4266 | llen := list.Len() |
| 4267 | if llen == 0 { |
| 4268 | return b, nil |
| 4269 | } |
| 4270 | b = protowire.AppendVarint(b, wiretag) |
| 4271 | n := llen * protowire.SizeFixed64() |
| 4272 | b = protowire.AppendVarint(b, uint64(n)) |
| 4273 | for i := 0; i < llen; i++ { |
| 4274 | v := list.Get(i) |
| 4275 | b = protowire.AppendFixed64(b, uint64(v.Int())) |
| 4276 | } |
| 4277 | return b, nil |
| 4278 | } |
| 4279 | |
| 4280 | var coderSfixed64PackedSliceValue = valueCoderFuncs{ |
| 4281 | size: sizeSfixed64PackedSliceValue, |
| 4282 | marshal: appendSfixed64PackedSliceValue, |
| 4283 | unmarshal: consumeSfixed64SliceValue, |
| 4284 | merge: mergeListValue, |
| 4285 | } |
| 4286 | |
| 4287 | // sizeFixed64 returns the size of wire encoding a uint64 pointer as a Fixed64. |
| 4288 | func sizeFixed64(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4289 | |
| 4290 | return f.tagsize + protowire.SizeFixed64() |
| 4291 | } |
| 4292 | |
| 4293 | // appendFixed64 wire encodes a uint64 pointer as a Fixed64. |
| 4294 | func appendFixed64(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4295 | v := *p.Uint64() |
| 4296 | b = protowire.AppendVarint(b, f.wiretag) |
| 4297 | b = protowire.AppendFixed64(b, v) |
| 4298 | return b, nil |
| 4299 | } |
| 4300 | |
| 4301 | // consumeFixed64 wire decodes a uint64 pointer as a Fixed64. |
| 4302 | func consumeFixed64(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 4303 | if wtyp != protowire.Fixed64Type { |
| 4304 | return out, errUnknown |
| 4305 | } |
| 4306 | v, n := protowire.ConsumeFixed64(b) |
| 4307 | if n < 0 { |
| 4308 | return out, errDecode |
| 4309 | } |
| 4310 | *p.Uint64() = v |
| 4311 | out.n = n |
| 4312 | return out, nil |
| 4313 | } |
| 4314 | |
| 4315 | var coderFixed64 = pointerCoderFuncs{ |
| 4316 | size: sizeFixed64, |
| 4317 | marshal: appendFixed64, |
| 4318 | unmarshal: consumeFixed64, |
| 4319 | merge: mergeUint64, |
| 4320 | } |
| 4321 | |
| 4322 | // sizeFixed64NoZero returns the size of wire encoding a uint64 pointer as a Fixed64. |
| 4323 | // The zero value is not encoded. |
| 4324 | func sizeFixed64NoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4325 | v := *p.Uint64() |
| 4326 | if v == 0 { |
| 4327 | return 0 |
| 4328 | } |
| 4329 | return f.tagsize + protowire.SizeFixed64() |
| 4330 | } |
| 4331 | |
| 4332 | // appendFixed64NoZero wire encodes a uint64 pointer as a Fixed64. |
| 4333 | // The zero value is not encoded. |
| 4334 | func appendFixed64NoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4335 | v := *p.Uint64() |
| 4336 | if v == 0 { |
| 4337 | return b, nil |
| 4338 | } |
| 4339 | b = protowire.AppendVarint(b, f.wiretag) |
| 4340 | b = protowire.AppendFixed64(b, v) |
| 4341 | return b, nil |
| 4342 | } |
| 4343 | |
| 4344 | var coderFixed64NoZero = pointerCoderFuncs{ |
| 4345 | size: sizeFixed64NoZero, |
| 4346 | marshal: appendFixed64NoZero, |
| 4347 | unmarshal: consumeFixed64, |
| 4348 | merge: mergeUint64NoZero, |
| 4349 | } |
| 4350 | |
| 4351 | // sizeFixed64Ptr returns the size of wire encoding a *uint64 pointer as a Fixed64. |
| 4352 | // It panics if the pointer is nil. |
| 4353 | func sizeFixed64Ptr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4354 | return f.tagsize + protowire.SizeFixed64() |
| 4355 | } |
| 4356 | |
| 4357 | // appendFixed64Ptr wire encodes a *uint64 pointer as a Fixed64. |
| 4358 | // It panics if the pointer is nil. |
| 4359 | func appendFixed64Ptr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4360 | v := **p.Uint64Ptr() |
| 4361 | b = protowire.AppendVarint(b, f.wiretag) |
| 4362 | b = protowire.AppendFixed64(b, v) |
| 4363 | return b, nil |
| 4364 | } |
| 4365 | |
| 4366 | // consumeFixed64Ptr wire decodes a *uint64 pointer as a Fixed64. |
| 4367 | func consumeFixed64Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 4368 | if wtyp != protowire.Fixed64Type { |
| 4369 | return out, errUnknown |
| 4370 | } |
| 4371 | v, n := protowire.ConsumeFixed64(b) |
| 4372 | if n < 0 { |
| 4373 | return out, errDecode |
| 4374 | } |
| 4375 | vp := p.Uint64Ptr() |
| 4376 | if *vp == nil { |
| 4377 | *vp = new(uint64) |
| 4378 | } |
| 4379 | **vp = v |
| 4380 | out.n = n |
| 4381 | return out, nil |
| 4382 | } |
| 4383 | |
| 4384 | var coderFixed64Ptr = pointerCoderFuncs{ |
| 4385 | size: sizeFixed64Ptr, |
| 4386 | marshal: appendFixed64Ptr, |
| 4387 | unmarshal: consumeFixed64Ptr, |
| 4388 | merge: mergeUint64Ptr, |
| 4389 | } |
| 4390 | |
| 4391 | // sizeFixed64Slice returns the size of wire encoding a []uint64 pointer as a repeated Fixed64. |
| 4392 | func sizeFixed64Slice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4393 | s := *p.Uint64Slice() |
| 4394 | size = len(s) * (f.tagsize + protowire.SizeFixed64()) |
| 4395 | return size |
| 4396 | } |
| 4397 | |
| 4398 | // appendFixed64Slice encodes a []uint64 pointer as a repeated Fixed64. |
| 4399 | func appendFixed64Slice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4400 | s := *p.Uint64Slice() |
| 4401 | for _, v := range s { |
| 4402 | b = protowire.AppendVarint(b, f.wiretag) |
| 4403 | b = protowire.AppendFixed64(b, v) |
| 4404 | } |
| 4405 | return b, nil |
| 4406 | } |
| 4407 | |
| 4408 | // consumeFixed64Slice wire decodes a []uint64 pointer as a repeated Fixed64. |
| 4409 | func consumeFixed64Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 4410 | sp := p.Uint64Slice() |
| 4411 | if wtyp == protowire.BytesType { |
| 4412 | s := *sp |
| 4413 | b, n := protowire.ConsumeBytes(b) |
| 4414 | if n < 0 { |
| 4415 | return out, errDecode |
| 4416 | } |
| 4417 | for len(b) > 0 { |
| 4418 | v, n := protowire.ConsumeFixed64(b) |
| 4419 | if n < 0 { |
| 4420 | return out, errDecode |
| 4421 | } |
| 4422 | s = append(s, v) |
| 4423 | b = b[n:] |
| 4424 | } |
| 4425 | *sp = s |
| 4426 | out.n = n |
| 4427 | return out, nil |
| 4428 | } |
| 4429 | if wtyp != protowire.Fixed64Type { |
| 4430 | return out, errUnknown |
| 4431 | } |
| 4432 | v, n := protowire.ConsumeFixed64(b) |
| 4433 | if n < 0 { |
| 4434 | return out, errDecode |
| 4435 | } |
| 4436 | *sp = append(*sp, v) |
| 4437 | out.n = n |
| 4438 | return out, nil |
| 4439 | } |
| 4440 | |
| 4441 | var coderFixed64Slice = pointerCoderFuncs{ |
| 4442 | size: sizeFixed64Slice, |
| 4443 | marshal: appendFixed64Slice, |
| 4444 | unmarshal: consumeFixed64Slice, |
| 4445 | merge: mergeUint64Slice, |
| 4446 | } |
| 4447 | |
| 4448 | // sizeFixed64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Fixed64. |
| 4449 | func sizeFixed64PackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4450 | s := *p.Uint64Slice() |
| 4451 | if len(s) == 0 { |
| 4452 | return 0 |
| 4453 | } |
| 4454 | n := len(s) * protowire.SizeFixed64() |
| 4455 | return f.tagsize + protowire.SizeBytes(n) |
| 4456 | } |
| 4457 | |
| 4458 | // appendFixed64PackedSlice encodes a []uint64 pointer as a packed repeated Fixed64. |
| 4459 | func appendFixed64PackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4460 | s := *p.Uint64Slice() |
| 4461 | if len(s) == 0 { |
| 4462 | return b, nil |
| 4463 | } |
| 4464 | b = protowire.AppendVarint(b, f.wiretag) |
| 4465 | n := len(s) * protowire.SizeFixed64() |
| 4466 | b = protowire.AppendVarint(b, uint64(n)) |
| 4467 | for _, v := range s { |
| 4468 | b = protowire.AppendFixed64(b, v) |
| 4469 | } |
| 4470 | return b, nil |
| 4471 | } |
| 4472 | |
| 4473 | var coderFixed64PackedSlice = pointerCoderFuncs{ |
| 4474 | size: sizeFixed64PackedSlice, |
| 4475 | marshal: appendFixed64PackedSlice, |
| 4476 | unmarshal: consumeFixed64Slice, |
| 4477 | merge: mergeUint64Slice, |
| 4478 | } |
| 4479 | |
| 4480 | // sizeFixed64Value returns the size of wire encoding a uint64 value as a Fixed64. |
| 4481 | func sizeFixed64Value(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 4482 | return tagsize + protowire.SizeFixed64() |
| 4483 | } |
| 4484 | |
| 4485 | // appendFixed64Value encodes a uint64 value as a Fixed64. |
| 4486 | func appendFixed64Value(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 4487 | b = protowire.AppendVarint(b, wiretag) |
| 4488 | b = protowire.AppendFixed64(b, v.Uint()) |
| 4489 | return b, nil |
| 4490 | } |
| 4491 | |
| 4492 | // consumeFixed64Value decodes a uint64 value as a Fixed64. |
| 4493 | func consumeFixed64Value(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 4494 | if wtyp != protowire.Fixed64Type { |
| 4495 | return protoreflect.Value{}, out, errUnknown |
| 4496 | } |
| 4497 | v, n := protowire.ConsumeFixed64(b) |
| 4498 | if n < 0 { |
| 4499 | return protoreflect.Value{}, out, errDecode |
| 4500 | } |
| 4501 | out.n = n |
| 4502 | return protoreflect.ValueOfUint64(v), out, nil |
| 4503 | } |
| 4504 | |
| 4505 | var coderFixed64Value = valueCoderFuncs{ |
| 4506 | size: sizeFixed64Value, |
| 4507 | marshal: appendFixed64Value, |
| 4508 | unmarshal: consumeFixed64Value, |
| 4509 | merge: mergeScalarValue, |
| 4510 | } |
| 4511 | |
| 4512 | // sizeFixed64SliceValue returns the size of wire encoding a []uint64 value as a repeated Fixed64. |
| 4513 | func sizeFixed64SliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 4514 | list := listv.List() |
| 4515 | size = list.Len() * (tagsize + protowire.SizeFixed64()) |
| 4516 | return size |
| 4517 | } |
| 4518 | |
| 4519 | // appendFixed64SliceValue encodes a []uint64 value as a repeated Fixed64. |
| 4520 | func appendFixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 4521 | list := listv.List() |
| 4522 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 4523 | v := list.Get(i) |
| 4524 | b = protowire.AppendVarint(b, wiretag) |
| 4525 | b = protowire.AppendFixed64(b, v.Uint()) |
| 4526 | } |
| 4527 | return b, nil |
| 4528 | } |
| 4529 | |
| 4530 | // consumeFixed64SliceValue wire decodes a []uint64 value as a repeated Fixed64. |
| 4531 | func consumeFixed64SliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 4532 | list := listv.List() |
| 4533 | if wtyp == protowire.BytesType { |
| 4534 | b, n := protowire.ConsumeBytes(b) |
| 4535 | if n < 0 { |
| 4536 | return protoreflect.Value{}, out, errDecode |
| 4537 | } |
| 4538 | for len(b) > 0 { |
| 4539 | v, n := protowire.ConsumeFixed64(b) |
| 4540 | if n < 0 { |
| 4541 | return protoreflect.Value{}, out, errDecode |
| 4542 | } |
| 4543 | list.Append(protoreflect.ValueOfUint64(v)) |
| 4544 | b = b[n:] |
| 4545 | } |
| 4546 | out.n = n |
| 4547 | return listv, out, nil |
| 4548 | } |
| 4549 | if wtyp != protowire.Fixed64Type { |
| 4550 | return protoreflect.Value{}, out, errUnknown |
| 4551 | } |
| 4552 | v, n := protowire.ConsumeFixed64(b) |
| 4553 | if n < 0 { |
| 4554 | return protoreflect.Value{}, out, errDecode |
| 4555 | } |
| 4556 | list.Append(protoreflect.ValueOfUint64(v)) |
| 4557 | out.n = n |
| 4558 | return listv, out, nil |
| 4559 | } |
| 4560 | |
| 4561 | var coderFixed64SliceValue = valueCoderFuncs{ |
| 4562 | size: sizeFixed64SliceValue, |
| 4563 | marshal: appendFixed64SliceValue, |
| 4564 | unmarshal: consumeFixed64SliceValue, |
| 4565 | merge: mergeListValue, |
| 4566 | } |
| 4567 | |
| 4568 | // sizeFixed64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Fixed64. |
| 4569 | func sizeFixed64PackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 4570 | list := listv.List() |
| 4571 | llen := list.Len() |
| 4572 | if llen == 0 { |
| 4573 | return 0 |
| 4574 | } |
| 4575 | n := llen * protowire.SizeFixed64() |
| 4576 | return tagsize + protowire.SizeBytes(n) |
| 4577 | } |
| 4578 | |
| 4579 | // appendFixed64PackedSliceValue encodes a []uint64 value as a packed repeated Fixed64. |
| 4580 | func appendFixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 4581 | list := listv.List() |
| 4582 | llen := list.Len() |
| 4583 | if llen == 0 { |
| 4584 | return b, nil |
| 4585 | } |
| 4586 | b = protowire.AppendVarint(b, wiretag) |
| 4587 | n := llen * protowire.SizeFixed64() |
| 4588 | b = protowire.AppendVarint(b, uint64(n)) |
| 4589 | for i := 0; i < llen; i++ { |
| 4590 | v := list.Get(i) |
| 4591 | b = protowire.AppendFixed64(b, v.Uint()) |
| 4592 | } |
| 4593 | return b, nil |
| 4594 | } |
| 4595 | |
| 4596 | var coderFixed64PackedSliceValue = valueCoderFuncs{ |
| 4597 | size: sizeFixed64PackedSliceValue, |
| 4598 | marshal: appendFixed64PackedSliceValue, |
| 4599 | unmarshal: consumeFixed64SliceValue, |
| 4600 | merge: mergeListValue, |
| 4601 | } |
| 4602 | |
| 4603 | // sizeDouble returns the size of wire encoding a float64 pointer as a Double. |
| 4604 | func sizeDouble(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4605 | |
| 4606 | return f.tagsize + protowire.SizeFixed64() |
| 4607 | } |
| 4608 | |
| 4609 | // appendDouble wire encodes a float64 pointer as a Double. |
| 4610 | func appendDouble(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4611 | v := *p.Float64() |
| 4612 | b = protowire.AppendVarint(b, f.wiretag) |
| 4613 | b = protowire.AppendFixed64(b, math.Float64bits(v)) |
| 4614 | return b, nil |
| 4615 | } |
| 4616 | |
| 4617 | // consumeDouble wire decodes a float64 pointer as a Double. |
| 4618 | func consumeDouble(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 4619 | if wtyp != protowire.Fixed64Type { |
| 4620 | return out, errUnknown |
| 4621 | } |
| 4622 | v, n := protowire.ConsumeFixed64(b) |
| 4623 | if n < 0 { |
| 4624 | return out, errDecode |
| 4625 | } |
| 4626 | *p.Float64() = math.Float64frombits(v) |
| 4627 | out.n = n |
| 4628 | return out, nil |
| 4629 | } |
| 4630 | |
| 4631 | var coderDouble = pointerCoderFuncs{ |
| 4632 | size: sizeDouble, |
| 4633 | marshal: appendDouble, |
| 4634 | unmarshal: consumeDouble, |
| 4635 | merge: mergeFloat64, |
| 4636 | } |
| 4637 | |
| 4638 | // sizeDoubleNoZero returns the size of wire encoding a float64 pointer as a Double. |
| 4639 | // The zero value is not encoded. |
| 4640 | func sizeDoubleNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4641 | v := *p.Float64() |
| 4642 | if v == 0 && !math.Signbit(float64(v)) { |
| 4643 | return 0 |
| 4644 | } |
| 4645 | return f.tagsize + protowire.SizeFixed64() |
| 4646 | } |
| 4647 | |
| 4648 | // appendDoubleNoZero wire encodes a float64 pointer as a Double. |
| 4649 | // The zero value is not encoded. |
| 4650 | func appendDoubleNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4651 | v := *p.Float64() |
| 4652 | if v == 0 && !math.Signbit(float64(v)) { |
| 4653 | return b, nil |
| 4654 | } |
| 4655 | b = protowire.AppendVarint(b, f.wiretag) |
| 4656 | b = protowire.AppendFixed64(b, math.Float64bits(v)) |
| 4657 | return b, nil |
| 4658 | } |
| 4659 | |
| 4660 | var coderDoubleNoZero = pointerCoderFuncs{ |
| 4661 | size: sizeDoubleNoZero, |
| 4662 | marshal: appendDoubleNoZero, |
| 4663 | unmarshal: consumeDouble, |
| 4664 | merge: mergeFloat64NoZero, |
| 4665 | } |
| 4666 | |
| 4667 | // sizeDoublePtr returns the size of wire encoding a *float64 pointer as a Double. |
| 4668 | // It panics if the pointer is nil. |
| 4669 | func sizeDoublePtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4670 | return f.tagsize + protowire.SizeFixed64() |
| 4671 | } |
| 4672 | |
| 4673 | // appendDoublePtr wire encodes a *float64 pointer as a Double. |
| 4674 | // It panics if the pointer is nil. |
| 4675 | func appendDoublePtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4676 | v := **p.Float64Ptr() |
| 4677 | b = protowire.AppendVarint(b, f.wiretag) |
| 4678 | b = protowire.AppendFixed64(b, math.Float64bits(v)) |
| 4679 | return b, nil |
| 4680 | } |
| 4681 | |
| 4682 | // consumeDoublePtr wire decodes a *float64 pointer as a Double. |
| 4683 | func consumeDoublePtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 4684 | if wtyp != protowire.Fixed64Type { |
| 4685 | return out, errUnknown |
| 4686 | } |
| 4687 | v, n := protowire.ConsumeFixed64(b) |
| 4688 | if n < 0 { |
| 4689 | return out, errDecode |
| 4690 | } |
| 4691 | vp := p.Float64Ptr() |
| 4692 | if *vp == nil { |
| 4693 | *vp = new(float64) |
| 4694 | } |
| 4695 | **vp = math.Float64frombits(v) |
| 4696 | out.n = n |
| 4697 | return out, nil |
| 4698 | } |
| 4699 | |
| 4700 | var coderDoublePtr = pointerCoderFuncs{ |
| 4701 | size: sizeDoublePtr, |
| 4702 | marshal: appendDoublePtr, |
| 4703 | unmarshal: consumeDoublePtr, |
| 4704 | merge: mergeFloat64Ptr, |
| 4705 | } |
| 4706 | |
| 4707 | // sizeDoubleSlice returns the size of wire encoding a []float64 pointer as a repeated Double. |
| 4708 | func sizeDoubleSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4709 | s := *p.Float64Slice() |
| 4710 | size = len(s) * (f.tagsize + protowire.SizeFixed64()) |
| 4711 | return size |
| 4712 | } |
| 4713 | |
| 4714 | // appendDoubleSlice encodes a []float64 pointer as a repeated Double. |
| 4715 | func appendDoubleSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4716 | s := *p.Float64Slice() |
| 4717 | for _, v := range s { |
| 4718 | b = protowire.AppendVarint(b, f.wiretag) |
| 4719 | b = protowire.AppendFixed64(b, math.Float64bits(v)) |
| 4720 | } |
| 4721 | return b, nil |
| 4722 | } |
| 4723 | |
| 4724 | // consumeDoubleSlice wire decodes a []float64 pointer as a repeated Double. |
| 4725 | func consumeDoubleSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 4726 | sp := p.Float64Slice() |
| 4727 | if wtyp == protowire.BytesType { |
| 4728 | s := *sp |
| 4729 | b, n := protowire.ConsumeBytes(b) |
| 4730 | if n < 0 { |
| 4731 | return out, errDecode |
| 4732 | } |
| 4733 | for len(b) > 0 { |
| 4734 | v, n := protowire.ConsumeFixed64(b) |
| 4735 | if n < 0 { |
| 4736 | return out, errDecode |
| 4737 | } |
| 4738 | s = append(s, math.Float64frombits(v)) |
| 4739 | b = b[n:] |
| 4740 | } |
| 4741 | *sp = s |
| 4742 | out.n = n |
| 4743 | return out, nil |
| 4744 | } |
| 4745 | if wtyp != protowire.Fixed64Type { |
| 4746 | return out, errUnknown |
| 4747 | } |
| 4748 | v, n := protowire.ConsumeFixed64(b) |
| 4749 | if n < 0 { |
| 4750 | return out, errDecode |
| 4751 | } |
| 4752 | *sp = append(*sp, math.Float64frombits(v)) |
| 4753 | out.n = n |
| 4754 | return out, nil |
| 4755 | } |
| 4756 | |
| 4757 | var coderDoubleSlice = pointerCoderFuncs{ |
| 4758 | size: sizeDoubleSlice, |
| 4759 | marshal: appendDoubleSlice, |
| 4760 | unmarshal: consumeDoubleSlice, |
| 4761 | merge: mergeFloat64Slice, |
| 4762 | } |
| 4763 | |
| 4764 | // sizeDoublePackedSlice returns the size of wire encoding a []float64 pointer as a packed repeated Double. |
| 4765 | func sizeDoublePackedSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4766 | s := *p.Float64Slice() |
| 4767 | if len(s) == 0 { |
| 4768 | return 0 |
| 4769 | } |
| 4770 | n := len(s) * protowire.SizeFixed64() |
| 4771 | return f.tagsize + protowire.SizeBytes(n) |
| 4772 | } |
| 4773 | |
| 4774 | // appendDoublePackedSlice encodes a []float64 pointer as a packed repeated Double. |
| 4775 | func appendDoublePackedSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4776 | s := *p.Float64Slice() |
| 4777 | if len(s) == 0 { |
| 4778 | return b, nil |
| 4779 | } |
| 4780 | b = protowire.AppendVarint(b, f.wiretag) |
| 4781 | n := len(s) * protowire.SizeFixed64() |
| 4782 | b = protowire.AppendVarint(b, uint64(n)) |
| 4783 | for _, v := range s { |
| 4784 | b = protowire.AppendFixed64(b, math.Float64bits(v)) |
| 4785 | } |
| 4786 | return b, nil |
| 4787 | } |
| 4788 | |
| 4789 | var coderDoublePackedSlice = pointerCoderFuncs{ |
| 4790 | size: sizeDoublePackedSlice, |
| 4791 | marshal: appendDoublePackedSlice, |
| 4792 | unmarshal: consumeDoubleSlice, |
| 4793 | merge: mergeFloat64Slice, |
| 4794 | } |
| 4795 | |
| 4796 | // sizeDoubleValue returns the size of wire encoding a float64 value as a Double. |
| 4797 | func sizeDoubleValue(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 4798 | return tagsize + protowire.SizeFixed64() |
| 4799 | } |
| 4800 | |
| 4801 | // appendDoubleValue encodes a float64 value as a Double. |
| 4802 | func appendDoubleValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 4803 | b = protowire.AppendVarint(b, wiretag) |
| 4804 | b = protowire.AppendFixed64(b, math.Float64bits(v.Float())) |
| 4805 | return b, nil |
| 4806 | } |
| 4807 | |
| 4808 | // consumeDoubleValue decodes a float64 value as a Double. |
| 4809 | func consumeDoubleValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 4810 | if wtyp != protowire.Fixed64Type { |
| 4811 | return protoreflect.Value{}, out, errUnknown |
| 4812 | } |
| 4813 | v, n := protowire.ConsumeFixed64(b) |
| 4814 | if n < 0 { |
| 4815 | return protoreflect.Value{}, out, errDecode |
| 4816 | } |
| 4817 | out.n = n |
| 4818 | return protoreflect.ValueOfFloat64(math.Float64frombits(v)), out, nil |
| 4819 | } |
| 4820 | |
| 4821 | var coderDoubleValue = valueCoderFuncs{ |
| 4822 | size: sizeDoubleValue, |
| 4823 | marshal: appendDoubleValue, |
| 4824 | unmarshal: consumeDoubleValue, |
| 4825 | merge: mergeScalarValue, |
| 4826 | } |
| 4827 | |
| 4828 | // sizeDoubleSliceValue returns the size of wire encoding a []float64 value as a repeated Double. |
| 4829 | func sizeDoubleSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 4830 | list := listv.List() |
| 4831 | size = list.Len() * (tagsize + protowire.SizeFixed64()) |
| 4832 | return size |
| 4833 | } |
| 4834 | |
| 4835 | // appendDoubleSliceValue encodes a []float64 value as a repeated Double. |
| 4836 | func appendDoubleSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 4837 | list := listv.List() |
| 4838 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 4839 | v := list.Get(i) |
| 4840 | b = protowire.AppendVarint(b, wiretag) |
| 4841 | b = protowire.AppendFixed64(b, math.Float64bits(v.Float())) |
| 4842 | } |
| 4843 | return b, nil |
| 4844 | } |
| 4845 | |
| 4846 | // consumeDoubleSliceValue wire decodes a []float64 value as a repeated Double. |
| 4847 | func consumeDoubleSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 4848 | list := listv.List() |
| 4849 | if wtyp == protowire.BytesType { |
| 4850 | b, n := protowire.ConsumeBytes(b) |
| 4851 | if n < 0 { |
| 4852 | return protoreflect.Value{}, out, errDecode |
| 4853 | } |
| 4854 | for len(b) > 0 { |
| 4855 | v, n := protowire.ConsumeFixed64(b) |
| 4856 | if n < 0 { |
| 4857 | return protoreflect.Value{}, out, errDecode |
| 4858 | } |
| 4859 | list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v))) |
| 4860 | b = b[n:] |
| 4861 | } |
| 4862 | out.n = n |
| 4863 | return listv, out, nil |
| 4864 | } |
| 4865 | if wtyp != protowire.Fixed64Type { |
| 4866 | return protoreflect.Value{}, out, errUnknown |
| 4867 | } |
| 4868 | v, n := protowire.ConsumeFixed64(b) |
| 4869 | if n < 0 { |
| 4870 | return protoreflect.Value{}, out, errDecode |
| 4871 | } |
| 4872 | list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v))) |
| 4873 | out.n = n |
| 4874 | return listv, out, nil |
| 4875 | } |
| 4876 | |
| 4877 | var coderDoubleSliceValue = valueCoderFuncs{ |
| 4878 | size: sizeDoubleSliceValue, |
| 4879 | marshal: appendDoubleSliceValue, |
| 4880 | unmarshal: consumeDoubleSliceValue, |
| 4881 | merge: mergeListValue, |
| 4882 | } |
| 4883 | |
| 4884 | // sizeDoublePackedSliceValue returns the size of wire encoding a []float64 value as a packed repeated Double. |
| 4885 | func sizeDoublePackedSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 4886 | list := listv.List() |
| 4887 | llen := list.Len() |
| 4888 | if llen == 0 { |
| 4889 | return 0 |
| 4890 | } |
| 4891 | n := llen * protowire.SizeFixed64() |
| 4892 | return tagsize + protowire.SizeBytes(n) |
| 4893 | } |
| 4894 | |
| 4895 | // appendDoublePackedSliceValue encodes a []float64 value as a packed repeated Double. |
| 4896 | func appendDoublePackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 4897 | list := listv.List() |
| 4898 | llen := list.Len() |
| 4899 | if llen == 0 { |
| 4900 | return b, nil |
| 4901 | } |
| 4902 | b = protowire.AppendVarint(b, wiretag) |
| 4903 | n := llen * protowire.SizeFixed64() |
| 4904 | b = protowire.AppendVarint(b, uint64(n)) |
| 4905 | for i := 0; i < llen; i++ { |
| 4906 | v := list.Get(i) |
| 4907 | b = protowire.AppendFixed64(b, math.Float64bits(v.Float())) |
| 4908 | } |
| 4909 | return b, nil |
| 4910 | } |
| 4911 | |
| 4912 | var coderDoublePackedSliceValue = valueCoderFuncs{ |
| 4913 | size: sizeDoublePackedSliceValue, |
| 4914 | marshal: appendDoublePackedSliceValue, |
| 4915 | unmarshal: consumeDoubleSliceValue, |
| 4916 | merge: mergeListValue, |
| 4917 | } |
| 4918 | |
| 4919 | // sizeString returns the size of wire encoding a string pointer as a String. |
| 4920 | func sizeString(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4921 | v := *p.String() |
| 4922 | return f.tagsize + protowire.SizeBytes(len(v)) |
| 4923 | } |
| 4924 | |
| 4925 | // appendString wire encodes a string pointer as a String. |
| 4926 | func appendString(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4927 | v := *p.String() |
| 4928 | b = protowire.AppendVarint(b, f.wiretag) |
| 4929 | b = protowire.AppendString(b, v) |
| 4930 | return b, nil |
| 4931 | } |
| 4932 | |
| 4933 | // consumeString wire decodes a string pointer as a String. |
| 4934 | func consumeString(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 4935 | if wtyp != protowire.BytesType { |
| 4936 | return out, errUnknown |
| 4937 | } |
| 4938 | v, n := protowire.ConsumeBytes(b) |
| 4939 | if n < 0 { |
| 4940 | return out, errDecode |
| 4941 | } |
| 4942 | *p.String() = string(v) |
| 4943 | out.n = n |
| 4944 | return out, nil |
| 4945 | } |
| 4946 | |
| 4947 | var coderString = pointerCoderFuncs{ |
| 4948 | size: sizeString, |
| 4949 | marshal: appendString, |
| 4950 | unmarshal: consumeString, |
| 4951 | merge: mergeString, |
| 4952 | } |
| 4953 | |
| 4954 | // appendStringValidateUTF8 wire encodes a string pointer as a String. |
| 4955 | func appendStringValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 4956 | v := *p.String() |
| 4957 | b = protowire.AppendVarint(b, f.wiretag) |
| 4958 | b = protowire.AppendString(b, v) |
| 4959 | if !utf8.ValidString(v) { |
| 4960 | return b, errInvalidUTF8{} |
| 4961 | } |
| 4962 | return b, nil |
| 4963 | } |
| 4964 | |
| 4965 | // consumeStringValidateUTF8 wire decodes a string pointer as a String. |
| 4966 | func consumeStringValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 4967 | if wtyp != protowire.BytesType { |
| 4968 | return out, errUnknown |
| 4969 | } |
| 4970 | v, n := protowire.ConsumeBytes(b) |
| 4971 | if n < 0 { |
| 4972 | return out, errDecode |
| 4973 | } |
| 4974 | if !utf8.Valid(v) { |
| 4975 | return out, errInvalidUTF8{} |
| 4976 | } |
| 4977 | *p.String() = string(v) |
| 4978 | out.n = n |
| 4979 | return out, nil |
| 4980 | } |
| 4981 | |
| 4982 | var coderStringValidateUTF8 = pointerCoderFuncs{ |
| 4983 | size: sizeString, |
| 4984 | marshal: appendStringValidateUTF8, |
| 4985 | unmarshal: consumeStringValidateUTF8, |
| 4986 | merge: mergeString, |
| 4987 | } |
| 4988 | |
| 4989 | // sizeStringNoZero returns the size of wire encoding a string pointer as a String. |
| 4990 | // The zero value is not encoded. |
| 4991 | func sizeStringNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 4992 | v := *p.String() |
| 4993 | if len(v) == 0 { |
| 4994 | return 0 |
| 4995 | } |
| 4996 | return f.tagsize + protowire.SizeBytes(len(v)) |
| 4997 | } |
| 4998 | |
| 4999 | // appendStringNoZero wire encodes a string pointer as a String. |
| 5000 | // The zero value is not encoded. |
| 5001 | func appendStringNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5002 | v := *p.String() |
| 5003 | if len(v) == 0 { |
| 5004 | return b, nil |
| 5005 | } |
| 5006 | b = protowire.AppendVarint(b, f.wiretag) |
| 5007 | b = protowire.AppendString(b, v) |
| 5008 | return b, nil |
| 5009 | } |
| 5010 | |
| 5011 | var coderStringNoZero = pointerCoderFuncs{ |
| 5012 | size: sizeStringNoZero, |
| 5013 | marshal: appendStringNoZero, |
| 5014 | unmarshal: consumeString, |
| 5015 | merge: mergeStringNoZero, |
| 5016 | } |
| 5017 | |
| 5018 | // appendStringNoZeroValidateUTF8 wire encodes a string pointer as a String. |
| 5019 | // The zero value is not encoded. |
| 5020 | func appendStringNoZeroValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5021 | v := *p.String() |
| 5022 | if len(v) == 0 { |
| 5023 | return b, nil |
| 5024 | } |
| 5025 | b = protowire.AppendVarint(b, f.wiretag) |
| 5026 | b = protowire.AppendString(b, v) |
| 5027 | if !utf8.ValidString(v) { |
| 5028 | return b, errInvalidUTF8{} |
| 5029 | } |
| 5030 | return b, nil |
| 5031 | } |
| 5032 | |
| 5033 | var coderStringNoZeroValidateUTF8 = pointerCoderFuncs{ |
| 5034 | size: sizeStringNoZero, |
| 5035 | marshal: appendStringNoZeroValidateUTF8, |
| 5036 | unmarshal: consumeStringValidateUTF8, |
| 5037 | merge: mergeStringNoZero, |
| 5038 | } |
| 5039 | |
| 5040 | // sizeStringPtr returns the size of wire encoding a *string pointer as a String. |
| 5041 | // It panics if the pointer is nil. |
| 5042 | func sizeStringPtr(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 5043 | v := **p.StringPtr() |
| 5044 | return f.tagsize + protowire.SizeBytes(len(v)) |
| 5045 | } |
| 5046 | |
| 5047 | // appendStringPtr wire encodes a *string pointer as a String. |
| 5048 | // It panics if the pointer is nil. |
| 5049 | func appendStringPtr(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5050 | v := **p.StringPtr() |
| 5051 | b = protowire.AppendVarint(b, f.wiretag) |
| 5052 | b = protowire.AppendString(b, v) |
| 5053 | return b, nil |
| 5054 | } |
| 5055 | |
| 5056 | // consumeStringPtr wire decodes a *string pointer as a String. |
| 5057 | func consumeStringPtr(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 5058 | if wtyp != protowire.BytesType { |
| 5059 | return out, errUnknown |
| 5060 | } |
| 5061 | v, n := protowire.ConsumeBytes(b) |
| 5062 | if n < 0 { |
| 5063 | return out, errDecode |
| 5064 | } |
| 5065 | vp := p.StringPtr() |
| 5066 | if *vp == nil { |
| 5067 | *vp = new(string) |
| 5068 | } |
| 5069 | **vp = string(v) |
| 5070 | out.n = n |
| 5071 | return out, nil |
| 5072 | } |
| 5073 | |
| 5074 | var coderStringPtr = pointerCoderFuncs{ |
| 5075 | size: sizeStringPtr, |
| 5076 | marshal: appendStringPtr, |
| 5077 | unmarshal: consumeStringPtr, |
| 5078 | merge: mergeStringPtr, |
| 5079 | } |
| 5080 | |
| 5081 | // appendStringPtrValidateUTF8 wire encodes a *string pointer as a String. |
| 5082 | // It panics if the pointer is nil. |
| 5083 | func appendStringPtrValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5084 | v := **p.StringPtr() |
| 5085 | b = protowire.AppendVarint(b, f.wiretag) |
| 5086 | b = protowire.AppendString(b, v) |
| 5087 | if !utf8.ValidString(v) { |
| 5088 | return b, errInvalidUTF8{} |
| 5089 | } |
| 5090 | return b, nil |
| 5091 | } |
| 5092 | |
| 5093 | // consumeStringPtrValidateUTF8 wire decodes a *string pointer as a String. |
| 5094 | func consumeStringPtrValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 5095 | if wtyp != protowire.BytesType { |
| 5096 | return out, errUnknown |
| 5097 | } |
| 5098 | v, n := protowire.ConsumeBytes(b) |
| 5099 | if n < 0 { |
| 5100 | return out, errDecode |
| 5101 | } |
| 5102 | if !utf8.Valid(v) { |
| 5103 | return out, errInvalidUTF8{} |
| 5104 | } |
| 5105 | vp := p.StringPtr() |
| 5106 | if *vp == nil { |
| 5107 | *vp = new(string) |
| 5108 | } |
| 5109 | **vp = string(v) |
| 5110 | out.n = n |
| 5111 | return out, nil |
| 5112 | } |
| 5113 | |
| 5114 | var coderStringPtrValidateUTF8 = pointerCoderFuncs{ |
| 5115 | size: sizeStringPtr, |
| 5116 | marshal: appendStringPtrValidateUTF8, |
| 5117 | unmarshal: consumeStringPtrValidateUTF8, |
| 5118 | merge: mergeStringPtr, |
| 5119 | } |
| 5120 | |
| 5121 | // sizeStringSlice returns the size of wire encoding a []string pointer as a repeated String. |
| 5122 | func sizeStringSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 5123 | s := *p.StringSlice() |
| 5124 | for _, v := range s { |
| 5125 | size += f.tagsize + protowire.SizeBytes(len(v)) |
| 5126 | } |
| 5127 | return size |
| 5128 | } |
| 5129 | |
| 5130 | // appendStringSlice encodes a []string pointer as a repeated String. |
| 5131 | func appendStringSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5132 | s := *p.StringSlice() |
| 5133 | for _, v := range s { |
| 5134 | b = protowire.AppendVarint(b, f.wiretag) |
| 5135 | b = protowire.AppendString(b, v) |
| 5136 | } |
| 5137 | return b, nil |
| 5138 | } |
| 5139 | |
| 5140 | // consumeStringSlice wire decodes a []string pointer as a repeated String. |
| 5141 | func consumeStringSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 5142 | sp := p.StringSlice() |
| 5143 | if wtyp != protowire.BytesType { |
| 5144 | return out, errUnknown |
| 5145 | } |
| 5146 | v, n := protowire.ConsumeBytes(b) |
| 5147 | if n < 0 { |
| 5148 | return out, errDecode |
| 5149 | } |
| 5150 | *sp = append(*sp, string(v)) |
| 5151 | out.n = n |
| 5152 | return out, nil |
| 5153 | } |
| 5154 | |
| 5155 | var coderStringSlice = pointerCoderFuncs{ |
| 5156 | size: sizeStringSlice, |
| 5157 | marshal: appendStringSlice, |
| 5158 | unmarshal: consumeStringSlice, |
| 5159 | merge: mergeStringSlice, |
| 5160 | } |
| 5161 | |
| 5162 | // appendStringSliceValidateUTF8 encodes a []string pointer as a repeated String. |
| 5163 | func appendStringSliceValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5164 | s := *p.StringSlice() |
| 5165 | for _, v := range s { |
| 5166 | b = protowire.AppendVarint(b, f.wiretag) |
| 5167 | b = protowire.AppendString(b, v) |
| 5168 | if !utf8.ValidString(v) { |
| 5169 | return b, errInvalidUTF8{} |
| 5170 | } |
| 5171 | } |
| 5172 | return b, nil |
| 5173 | } |
| 5174 | |
| 5175 | // consumeStringSliceValidateUTF8 wire decodes a []string pointer as a repeated String. |
| 5176 | func consumeStringSliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 5177 | if wtyp != protowire.BytesType { |
| 5178 | return out, errUnknown |
| 5179 | } |
| 5180 | v, n := protowire.ConsumeBytes(b) |
| 5181 | if n < 0 { |
| 5182 | return out, errDecode |
| 5183 | } |
| 5184 | if !utf8.Valid(v) { |
| 5185 | return out, errInvalidUTF8{} |
| 5186 | } |
| 5187 | sp := p.StringSlice() |
| 5188 | *sp = append(*sp, string(v)) |
| 5189 | out.n = n |
| 5190 | return out, nil |
| 5191 | } |
| 5192 | |
| 5193 | var coderStringSliceValidateUTF8 = pointerCoderFuncs{ |
| 5194 | size: sizeStringSlice, |
| 5195 | marshal: appendStringSliceValidateUTF8, |
| 5196 | unmarshal: consumeStringSliceValidateUTF8, |
| 5197 | merge: mergeStringSlice, |
| 5198 | } |
| 5199 | |
| 5200 | // sizeStringValue returns the size of wire encoding a string value as a String. |
| 5201 | func sizeStringValue(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 5202 | return tagsize + protowire.SizeBytes(len(v.String())) |
| 5203 | } |
| 5204 | |
| 5205 | // appendStringValue encodes a string value as a String. |
| 5206 | func appendStringValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 5207 | b = protowire.AppendVarint(b, wiretag) |
| 5208 | b = protowire.AppendString(b, v.String()) |
| 5209 | return b, nil |
| 5210 | } |
| 5211 | |
| 5212 | // consumeStringValue decodes a string value as a String. |
| 5213 | func consumeStringValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 5214 | if wtyp != protowire.BytesType { |
| 5215 | return protoreflect.Value{}, out, errUnknown |
| 5216 | } |
| 5217 | v, n := protowire.ConsumeBytes(b) |
| 5218 | if n < 0 { |
| 5219 | return protoreflect.Value{}, out, errDecode |
| 5220 | } |
| 5221 | out.n = n |
| 5222 | return protoreflect.ValueOfString(string(v)), out, nil |
| 5223 | } |
| 5224 | |
| 5225 | var coderStringValue = valueCoderFuncs{ |
| 5226 | size: sizeStringValue, |
| 5227 | marshal: appendStringValue, |
| 5228 | unmarshal: consumeStringValue, |
| 5229 | merge: mergeScalarValue, |
| 5230 | } |
| 5231 | |
| 5232 | // appendStringValueValidateUTF8 encodes a string value as a String. |
| 5233 | func appendStringValueValidateUTF8(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 5234 | b = protowire.AppendVarint(b, wiretag) |
| 5235 | b = protowire.AppendString(b, v.String()) |
| 5236 | if !utf8.ValidString(v.String()) { |
| 5237 | return b, errInvalidUTF8{} |
| 5238 | } |
| 5239 | return b, nil |
| 5240 | } |
| 5241 | |
| 5242 | // consumeStringValueValidateUTF8 decodes a string value as a String. |
| 5243 | func consumeStringValueValidateUTF8(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 5244 | if wtyp != protowire.BytesType { |
| 5245 | return protoreflect.Value{}, out, errUnknown |
| 5246 | } |
| 5247 | v, n := protowire.ConsumeBytes(b) |
| 5248 | if n < 0 { |
| 5249 | return protoreflect.Value{}, out, errDecode |
| 5250 | } |
| 5251 | if !utf8.Valid(v) { |
| 5252 | return protoreflect.Value{}, out, errInvalidUTF8{} |
| 5253 | } |
| 5254 | out.n = n |
| 5255 | return protoreflect.ValueOfString(string(v)), out, nil |
| 5256 | } |
| 5257 | |
| 5258 | var coderStringValueValidateUTF8 = valueCoderFuncs{ |
| 5259 | size: sizeStringValue, |
| 5260 | marshal: appendStringValueValidateUTF8, |
| 5261 | unmarshal: consumeStringValueValidateUTF8, |
| 5262 | merge: mergeScalarValue, |
| 5263 | } |
| 5264 | |
| 5265 | // sizeStringSliceValue returns the size of wire encoding a []string value as a repeated String. |
| 5266 | func sizeStringSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 5267 | list := listv.List() |
| 5268 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 5269 | v := list.Get(i) |
| 5270 | size += tagsize + protowire.SizeBytes(len(v.String())) |
| 5271 | } |
| 5272 | return size |
| 5273 | } |
| 5274 | |
| 5275 | // appendStringSliceValue encodes a []string value as a repeated String. |
| 5276 | func appendStringSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 5277 | list := listv.List() |
| 5278 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 5279 | v := list.Get(i) |
| 5280 | b = protowire.AppendVarint(b, wiretag) |
| 5281 | b = protowire.AppendString(b, v.String()) |
| 5282 | } |
| 5283 | return b, nil |
| 5284 | } |
| 5285 | |
| 5286 | // consumeStringSliceValue wire decodes a []string value as a repeated String. |
| 5287 | func consumeStringSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 5288 | list := listv.List() |
| 5289 | if wtyp != protowire.BytesType { |
| 5290 | return protoreflect.Value{}, out, errUnknown |
| 5291 | } |
| 5292 | v, n := protowire.ConsumeBytes(b) |
| 5293 | if n < 0 { |
| 5294 | return protoreflect.Value{}, out, errDecode |
| 5295 | } |
| 5296 | list.Append(protoreflect.ValueOfString(string(v))) |
| 5297 | out.n = n |
| 5298 | return listv, out, nil |
| 5299 | } |
| 5300 | |
| 5301 | var coderStringSliceValue = valueCoderFuncs{ |
| 5302 | size: sizeStringSliceValue, |
| 5303 | marshal: appendStringSliceValue, |
| 5304 | unmarshal: consumeStringSliceValue, |
| 5305 | merge: mergeListValue, |
| 5306 | } |
| 5307 | |
| 5308 | // sizeBytes returns the size of wire encoding a []byte pointer as a Bytes. |
| 5309 | func sizeBytes(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 5310 | v := *p.Bytes() |
| 5311 | return f.tagsize + protowire.SizeBytes(len(v)) |
| 5312 | } |
| 5313 | |
| 5314 | // appendBytes wire encodes a []byte pointer as a Bytes. |
| 5315 | func appendBytes(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5316 | v := *p.Bytes() |
| 5317 | b = protowire.AppendVarint(b, f.wiretag) |
| 5318 | b = protowire.AppendBytes(b, v) |
| 5319 | return b, nil |
| 5320 | } |
| 5321 | |
| 5322 | // consumeBytes wire decodes a []byte pointer as a Bytes. |
| 5323 | func consumeBytes(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 5324 | if wtyp != protowire.BytesType { |
| 5325 | return out, errUnknown |
| 5326 | } |
| 5327 | v, n := protowire.ConsumeBytes(b) |
| 5328 | if n < 0 { |
| 5329 | return out, errDecode |
| 5330 | } |
| 5331 | *p.Bytes() = append(emptyBuf[:], v...) |
| 5332 | out.n = n |
| 5333 | return out, nil |
| 5334 | } |
| 5335 | |
| 5336 | var coderBytes = pointerCoderFuncs{ |
| 5337 | size: sizeBytes, |
| 5338 | marshal: appendBytes, |
| 5339 | unmarshal: consumeBytes, |
| 5340 | merge: mergeBytes, |
| 5341 | } |
| 5342 | |
| 5343 | // appendBytesValidateUTF8 wire encodes a []byte pointer as a Bytes. |
| 5344 | func appendBytesValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5345 | v := *p.Bytes() |
| 5346 | b = protowire.AppendVarint(b, f.wiretag) |
| 5347 | b = protowire.AppendBytes(b, v) |
| 5348 | if !utf8.Valid(v) { |
| 5349 | return b, errInvalidUTF8{} |
| 5350 | } |
| 5351 | return b, nil |
| 5352 | } |
| 5353 | |
| 5354 | // consumeBytesValidateUTF8 wire decodes a []byte pointer as a Bytes. |
| 5355 | func consumeBytesValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 5356 | if wtyp != protowire.BytesType { |
| 5357 | return out, errUnknown |
| 5358 | } |
| 5359 | v, n := protowire.ConsumeBytes(b) |
| 5360 | if n < 0 { |
| 5361 | return out, errDecode |
| 5362 | } |
| 5363 | if !utf8.Valid(v) { |
| 5364 | return out, errInvalidUTF8{} |
| 5365 | } |
| 5366 | *p.Bytes() = append(emptyBuf[:], v...) |
| 5367 | out.n = n |
| 5368 | return out, nil |
| 5369 | } |
| 5370 | |
| 5371 | var coderBytesValidateUTF8 = pointerCoderFuncs{ |
| 5372 | size: sizeBytes, |
| 5373 | marshal: appendBytesValidateUTF8, |
| 5374 | unmarshal: consumeBytesValidateUTF8, |
| 5375 | merge: mergeBytes, |
| 5376 | } |
| 5377 | |
| 5378 | // sizeBytesNoZero returns the size of wire encoding a []byte pointer as a Bytes. |
| 5379 | // The zero value is not encoded. |
| 5380 | func sizeBytesNoZero(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 5381 | v := *p.Bytes() |
| 5382 | if len(v) == 0 { |
| 5383 | return 0 |
| 5384 | } |
| 5385 | return f.tagsize + protowire.SizeBytes(len(v)) |
| 5386 | } |
| 5387 | |
| 5388 | // appendBytesNoZero wire encodes a []byte pointer as a Bytes. |
| 5389 | // The zero value is not encoded. |
| 5390 | func appendBytesNoZero(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5391 | v := *p.Bytes() |
| 5392 | if len(v) == 0 { |
| 5393 | return b, nil |
| 5394 | } |
| 5395 | b = protowire.AppendVarint(b, f.wiretag) |
| 5396 | b = protowire.AppendBytes(b, v) |
| 5397 | return b, nil |
| 5398 | } |
| 5399 | |
| 5400 | // consumeBytesNoZero wire decodes a []byte pointer as a Bytes. |
| 5401 | // The zero value is not decoded. |
| 5402 | func consumeBytesNoZero(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 5403 | if wtyp != protowire.BytesType { |
| 5404 | return out, errUnknown |
| 5405 | } |
| 5406 | v, n := protowire.ConsumeBytes(b) |
| 5407 | if n < 0 { |
| 5408 | return out, errDecode |
| 5409 | } |
| 5410 | *p.Bytes() = append(([]byte)(nil), v...) |
| 5411 | out.n = n |
| 5412 | return out, nil |
| 5413 | } |
| 5414 | |
| 5415 | var coderBytesNoZero = pointerCoderFuncs{ |
| 5416 | size: sizeBytesNoZero, |
| 5417 | marshal: appendBytesNoZero, |
| 5418 | unmarshal: consumeBytesNoZero, |
| 5419 | merge: mergeBytesNoZero, |
| 5420 | } |
| 5421 | |
| 5422 | // appendBytesNoZeroValidateUTF8 wire encodes a []byte pointer as a Bytes. |
| 5423 | // The zero value is not encoded. |
| 5424 | func appendBytesNoZeroValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5425 | v := *p.Bytes() |
| 5426 | if len(v) == 0 { |
| 5427 | return b, nil |
| 5428 | } |
| 5429 | b = protowire.AppendVarint(b, f.wiretag) |
| 5430 | b = protowire.AppendBytes(b, v) |
| 5431 | if !utf8.Valid(v) { |
| 5432 | return b, errInvalidUTF8{} |
| 5433 | } |
| 5434 | return b, nil |
| 5435 | } |
| 5436 | |
| 5437 | // consumeBytesNoZeroValidateUTF8 wire decodes a []byte pointer as a Bytes. |
| 5438 | func consumeBytesNoZeroValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 5439 | if wtyp != protowire.BytesType { |
| 5440 | return out, errUnknown |
| 5441 | } |
| 5442 | v, n := protowire.ConsumeBytes(b) |
| 5443 | if n < 0 { |
| 5444 | return out, errDecode |
| 5445 | } |
| 5446 | if !utf8.Valid(v) { |
| 5447 | return out, errInvalidUTF8{} |
| 5448 | } |
| 5449 | *p.Bytes() = append(([]byte)(nil), v...) |
| 5450 | out.n = n |
| 5451 | return out, nil |
| 5452 | } |
| 5453 | |
| 5454 | var coderBytesNoZeroValidateUTF8 = pointerCoderFuncs{ |
| 5455 | size: sizeBytesNoZero, |
| 5456 | marshal: appendBytesNoZeroValidateUTF8, |
| 5457 | unmarshal: consumeBytesNoZeroValidateUTF8, |
| 5458 | merge: mergeBytesNoZero, |
| 5459 | } |
| 5460 | |
| 5461 | // sizeBytesSlice returns the size of wire encoding a [][]byte pointer as a repeated Bytes. |
| 5462 | func sizeBytesSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) { |
| 5463 | s := *p.BytesSlice() |
| 5464 | for _, v := range s { |
| 5465 | size += f.tagsize + protowire.SizeBytes(len(v)) |
| 5466 | } |
| 5467 | return size |
| 5468 | } |
| 5469 | |
| 5470 | // appendBytesSlice encodes a [][]byte pointer as a repeated Bytes. |
| 5471 | func appendBytesSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5472 | s := *p.BytesSlice() |
| 5473 | for _, v := range s { |
| 5474 | b = protowire.AppendVarint(b, f.wiretag) |
| 5475 | b = protowire.AppendBytes(b, v) |
| 5476 | } |
| 5477 | return b, nil |
| 5478 | } |
| 5479 | |
| 5480 | // consumeBytesSlice wire decodes a [][]byte pointer as a repeated Bytes. |
| 5481 | func consumeBytesSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 5482 | sp := p.BytesSlice() |
| 5483 | if wtyp != protowire.BytesType { |
| 5484 | return out, errUnknown |
| 5485 | } |
| 5486 | v, n := protowire.ConsumeBytes(b) |
| 5487 | if n < 0 { |
| 5488 | return out, errDecode |
| 5489 | } |
| 5490 | *sp = append(*sp, append(emptyBuf[:], v...)) |
| 5491 | out.n = n |
| 5492 | return out, nil |
| 5493 | } |
| 5494 | |
| 5495 | var coderBytesSlice = pointerCoderFuncs{ |
| 5496 | size: sizeBytesSlice, |
| 5497 | marshal: appendBytesSlice, |
| 5498 | unmarshal: consumeBytesSlice, |
| 5499 | merge: mergeBytesSlice, |
| 5500 | } |
| 5501 | |
| 5502 | // appendBytesSliceValidateUTF8 encodes a [][]byte pointer as a repeated Bytes. |
| 5503 | func appendBytesSliceValidateUTF8(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) { |
| 5504 | s := *p.BytesSlice() |
| 5505 | for _, v := range s { |
| 5506 | b = protowire.AppendVarint(b, f.wiretag) |
| 5507 | b = protowire.AppendBytes(b, v) |
| 5508 | if !utf8.Valid(v) { |
| 5509 | return b, errInvalidUTF8{} |
| 5510 | } |
| 5511 | } |
| 5512 | return b, nil |
| 5513 | } |
| 5514 | |
| 5515 | // consumeBytesSliceValidateUTF8 wire decodes a [][]byte pointer as a repeated Bytes. |
| 5516 | func consumeBytesSliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { |
| 5517 | if wtyp != protowire.BytesType { |
| 5518 | return out, errUnknown |
| 5519 | } |
| 5520 | v, n := protowire.ConsumeBytes(b) |
| 5521 | if n < 0 { |
| 5522 | return out, errDecode |
| 5523 | } |
| 5524 | if !utf8.Valid(v) { |
| 5525 | return out, errInvalidUTF8{} |
| 5526 | } |
| 5527 | sp := p.BytesSlice() |
| 5528 | *sp = append(*sp, append(emptyBuf[:], v...)) |
| 5529 | out.n = n |
| 5530 | return out, nil |
| 5531 | } |
| 5532 | |
| 5533 | var coderBytesSliceValidateUTF8 = pointerCoderFuncs{ |
| 5534 | size: sizeBytesSlice, |
| 5535 | marshal: appendBytesSliceValidateUTF8, |
| 5536 | unmarshal: consumeBytesSliceValidateUTF8, |
| 5537 | merge: mergeBytesSlice, |
| 5538 | } |
| 5539 | |
| 5540 | // sizeBytesValue returns the size of wire encoding a []byte value as a Bytes. |
| 5541 | func sizeBytesValue(v protoreflect.Value, tagsize int, opts marshalOptions) int { |
| 5542 | return tagsize + protowire.SizeBytes(len(v.Bytes())) |
| 5543 | } |
| 5544 | |
| 5545 | // appendBytesValue encodes a []byte value as a Bytes. |
| 5546 | func appendBytesValue(b []byte, v protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 5547 | b = protowire.AppendVarint(b, wiretag) |
| 5548 | b = protowire.AppendBytes(b, v.Bytes()) |
| 5549 | return b, nil |
| 5550 | } |
| 5551 | |
| 5552 | // consumeBytesValue decodes a []byte value as a Bytes. |
| 5553 | func consumeBytesValue(b []byte, _ protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 5554 | if wtyp != protowire.BytesType { |
| 5555 | return protoreflect.Value{}, out, errUnknown |
| 5556 | } |
| 5557 | v, n := protowire.ConsumeBytes(b) |
| 5558 | if n < 0 { |
| 5559 | return protoreflect.Value{}, out, errDecode |
| 5560 | } |
| 5561 | out.n = n |
| 5562 | return protoreflect.ValueOfBytes(append(emptyBuf[:], v...)), out, nil |
| 5563 | } |
| 5564 | |
| 5565 | var coderBytesValue = valueCoderFuncs{ |
| 5566 | size: sizeBytesValue, |
| 5567 | marshal: appendBytesValue, |
| 5568 | unmarshal: consumeBytesValue, |
| 5569 | merge: mergeBytesValue, |
| 5570 | } |
| 5571 | |
| 5572 | // sizeBytesSliceValue returns the size of wire encoding a [][]byte value as a repeated Bytes. |
| 5573 | func sizeBytesSliceValue(listv protoreflect.Value, tagsize int, opts marshalOptions) (size int) { |
| 5574 | list := listv.List() |
| 5575 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 5576 | v := list.Get(i) |
| 5577 | size += tagsize + protowire.SizeBytes(len(v.Bytes())) |
| 5578 | } |
| 5579 | return size |
| 5580 | } |
| 5581 | |
| 5582 | // appendBytesSliceValue encodes a [][]byte value as a repeated Bytes. |
| 5583 | func appendBytesSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, opts marshalOptions) ([]byte, error) { |
| 5584 | list := listv.List() |
| 5585 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 5586 | v := list.Get(i) |
| 5587 | b = protowire.AppendVarint(b, wiretag) |
| 5588 | b = protowire.AppendBytes(b, v.Bytes()) |
| 5589 | } |
| 5590 | return b, nil |
| 5591 | } |
| 5592 | |
| 5593 | // consumeBytesSliceValue wire decodes a [][]byte value as a repeated Bytes. |
| 5594 | func consumeBytesSliceValue(b []byte, listv protoreflect.Value, _ protowire.Number, wtyp protowire.Type, opts unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { |
| 5595 | list := listv.List() |
| 5596 | if wtyp != protowire.BytesType { |
| 5597 | return protoreflect.Value{}, out, errUnknown |
| 5598 | } |
| 5599 | v, n := protowire.ConsumeBytes(b) |
| 5600 | if n < 0 { |
| 5601 | return protoreflect.Value{}, out, errDecode |
| 5602 | } |
| 5603 | list.Append(protoreflect.ValueOfBytes(append(emptyBuf[:], v...))) |
| 5604 | out.n = n |
| 5605 | return listv, out, nil |
| 5606 | } |
| 5607 | |
| 5608 | var coderBytesSliceValue = valueCoderFuncs{ |
| 5609 | size: sizeBytesSliceValue, |
| 5610 | marshal: appendBytesSliceValue, |
| 5611 | unmarshal: consumeBytesSliceValue, |
| 5612 | merge: mergeBytesListValue, |
| 5613 | } |
| 5614 | |
| 5615 | // We append to an empty array rather than a nil []byte to get non-nil zero-length byte slices. |
| 5616 | var emptyBuf [0]byte |
| 5617 | |
| 5618 | var wireTypes = map[protoreflect.Kind]protowire.Type{ |
| 5619 | protoreflect.BoolKind: protowire.VarintType, |
| 5620 | protoreflect.EnumKind: protowire.VarintType, |
| 5621 | protoreflect.Int32Kind: protowire.VarintType, |
| 5622 | protoreflect.Sint32Kind: protowire.VarintType, |
| 5623 | protoreflect.Uint32Kind: protowire.VarintType, |
| 5624 | protoreflect.Int64Kind: protowire.VarintType, |
| 5625 | protoreflect.Sint64Kind: protowire.VarintType, |
| 5626 | protoreflect.Uint64Kind: protowire.VarintType, |
| 5627 | protoreflect.Sfixed32Kind: protowire.Fixed32Type, |
| 5628 | protoreflect.Fixed32Kind: protowire.Fixed32Type, |
| 5629 | protoreflect.FloatKind: protowire.Fixed32Type, |
| 5630 | protoreflect.Sfixed64Kind: protowire.Fixed64Type, |
| 5631 | protoreflect.Fixed64Kind: protowire.Fixed64Type, |
| 5632 | protoreflect.DoubleKind: protowire.Fixed64Type, |
| 5633 | protoreflect.StringKind: protowire.BytesType, |
| 5634 | protoreflect.BytesKind: protowire.BytesType, |
| 5635 | protoreflect.MessageKind: protowire.BytesType, |
| 5636 | protoreflect.GroupKind: protowire.StartGroupType, |
| 5637 | } |