Skip to content

Commit

Permalink
ptypes: UnmarshalAny with non-pointer DynamicMessage
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dsnet committed Feb 25, 2020
1 parent d8aac26 commit ad065b8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ptypes/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ func anyMessageName(any *anypb.Any) (protoreflect.FullName, error) {

// MarshalAny marshals the given message m into an anypb.Any message.
func MarshalAny(m proto.Message) (*anypb.Any, error) {
if dm, ok := m.(*DynamicAny); ok {
switch dm := m.(type) {
case DynamicAny:
m = dm.Message
case *DynamicAny:
if dm == nil {
return nil, proto.ErrNil
}
m = dm.Message
}
b, err := proto.Marshal(m)
Expand Down

0 comments on commit ad065b8

Please sign in to comment.