'Any' type and usage

31 views
Skip to first unread message

Christopher C

unread,
Mar 3, 2023, 2:16:25 PM3/3/23
to Protocol Buffers
Hello All,

Quick question on the 'Any' usage (in golang). I have some messages defined as below:

message AnyTypeRequest{
  string type = 1;
  google.protobuf.Any req_object = 2;
}
message Type1Msg {
  int32 count =1;
}
message Type2Msg{
  string msg = 1;
}

In the handler I was hoping to switch off the type field to unmarshal the req_object into a proper structure.    The call UnmarshalTo() fails with a mismatched message type because the Any object's TypeUrl is empty.  Do I need to set the Any.TypeUrl to the type I expect it to be, or am I not using this in the proper manner?

Thanks,
Chris

Reply all
Reply to author
Forward
0 new messages