value_pure.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. // +build purego appengine
  5. package protoreflect
  6. import "google.golang.org/protobuf/internal/pragma"
  7. type valueType int
  8. const (
  9. nilType valueType = iota
  10. boolType
  11. int32Type
  12. int64Type
  13. uint32Type
  14. uint64Type
  15. float32Type
  16. float64Type
  17. stringType
  18. bytesType
  19. enumType
  20. ifaceType
  21. )
  22. // value is a union where only one type can be represented at a time.
  23. // This uses a distinct field for each type. This is type safe in Go, but
  24. // occupies more memory than necessary (72B).
  25. type value struct {
  26. pragma.DoNotCompare // 0B
  27. typ valueType // 8B
  28. num uint64 // 8B
  29. str string // 16B
  30. bin []byte // 24B
  31. iface interface{} // 16B
  32. }
  33. func valueOfString(v string) Value {
  34. return Value{typ: stringType, str: v}
  35. }
  36. func valueOfBytes(v []byte) Value {
  37. return Value{typ: bytesType, bin: v}
  38. }
  39. func valueOfIface(v interface{}) Value {
  40. return Value{typ: ifaceType, iface: v}
  41. }
  42. func (v Value) getString() string {
  43. return v.str
  44. }
  45. func (v Value) getBytes() []byte {
  46. return v.bin
  47. }
  48. func (v Value) getIface() interface{} {
  49. return v.iface
  50. }