Consider the following proto:
message Payload {
google.protobuf.Any Object = 1;}
message HelloMsg {
string Name = 1;}
message HiMsg {
string Result = 1;}
So the Object field in Payload can have any valid protobuf message.
My consumer is written in Javacript. The method which receives the message,
knows which kind of protobuf message it wants. So, when this handler method
receives the Payload, I want to know if I can unpack it to the protobuf
message it expects. But how?
function myHandler(payload) {
expectedPaylaodType = HelloMsg;
// now how do I unpack, payload.getObject() to HelloMsg?
}
I tried following, but it failed:
let anyObj = payload.getObject();
let targetObj = expectedPaylaodType();
let unpackedObj = anyObj.unpack(anyObj.deserializeBinary,
targetObj.getTypeName());
It is because, targetObj.getTypeName is undefined.
If above is not possible, then I can check with the typeURL field? The any
object has this information. But I am not able to figure out against which
field of targetObj I can check this. Something like this:
if (anyObj.getTypeUrl() == targetObj.typeUrl) {}
targetObj.typeUrl does not exist, but I am not sure against which value I
can compare it to.
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/83d2a05e-01f6-4fd0-957d-baa8d8d0582c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.