mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-31 15:32:36 +00:00
internal/impl: minor refactoring
Change-Id: I1a5f4ca31fec72a39ba6690af06f4ae8576408cc Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/226897 Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
parent
188e702e78
commit
a75c9146b7
@ -124,7 +124,7 @@ func (Export) ProtoMessageV2Of(m message) pref.ProtoMessage {
|
||||
if mv := (Export{}).protoMessageV2Of(m); mv != nil {
|
||||
return mv
|
||||
}
|
||||
return legacyWrapMessage(reflect.ValueOf(m))
|
||||
return legacyWrapMessage(reflect.ValueOf(m)).Interface()
|
||||
}
|
||||
|
||||
// MessageOf returns the protoreflect.Message interface over m.
|
||||
@ -136,7 +136,7 @@ func (Export) MessageOf(m message) pref.Message {
|
||||
if mv := (Export{}).protoMessageV2Of(m); mv != nil {
|
||||
return mv.ProtoReflect()
|
||||
}
|
||||
return legacyWrapMessage(reflect.ValueOf(m)).ProtoReflect()
|
||||
return legacyWrapMessage(reflect.ValueOf(m))
|
||||
}
|
||||
|
||||
// MessageDescriptorOf returns the protoreflect.MessageDescriptor for m.
|
||||
|
@ -824,5 +824,5 @@ func asMessage(v reflect.Value) pref.ProtoMessage {
|
||||
if m, ok := v.Interface().(pref.ProtoMessage); ok {
|
||||
return m
|
||||
}
|
||||
return legacyWrapMessage(v)
|
||||
return legacyWrapMessage(v).Interface()
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ func (c *messageConverter) PBValueOf(v reflect.Value) pref.Value {
|
||||
if m, ok := v.Interface().(pref.ProtoMessage); ok {
|
||||
return pref.ValueOfMessage(m.ProtoReflect())
|
||||
}
|
||||
return pref.ValueOfMessage(legacyWrapMessage(v).ProtoReflect())
|
||||
return pref.ValueOfMessage(legacyWrapMessage(v))
|
||||
}
|
||||
|
||||
func (c *messageConverter) GoValueOf(v pref.Value) reflect.Value {
|
||||
|
@ -21,15 +21,15 @@ import (
|
||||
piface "google.golang.org/protobuf/runtime/protoiface"
|
||||
)
|
||||
|
||||
// legacyWrapMessage wraps v as a protoreflect.ProtoMessage,
|
||||
// legacyWrapMessage wraps v as a protoreflect.Message,
|
||||
// where v must be a *struct kind and not implement the v2 API already.
|
||||
func legacyWrapMessage(v reflect.Value) pref.ProtoMessage {
|
||||
func legacyWrapMessage(v reflect.Value) pref.Message {
|
||||
typ := v.Type()
|
||||
if typ.Kind() != reflect.Ptr || typ.Elem().Kind() != reflect.Struct {
|
||||
return aberrantMessage{v: v}
|
||||
}
|
||||
mt := legacyLoadMessageInfo(typ, "")
|
||||
return mt.MessageOf(v.Interface()).Interface()
|
||||
return mt.MessageOf(v.Interface())
|
||||
}
|
||||
|
||||
var legacyMessageTypeCache sync.Map // map[reflect.Type]*MessageInfo
|
||||
|
Loading…
x
Reference in New Issue
Block a user