Update dependencies
This commit is contained in:
parent
e97c7f2ada
commit
71b2136a9e
138 changed files with 7864 additions and 968 deletions
7
vendor/google.golang.org/protobuf/encoding/prototext/decode.go
generated
vendored
7
vendor/google.golang.org/protobuf/encoding/prototext/decode.go
generated
vendored
|
@ -16,6 +16,7 @@ import (
|
|||
"google.golang.org/protobuf/internal/flags"
|
||||
"google.golang.org/protobuf/internal/pragma"
|
||||
"google.golang.org/protobuf/internal/set"
|
||||
"google.golang.org/protobuf/internal/strs"
|
||||
"google.golang.org/protobuf/proto"
|
||||
pref "google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
|
@ -339,10 +340,10 @@ func (d decoder) unmarshalScalar(fd pref.FieldDescriptor) (pref.Value, error) {
|
|||
|
||||
case pref.StringKind:
|
||||
if s, ok := tok.String(); ok {
|
||||
if utf8.ValidString(s) {
|
||||
return pref.ValueOfString(s), nil
|
||||
if strs.EnforceUTF8(fd) && !utf8.ValidString(s) {
|
||||
return pref.Value{}, d.newError(tok.Pos(), "contains invalid UTF-8")
|
||||
}
|
||||
return pref.Value{}, d.newError(tok.Pos(), "contains invalid UTF-8")
|
||||
return pref.ValueOfString(s), nil
|
||||
}
|
||||
|
||||
case pref.BytesKind:
|
||||
|
|
16
vendor/google.golang.org/protobuf/encoding/prototext/encode.go
generated
vendored
16
vendor/google.golang.org/protobuf/encoding/prototext/encode.go
generated
vendored
|
@ -18,6 +18,7 @@ import (
|
|||
"google.golang.org/protobuf/internal/flags"
|
||||
"google.golang.org/protobuf/internal/mapsort"
|
||||
"google.golang.org/protobuf/internal/pragma"
|
||||
"google.golang.org/protobuf/internal/strs"
|
||||
"google.golang.org/protobuf/proto"
|
||||
pref "google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
|
@ -55,6 +56,15 @@ type MarshalOptions struct {
|
|||
// Indent can only be composed of space or tab characters.
|
||||
Indent string
|
||||
|
||||
// EmitASCII specifies whether to format strings and bytes as ASCII only
|
||||
// as opposed to using UTF-8 encoding when possible.
|
||||
EmitASCII bool
|
||||
|
||||
// allowInvalidUTF8 specifies whether to permit the encoding of strings
|
||||
// with invalid UTF-8. This is unexported as it is intended to only
|
||||
// be specified by the Format method.
|
||||
allowInvalidUTF8 bool
|
||||
|
||||
// AllowPartial allows messages that have missing required fields to marshal
|
||||
// without returning an error. If AllowPartial is false (the default),
|
||||
// Marshal will return error if there are any missing required fields.
|
||||
|
@ -81,6 +91,7 @@ func (o MarshalOptions) Format(m proto.Message) string {
|
|||
if m == nil || !m.ProtoReflect().IsValid() {
|
||||
return "<nil>" // invalid syntax, but okay since this is for debugging
|
||||
}
|
||||
o.allowInvalidUTF8 = true
|
||||
o.AllowPartial = true
|
||||
o.EmitUnknown = true
|
||||
b, _ := o.Marshal(m)
|
||||
|
@ -91,7 +102,6 @@ func (o MarshalOptions) Format(m proto.Message) string {
|
|||
// MarshalOptions object. Do not depend on the output being stable. It may
|
||||
// change over time across different versions of the program.
|
||||
func (o MarshalOptions) Marshal(m proto.Message) ([]byte, error) {
|
||||
const outputASCII = false
|
||||
var delims = [2]byte{'{', '}'}
|
||||
|
||||
if o.Multiline && o.Indent == "" {
|
||||
|
@ -101,7 +111,7 @@ func (o MarshalOptions) Marshal(m proto.Message) ([]byte, error) {
|
|||
o.Resolver = protoregistry.GlobalTypes
|
||||
}
|
||||
|
||||
internalEnc, err := text.NewEncoder(o.Indent, delims, outputASCII)
|
||||
internalEnc, err := text.NewEncoder(o.Indent, delims, o.EmitASCII)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -215,7 +225,7 @@ func (e encoder) marshalSingular(val pref.Value, fd pref.FieldDescriptor) error
|
|||
|
||||
case pref.StringKind:
|
||||
s := val.String()
|
||||
if !utf8.ValidString(s) {
|
||||
if !e.opts.allowInvalidUTF8 && strs.EnforceUTF8(fd) && !utf8.ValidString(s) {
|
||||
return errors.InvalidUTF8(string(fd.FullName()))
|
||||
}
|
||||
e.WriteString(s)
|
||||
|
|
2
vendor/google.golang.org/protobuf/internal/filedesc/desc.go
generated
vendored
2
vendor/google.golang.org/protobuf/internal/filedesc/desc.go
generated
vendored
|
@ -607,7 +607,7 @@ func (dv *defaultValue) get(fd pref.FieldDescriptor) pref.Value {
|
|||
// TODO: Avoid panic if we're running with the race detector
|
||||
// and instead spawn a goroutine that periodically resets
|
||||
// this value back to the original to induce a race.
|
||||
panic("detected mutation on the default bytes")
|
||||
panic(fmt.Sprintf("detected mutation on the default bytes for %v", fd.FullName()))
|
||||
}
|
||||
return dv.val
|
||||
}
|
||||
|
|
15
vendor/google.golang.org/protobuf/internal/impl/codec_message.go
generated
vendored
15
vendor/google.golang.org/protobuf/internal/impl/codec_message.go
generated
vendored
|
@ -31,11 +31,6 @@ type coderMessageInfo struct {
|
|||
needsInitCheck bool
|
||||
isMessageSet bool
|
||||
numRequiredFields uint8
|
||||
|
||||
// Include space for a number of coderFieldInfos to improve cache locality.
|
||||
// The number of entries is chosen through a combination of guesswork and
|
||||
// empirical testing.
|
||||
coderFieldBuf [32]coderFieldInfo
|
||||
}
|
||||
|
||||
type coderFieldInfo struct {
|
||||
|
@ -58,7 +53,7 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
|
|||
|
||||
mi.coderFields = make(map[protowire.Number]*coderFieldInfo)
|
||||
fields := mi.Desc.Fields()
|
||||
preallocFields := mi.coderFieldBuf[:]
|
||||
preallocFields := make([]coderFieldInfo, fields.Len())
|
||||
for i := 0; i < fields.Len(); i++ {
|
||||
fd := fields.Get(i)
|
||||
|
||||
|
@ -87,13 +82,7 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
|
|||
fieldOffset = offsetOf(fs, mi.Exporter)
|
||||
childMessage, funcs = fieldCoder(fd, ft)
|
||||
}
|
||||
var cf *coderFieldInfo
|
||||
if len(preallocFields) > 0 {
|
||||
cf = &preallocFields[0]
|
||||
preallocFields = preallocFields[1:]
|
||||
} else {
|
||||
cf = new(coderFieldInfo)
|
||||
}
|
||||
cf := &preallocFields[i]
|
||||
*cf = coderFieldInfo{
|
||||
num: fd.Number(),
|
||||
offset: fieldOffset,
|
||||
|
|
15
vendor/google.golang.org/protobuf/internal/impl/message_reflect.go
generated
vendored
15
vendor/google.golang.org/protobuf/internal/impl/message_reflect.go
generated
vendored
|
@ -338,24 +338,27 @@ func (mi *MessageInfo) checkField(fd pref.FieldDescriptor) (*fieldInfo, pref.Ext
|
|||
}
|
||||
if fi != nil {
|
||||
if fi.fieldDesc != fd {
|
||||
panic("mismatching field descriptor")
|
||||
if got, want := fd.FullName(), fi.fieldDesc.FullName(); got != want {
|
||||
panic(fmt.Sprintf("mismatching field: got %v, want %v", got, want))
|
||||
}
|
||||
panic(fmt.Sprintf("mismatching field: %v", fd.FullName()))
|
||||
}
|
||||
return fi, nil
|
||||
}
|
||||
|
||||
if fd.IsExtension() {
|
||||
if fd.ContainingMessage().FullName() != mi.Desc.FullName() {
|
||||
if got, want := fd.ContainingMessage().FullName(), mi.Desc.FullName(); got != want {
|
||||
// TODO: Should this be exact containing message descriptor match?
|
||||
panic("mismatching containing message")
|
||||
panic(fmt.Sprintf("extension %v has mismatching containing message: got %v, want %v", fd.FullName(), got, want))
|
||||
}
|
||||
if !mi.Desc.ExtensionRanges().Has(fd.Number()) {
|
||||
panic("invalid extension field")
|
||||
panic(fmt.Sprintf("extension %v extends %v outside the extension range", fd.FullName(), mi.Desc.FullName()))
|
||||
}
|
||||
xtd, ok := fd.(pref.ExtensionTypeDescriptor)
|
||||
if !ok {
|
||||
panic("extension descriptor does not implement ExtensionTypeDescriptor")
|
||||
panic(fmt.Sprintf("extension %v does not implement protoreflect.ExtensionTypeDescriptor", fd.FullName()))
|
||||
}
|
||||
return nil, xtd.Type()
|
||||
}
|
||||
panic("invalid field descriptor")
|
||||
panic(fmt.Sprintf("field %v is invalid", fd.FullName()))
|
||||
}
|
||||
|
|
29
vendor/google.golang.org/protobuf/internal/impl/message_reflect_field.go
generated
vendored
29
vendor/google.golang.org/protobuf/internal/impl/message_reflect_field.go
generated
vendored
|
@ -31,13 +31,13 @@ type fieldInfo struct {
|
|||
func fieldInfoForOneof(fd pref.FieldDescriptor, fs reflect.StructField, x exporter, ot reflect.Type) fieldInfo {
|
||||
ft := fs.Type
|
||||
if ft.Kind() != reflect.Interface {
|
||||
panic(fmt.Sprintf("invalid type: got %v, want interface kind", ft))
|
||||
panic(fmt.Sprintf("field %v has invalid type: got %v, want interface kind", fd.FullName(), ft))
|
||||
}
|
||||
if ot.Kind() != reflect.Struct {
|
||||
panic(fmt.Sprintf("invalid type: got %v, want struct kind", ot))
|
||||
panic(fmt.Sprintf("field %v has invalid type: got %v, want struct kind", fd.FullName(), ot))
|
||||
}
|
||||
if !reflect.PtrTo(ot).Implements(ft) {
|
||||
panic(fmt.Sprintf("invalid type: %v does not implement %v", ot, ft))
|
||||
panic(fmt.Sprintf("field %v has invalid type: %v does not implement %v", fd.FullName(), ot, ft))
|
||||
}
|
||||
conv := NewConverter(ot.Field(0).Type, fd)
|
||||
isMessage := fd.Message() != nil
|
||||
|
@ -90,7 +90,7 @@ func fieldInfoForOneof(fd pref.FieldDescriptor, fs reflect.StructField, x export
|
|||
},
|
||||
mutable: func(p pointer) pref.Value {
|
||||
if !isMessage {
|
||||
panic("invalid Mutable on field with non-composite type")
|
||||
panic(fmt.Sprintf("field %v with invalid Mutable call on field with non-composite type", fd.FullName()))
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if rv.IsNil() || rv.Elem().Type().Elem() != ot || rv.Elem().IsNil() {
|
||||
|
@ -114,7 +114,7 @@ func fieldInfoForOneof(fd pref.FieldDescriptor, fs reflect.StructField, x export
|
|||
func fieldInfoForMap(fd pref.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
|
||||
ft := fs.Type
|
||||
if ft.Kind() != reflect.Map {
|
||||
panic(fmt.Sprintf("invalid type: got %v, want map kind", ft))
|
||||
panic(fmt.Sprintf("field %v has invalid type: got %v, want map kind", fd.FullName(), ft))
|
||||
}
|
||||
conv := NewConverter(ft, fd)
|
||||
|
||||
|
@ -147,7 +147,7 @@ func fieldInfoForMap(fd pref.FieldDescriptor, fs reflect.StructField, x exporter
|
|||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
pv := conv.GoValueOf(v)
|
||||
if pv.IsNil() {
|
||||
panic(fmt.Sprintf("invalid value: setting map field to read-only value"))
|
||||
panic(fmt.Sprintf("map field %v cannot be set with read-only value", fd.FullName()))
|
||||
}
|
||||
rv.Set(pv)
|
||||
},
|
||||
|
@ -167,7 +167,7 @@ func fieldInfoForMap(fd pref.FieldDescriptor, fs reflect.StructField, x exporter
|
|||
func fieldInfoForList(fd pref.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
|
||||
ft := fs.Type
|
||||
if ft.Kind() != reflect.Slice {
|
||||
panic(fmt.Sprintf("invalid type: got %v, want slice kind", ft))
|
||||
panic(fmt.Sprintf("field %v has invalid type: got %v, want slice kind", fd.FullName(), ft))
|
||||
}
|
||||
conv := NewConverter(reflect.PtrTo(ft), fd)
|
||||
|
||||
|
@ -200,7 +200,7 @@ func fieldInfoForList(fd pref.FieldDescriptor, fs reflect.StructField, x exporte
|
|||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
pv := conv.GoValueOf(v)
|
||||
if pv.IsNil() {
|
||||
panic(fmt.Sprintf("invalid value: setting repeated field to read-only value"))
|
||||
panic(fmt.Sprintf("list field %v cannot be set with read-only value", fd.FullName()))
|
||||
}
|
||||
rv.Set(pv.Elem())
|
||||
},
|
||||
|
@ -225,7 +225,7 @@ func fieldInfoForScalar(fd pref.FieldDescriptor, fs reflect.StructField, x expor
|
|||
isBytes := ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8
|
||||
if nullable {
|
||||
if ft.Kind() != reflect.Ptr && ft.Kind() != reflect.Slice {
|
||||
panic(fmt.Sprintf("invalid type: got %v, want pointer", ft))
|
||||
panic(fmt.Sprintf("field %v has invalid type: got %v, want pointer", fd.FullName(), ft))
|
||||
}
|
||||
if ft.Kind() == reflect.Ptr {
|
||||
ft = ft.Elem()
|
||||
|
@ -257,7 +257,7 @@ func fieldInfoForScalar(fd pref.FieldDescriptor, fs reflect.StructField, x expor
|
|||
case reflect.String, reflect.Slice:
|
||||
return rv.Len() > 0
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid type: %v", rv.Type())) // should never happen
|
||||
panic(fmt.Sprintf("field %v has invalid type: %v", fd.FullName(), rv.Type())) // should never happen
|
||||
}
|
||||
},
|
||||
clear: func(p pointer) {
|
||||
|
@ -314,7 +314,7 @@ func fieldInfoForWeakMessage(fd pref.FieldDescriptor, weakOffset offset) fieldIn
|
|||
messageName := fd.Message().FullName()
|
||||
messageType, _ = preg.GlobalTypes.FindMessageByName(messageName)
|
||||
if messageType == nil {
|
||||
panic(fmt.Sprintf("weak message %v is not linked in", messageName))
|
||||
panic(fmt.Sprintf("weak message %v for field %v is not linked in", messageName, fd.FullName()))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -347,7 +347,10 @@ func fieldInfoForWeakMessage(fd pref.FieldDescriptor, weakOffset offset) fieldIn
|
|||
lazyInit()
|
||||
m := v.Message()
|
||||
if m.Descriptor() != messageType.Descriptor() {
|
||||
panic("mismatching message descriptor")
|
||||
if got, want := m.Descriptor().FullName(), messageType.Descriptor().FullName(); got != want {
|
||||
panic(fmt.Sprintf("field %v has mismatching message descriptor: got %v, want %v", fd.FullName(), got, want))
|
||||
}
|
||||
panic(fmt.Sprintf("field %v has mismatching message descriptor: %v", fd.FullName(), m.Descriptor().FullName()))
|
||||
}
|
||||
p.Apply(weakOffset).WeakFields().set(num, m.Interface())
|
||||
},
|
||||
|
@ -402,7 +405,7 @@ func fieldInfoForMessage(fd pref.FieldDescriptor, fs reflect.StructField, x expo
|
|||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
rv.Set(conv.GoValueOf(v))
|
||||
if rv.IsNil() {
|
||||
panic("invalid nil pointer")
|
||||
panic(fmt.Sprintf("field %v has invalid nil pointer", fd.FullName()))
|
||||
}
|
||||
},
|
||||
mutable: func(p pointer) pref.Value {
|
||||
|
|
4
vendor/google.golang.org/protobuf/internal/impl/message_reflect_gen.go
generated
vendored
4
vendor/google.golang.org/protobuf/internal/impl/message_reflect_gen.go
generated
vendored
|
@ -114,7 +114,7 @@ func (m *messageState) WhichOneof(od protoreflect.OneofDescriptor) protoreflect.
|
|||
if oi := m.messageInfo().oneofs[od.Name()]; oi != nil && oi.oneofDesc == od {
|
||||
return od.Fields().ByNumber(oi.which(m.pointer()))
|
||||
}
|
||||
panic("invalid oneof descriptor")
|
||||
panic("invalid oneof descriptor " + string(od.FullName()) + " for message " + string(m.Descriptor().FullName()))
|
||||
}
|
||||
func (m *messageState) GetUnknown() protoreflect.RawFields {
|
||||
m.messageInfo().init()
|
||||
|
@ -234,7 +234,7 @@ func (m *messageReflectWrapper) WhichOneof(od protoreflect.OneofDescriptor) prot
|
|||
if oi := m.messageInfo().oneofs[od.Name()]; oi != nil && oi.oneofDesc == od {
|
||||
return od.Fields().ByNumber(oi.which(m.pointer()))
|
||||
}
|
||||
panic("invalid oneof descriptor")
|
||||
panic("invalid oneof descriptor " + string(od.FullName()) + " for message " + string(m.Descriptor().FullName()))
|
||||
}
|
||||
func (m *messageReflectWrapper) GetUnknown() protoreflect.RawFields {
|
||||
m.messageInfo().init()
|
||||
|
|
6
vendor/google.golang.org/protobuf/internal/impl/pointer_unsafe.go
generated
vendored
6
vendor/google.golang.org/protobuf/internal/impl/pointer_unsafe.go
generated
vendored
|
@ -148,7 +148,11 @@ func (ms *messageState) pointer() pointer {
|
|||
return pointer{p: unsafe.Pointer(ms)}
|
||||
}
|
||||
func (ms *messageState) messageInfo() *MessageInfo {
|
||||
return ms.LoadMessageInfo()
|
||||
mi := ms.LoadMessageInfo()
|
||||
if mi == nil {
|
||||
panic("invalid nil message info; this suggests memory corruption due to a race or shallow copy on the message struct")
|
||||
}
|
||||
return mi
|
||||
}
|
||||
func (ms *messageState) LoadMessageInfo() *MessageInfo {
|
||||
return (*MessageInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&ms.atomicMessageInfo))))
|
||||
|
|
2
vendor/google.golang.org/protobuf/internal/version/version.go
generated
vendored
2
vendor/google.golang.org/protobuf/internal/version/version.go
generated
vendored
|
@ -52,7 +52,7 @@ import (
|
|||
// 10. Send out the CL for review and submit it.
|
||||
const (
|
||||
Major = 1
|
||||
Minor = 22
|
||||
Minor = 23
|
||||
Patch = 0
|
||||
PreRelease = ""
|
||||
)
|
||||
|
|
7
vendor/google.golang.org/protobuf/proto/merge.go
generated
vendored
7
vendor/google.golang.org/protobuf/proto/merge.go
generated
vendored
|
@ -5,6 +5,8 @@
|
|||
package proto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/runtime/protoiface"
|
||||
)
|
||||
|
@ -26,6 +28,9 @@ func Merge(dst, src Message) {
|
|||
|
||||
dstMsg, srcMsg := dst.ProtoReflect(), src.ProtoReflect()
|
||||
if dstMsg.Descriptor() != srcMsg.Descriptor() {
|
||||
if got, want := dstMsg.Descriptor().FullName(), srcMsg.Descriptor().FullName(); got != want {
|
||||
panic(fmt.Sprintf("descriptor mismatch: %v != %v", got, want))
|
||||
}
|
||||
panic("descriptor mismatch")
|
||||
}
|
||||
mergeOptions{}.mergeMessage(dstMsg, srcMsg)
|
||||
|
@ -72,7 +77,7 @@ func (o mergeOptions) mergeMessage(dst, src protoreflect.Message) {
|
|||
}
|
||||
|
||||
if !dst.IsValid() {
|
||||
panic("cannot merge into invalid destination message")
|
||||
panic(fmt.Sprintf("cannot merge into invalid %v message", dst.Descriptor().FullName()))
|
||||
}
|
||||
|
||||
src.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
|
||||
|
|
8
vendor/google.golang.org/protobuf/proto/reset.go
generated
vendored
8
vendor/google.golang.org/protobuf/proto/reset.go
generated
vendored
|
@ -4,7 +4,11 @@
|
|||
|
||||
package proto
|
||||
|
||||
import "google.golang.org/protobuf/reflect/protoreflect"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
// Reset clears every field in the message.
|
||||
// The resulting message shares no observable memory with its previous state
|
||||
|
@ -19,7 +23,7 @@ func Reset(m Message) {
|
|||
|
||||
func resetMessage(m protoreflect.Message) {
|
||||
if !m.IsValid() {
|
||||
panic("cannot reset invalid message")
|
||||
panic(fmt.Sprintf("cannot reset invalid %v message", m.Descriptor().FullName()))
|
||||
}
|
||||
|
||||
// Clear all known fields.
|
||||
|
|
78
vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go
generated
vendored
78
vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go
generated
vendored
|
@ -7,7 +7,6 @@ package protoreflect
|
|||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Value is a union where only one Go type may be set at a time.
|
||||
|
@ -87,7 +86,7 @@ func ValueOf(v interface{}) Value {
|
|||
case Message, List, Map:
|
||||
return valueOfIface(v)
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid type: %v", reflect.TypeOf(v)))
|
||||
panic(fmt.Sprintf("invalid type: %T", v))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,13 +196,55 @@ func (v Value) Interface() interface{} {
|
|||
}
|
||||
}
|
||||
|
||||
func (v Value) typeName() string {
|
||||
switch v.typ {
|
||||
case nilType:
|
||||
return "nil"
|
||||
case boolType:
|
||||
return "bool"
|
||||
case int32Type:
|
||||
return "int32"
|
||||
case int64Type:
|
||||
return "int64"
|
||||
case uint32Type:
|
||||
return "uint32"
|
||||
case uint64Type:
|
||||
return "uint64"
|
||||
case float32Type:
|
||||
return "float32"
|
||||
case float64Type:
|
||||
return "float64"
|
||||
case stringType:
|
||||
return "string"
|
||||
case bytesType:
|
||||
return "bytes"
|
||||
case enumType:
|
||||
return "enum"
|
||||
default:
|
||||
switch v := v.getIface().(type) {
|
||||
case Message:
|
||||
return "message"
|
||||
case List:
|
||||
return "list"
|
||||
case Map:
|
||||
return "map"
|
||||
default:
|
||||
return fmt.Sprintf("<unknown: %T>", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (v Value) panicMessage(what string) string {
|
||||
return fmt.Sprintf("type mismatch: cannot convert %v to %s", v.typeName(), what)
|
||||
}
|
||||
|
||||
// Bool returns v as a bool and panics if the type is not a bool.
|
||||
func (v Value) Bool() bool {
|
||||
switch v.typ {
|
||||
case boolType:
|
||||
return v.num > 0
|
||||
default:
|
||||
panic("proto: value type mismatch")
|
||||
panic(v.panicMessage("bool"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,7 +254,7 @@ func (v Value) Int() int64 {
|
|||
case int32Type, int64Type:
|
||||
return int64(v.num)
|
||||
default:
|
||||
panic("proto: value type mismatch")
|
||||
panic(v.panicMessage("int"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,7 +264,7 @@ func (v Value) Uint() uint64 {
|
|||
case uint32Type, uint64Type:
|
||||
return uint64(v.num)
|
||||
default:
|
||||
panic("proto: value type mismatch")
|
||||
panic(v.panicMessage("uint"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,7 +274,7 @@ func (v Value) Float() float64 {
|
|||
case float32Type, float64Type:
|
||||
return math.Float64frombits(uint64(v.num))
|
||||
default:
|
||||
panic("proto: value type mismatch")
|
||||
panic(v.panicMessage("float"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +295,7 @@ func (v Value) Bytes() []byte {
|
|||
case bytesType:
|
||||
return v.getBytes()
|
||||
default:
|
||||
panic("proto: value type mismatch")
|
||||
panic(v.panicMessage("bytes"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,37 +305,37 @@ func (v Value) Enum() EnumNumber {
|
|||
case enumType:
|
||||
return EnumNumber(v.num)
|
||||
default:
|
||||
panic("proto: value type mismatch")
|
||||
panic(v.panicMessage("enum"))
|
||||
}
|
||||
}
|
||||
|
||||
// Message returns v as a Message and panics if the type is not a Message.
|
||||
func (v Value) Message() Message {
|
||||
switch v := v.getIface().(type) {
|
||||
switch vi := v.getIface().(type) {
|
||||
case Message:
|
||||
return v
|
||||
return vi
|
||||
default:
|
||||
panic("proto: value type mismatch")
|
||||
panic(v.panicMessage("message"))
|
||||
}
|
||||
}
|
||||
|
||||
// List returns v as a List and panics if the type is not a List.
|
||||
func (v Value) List() List {
|
||||
switch v := v.getIface().(type) {
|
||||
switch vi := v.getIface().(type) {
|
||||
case List:
|
||||
return v
|
||||
return vi
|
||||
default:
|
||||
panic("proto: value type mismatch")
|
||||
panic(v.panicMessage("list"))
|
||||
}
|
||||
}
|
||||
|
||||
// Map returns v as a Map and panics if the type is not a Map.
|
||||
func (v Value) Map() Map {
|
||||
switch v := v.getIface().(type) {
|
||||
switch vi := v.getIface().(type) {
|
||||
case Map:
|
||||
return v
|
||||
return vi
|
||||
default:
|
||||
panic("proto: value type mismatch")
|
||||
panic(v.panicMessage("map"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,8 +344,9 @@ func (v Value) MapKey() MapKey {
|
|||
switch v.typ {
|
||||
case boolType, int32Type, int64Type, uint32Type, uint64Type, stringType:
|
||||
return MapKey(v)
|
||||
default:
|
||||
panic(v.panicMessage("map key"))
|
||||
}
|
||||
panic("proto: invalid map key type")
|
||||
}
|
||||
|
||||
// MapKey is used to index maps, where the Go type of the MapKey must match
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue