File: value_pure.go

package info (click to toggle)
golang-google-protobuf 1.25.0%2Bgit20201208.160c747-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, bullseye-backports
  • size: 10,260 kB
  • sloc: sh: 94; makefile: 4
file content (59 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build purego appengine

package protoreflect

import "google.golang.org/protobuf/internal/pragma"

type valueType int

const (
	nilType valueType = iota
	boolType
	int32Type
	int64Type
	uint32Type
	uint64Type
	float32Type
	float64Type
	stringType
	bytesType
	enumType
	ifaceType
)

// value is a union where only one type can be represented at a time.
// This uses a distinct field for each type. This is type safe in Go, but
// occupies more memory than necessary (72B).
type value struct {
	pragma.DoNotCompare // 0B

	typ   valueType   // 8B
	num   uint64      // 8B
	str   string      // 16B
	bin   []byte      // 24B
	iface interface{} // 16B
}

func valueOfString(v string) Value {
	return Value{typ: stringType, str: v}
}
func valueOfBytes(v []byte) Value {
	return Value{typ: bytesType, bin: v}
}
func valueOfIface(v interface{}) Value {
	return Value{typ: ifaceType, iface: v}
}

func (v Value) getString() string {
	return v.str
}
func (v Value) getBytes() []byte {
	return v.bin
}
func (v Value) getIface() interface{} {
	return v.iface
}