Is it possible to read common fields from Any (Java)

15 views
Skip to first unread message

JDS

unread,
Nov 4, 2019, 2:51:08 PM11/4/19
to Protocol Buffers
There's prob a better way of doing this, so perhaps someone can point this out. 

I have several different messages each containing data specific to them. However, each one of these messages also contains an instance of another proto message. So for example:

message InEveryClass{
   int id = 1;
}

message A{
  InEveryClass info = 1;
 
............

}
message B{
  InEveryClass info = 1;
 
..........

}



I'm sending A and B across the network, by packing them into an Any message.

I know upon receipt of these bytes they will ALWAYS have an InEveryClass field.

Currently, when I receive the bytes, I do something similar to this.

Any any = Any.parseFrom(bytes);


Now, I would like to be able to get the InEveryClass field withouth having to unpack this Any to a specific class. Is that possible, or do I need to type check it and unpack in order to get the InEveryClass field?



Reply all
Reply to author
Forward
0 new messages