MCPcopy
hub / github.com/golang/protobuf / MarshalAny

Function MarshalAny

ptypes/any.go:45–60  ·  view source on GitHub ↗

MarshalAny marshals the given message m into an anypb.Any message. Deprecated: Call the anypb.New function instead.

(m proto.Message)

Source from the content-addressed store, hash-verified

43//
44// Deprecated: Call the anypb.New function instead.
45func 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

Callers 6

TestMarshalUnmarshalFunction · 0.85
TestIsFunction · 0.85
TestUnmarshalDynamicFunction · 0.85
TestEmptyFunction · 0.85
TestAnyReflectFunction · 0.85

Calls 2

MarshalFunction · 0.92
MessageNameFunction · 0.92

Tested by 6

TestMarshalUnmarshalFunction · 0.68
TestIsFunction · 0.68
TestUnmarshalDynamicFunction · 0.68
TestEmptyFunction · 0.68
TestAnyReflectFunction · 0.68