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