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//go:build purego || appengine 6// +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} 61