Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

61 Zeilen
1.2 KiB

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