summaryrefslogtreecommitdiffstats
path: root/vendor/google.golang.org/protobuf/internal/impl/convert.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-06-16 21:00:49 +0200
committerGitHub <noreply@github.com>2021-06-16 21:00:49 +0200
commitfb5a84212c491332504fcdd4b5f4a4b97705d2e3 (patch)
treebe03e973d30d040a49a90c47f1e6b73ed8922539 /vendor/google.golang.org/protobuf/internal/impl/convert.go
parentdedc1c45a113d8db373d9e4638f54a0f9d29624f (diff)
downloadmatterbridge-msglm-fb5a84212c491332504fcdd4b5f4a4b97705d2e3.tar.gz
matterbridge-msglm-fb5a84212c491332504fcdd4b5f4a4b97705d2e3.tar.bz2
matterbridge-msglm-fb5a84212c491332504fcdd4b5f4a4b97705d2e3.zip
Update dependencies (#1521)
Diffstat (limited to 'vendor/google.golang.org/protobuf/internal/impl/convert.go')
-rw-r--r--vendor/google.golang.org/protobuf/internal/impl/convert.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/google.golang.org/protobuf/internal/impl/convert.go b/vendor/google.golang.org/protobuf/internal/impl/convert.go
index 36a90dff..acd61bb5 100644
--- a/vendor/google.golang.org/protobuf/internal/impl/convert.go
+++ b/vendor/google.golang.org/protobuf/internal/impl/convert.go
@@ -423,6 +423,13 @@ func (c *messageConverter) PBValueOf(v reflect.Value) pref.Value {
if v.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", v.Type(), c.goType))
}
+ if c.isNonPointer() {
+ if v.CanAddr() {
+ v = v.Addr() // T => *T
+ } else {
+ v = reflect.Zero(reflect.PtrTo(v.Type()))
+ }
+ }
if m, ok := v.Interface().(pref.ProtoMessage); ok {
return pref.ValueOfMessage(m.ProtoReflect())
}
@@ -437,6 +444,16 @@ func (c *messageConverter) GoValueOf(v pref.Value) reflect.Value {
} else {
rv = reflect.ValueOf(m.Interface())
}
+ if c.isNonPointer() {
+ if rv.Type() != reflect.PtrTo(c.goType) {
+ panic(fmt.Sprintf("invalid type: got %v, want %v", rv.Type(), reflect.PtrTo(c.goType)))
+ }
+ if !rv.IsNil() {
+ rv = rv.Elem() // *T => T
+ } else {
+ rv = reflect.Zero(rv.Type().Elem())
+ }
+ }
if rv.Type() != c.goType {
panic(fmt.Sprintf("invalid type: got %v, want %v", rv.Type(), c.goType))
}
@@ -451,6 +468,9 @@ func (c *messageConverter) IsValidPB(v pref.Value) bool {
} else {
rv = reflect.ValueOf(m.Interface())
}
+ if c.isNonPointer() {
+ return rv.Type() == reflect.PtrTo(c.goType)
+ }
return rv.Type() == c.goType
}
@@ -459,9 +479,18 @@ func (c *messageConverter) IsValidGo(v reflect.Value) bool {
}
func (c *messageConverter) New() pref.Value {
+ if c.isNonPointer() {
+ return c.PBValueOf(reflect.New(c.goType).Elem())
+ }
return c.PBValueOf(reflect.New(c.goType.Elem()))
}
func (c *messageConverter) Zero() pref.Value {
return c.PBValueOf(reflect.Zero(c.goType))
}
+
+// isNonPointer reports whether the type is a non-pointer type.
+// This never occurs for generated message types.
+func (c *messageConverter) isNonPointer() bool {
+ return c.goType.Kind() != reflect.Ptr
+}