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