Reputation: 13600
In the examples parsing is made like:
AddressBook addressBook = AddressBook.parseFrom(new FileInputStream(args[0]));
but that means that you must know what is the type of the expected message.
I have defined in my .proto file different messages like 'Login', 'Logout', etc. and generated the java file.
How do you handle the situation when you don't know what is the concrete message that is about to come? How do you parse it (from an InputStream for example)?
Is there some generic parse
method in the generated file that "automagically" determines how to parse the message and return Message
or MessageLite
?
Upvotes: 1
Views: 1894
Reputation: 261
Protobuf is basically just a serialization API. So there is no generic way of "knowing" which message it is.
I would try to use a message header uniquely identifying each message type. Maybe that would be enough for you.
Upvotes: 1