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