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
7package protoreflect
8
9import "google.golang.org/protobuf/internal/pragma"
10
11type valueType int
12
13const (
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).
31type 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
41func valueOfString(v string) Value {
42	return Value{typ: stringType, str: v}
43}
44func valueOfBytes(v []byte) Value {
45	return Value{typ: bytesType, bin: v}
46}
47func valueOfIface(v interface{}) Value {
48	return Value{typ: ifaceType, iface: v}
49}
50
51func (v Value) getString() string {
52	return v.str
53}
54func (v Value) getBytes() []byte {
55	return v.bin
56}
57func (v Value) getIface() interface{} {
58	return v.iface
59}
60