MarshalAny marshals the given message m into an anypb.Any message. Deprecated: Call the anypb.New function instead.
(m proto.Message)
| 43 | // |
| 44 | // Deprecated: Call the anypb.New function instead. |
| 45 | func MarshalAny(m proto.Message) (*anypb.Any, error) { |
| 46 | switch dm := m.(type) { |
| 47 | case DynamicAny: |
| 48 | m = dm.Message |
| 49 | case *DynamicAny: |
| 50 | if dm == nil { |
| 51 | return nil, proto.ErrNil |
| 52 | } |
| 53 | m = dm.Message |
| 54 | } |
| 55 | b, err := proto.Marshal(m) |
| 56 | if err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | return &anypb.Any{TypeUrl: urlPrefix + proto.MessageName(m), Value: b}, nil |
| 60 | } |
| 61 | |
| 62 | // Empty returns a new message of the type specified in an anypb.Any message. |
| 63 | // It returns protoregistry.NotFound if the corresponding message type could not |