mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-01 11:58:21 +00:00
01ab29648e
This change was created by running: git ls-files | xargs sed -i "s|google.golang.org/proto|github.com/golang/protobuf/v2|g" This change is *not* an endorsement of "github.com/golang/protobuf/v2" as the final import path when the v2 API is eventually released as stable. We continue to reserve the right to make breaking changes as we see fit. This change enables us to host the v2 API on a repository that is go-gettable (since go.googlesource.com is not a known host by the "go get" tool; and google.golang.org/proto was just a stub URL that is not currently served). Thus, we can start work on a forked version of the v1 API that explores what it would take to implement v1 in terms of v2 in a backwards compatible way. Change-Id: Ia3ebc41ac4238af62ee140200d3158b53ac9ec48 Reviewed-on: https://go-review.googlesource.com/136736 Reviewed-by: Damien Neil <dneil@google.com>
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
// 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
|
|
|
|
package protoreflect
|
|
|
|
import "github.com/golang/protobuf/v2/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
|
|
}
|