Skip to content

Commit ad065b8

Browse files
committed
ptypes: UnmarshalAny with non-pointer DynamicMessage
Unfortunately, both DynamicMessage and *DynamicMessage implement the proto.Message interface. Check for both. Change-Id: I4d645fe5019f44b3ba349f731d1cbdcea481dffe Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/220505 Reviewed-by: Damien Neil <[email protected]>
1 parent d8aac26 commit ad065b8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ptypes/any.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ func anyMessageName(any *anypb.Any) (protoreflect.FullName, error) {
4040

4141
// MarshalAny marshals the given message m into an anypb.Any message.
4242
func MarshalAny(m proto.Message) (*anypb.Any, error) {
43-
if dm, ok := m.(*DynamicAny); ok {
43+
switch dm := m.(type) {
44+
case DynamicAny:
45+
m = dm.Message
46+
case *DynamicAny:
47+
if dm == nil {
48+
return nil, proto.ErrNil
49+
}
4450
m = dm.Message
4551
}
4652
b, err := proto.Marshal(m)

0 commit comments

Comments
 (0)