size_gen.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. // Code generated by generate-types. DO NOT EDIT.
  5. package proto
  6. import (
  7. "google.golang.org/protobuf/internal/encoding/wire"
  8. "google.golang.org/protobuf/reflect/protoreflect"
  9. )
  10. func sizeSingular(num wire.Number, kind protoreflect.Kind, v protoreflect.Value) int {
  11. switch kind {
  12. case protoreflect.BoolKind:
  13. return wire.SizeVarint(wire.EncodeBool(v.Bool()))
  14. case protoreflect.EnumKind:
  15. return wire.SizeVarint(uint64(v.Enum()))
  16. case protoreflect.Int32Kind:
  17. return wire.SizeVarint(uint64(int32(v.Int())))
  18. case protoreflect.Sint32Kind:
  19. return wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int()))))
  20. case protoreflect.Uint32Kind:
  21. return wire.SizeVarint(uint64(uint32(v.Uint())))
  22. case protoreflect.Int64Kind:
  23. return wire.SizeVarint(uint64(v.Int()))
  24. case protoreflect.Sint64Kind:
  25. return wire.SizeVarint(wire.EncodeZigZag(v.Int()))
  26. case protoreflect.Uint64Kind:
  27. return wire.SizeVarint(v.Uint())
  28. case protoreflect.Sfixed32Kind:
  29. return wire.SizeFixed32()
  30. case protoreflect.Fixed32Kind:
  31. return wire.SizeFixed32()
  32. case protoreflect.FloatKind:
  33. return wire.SizeFixed32()
  34. case protoreflect.Sfixed64Kind:
  35. return wire.SizeFixed64()
  36. case protoreflect.Fixed64Kind:
  37. return wire.SizeFixed64()
  38. case protoreflect.DoubleKind:
  39. return wire.SizeFixed64()
  40. case protoreflect.StringKind:
  41. return wire.SizeBytes(len(v.String()))
  42. case protoreflect.BytesKind:
  43. return wire.SizeBytes(len(v.Bytes()))
  44. case protoreflect.MessageKind:
  45. return wire.SizeBytes(sizeMessage(v.Message()))
  46. case protoreflect.GroupKind:
  47. return wire.SizeGroup(num, sizeMessage(v.Message()))
  48. default:
  49. return 0
  50. }
  51. }