-1

I'm implementing a communication system using UDP style client and receiver in C++. My client will send multiple byte streams which represent serialized Protobuf messages. My receiver then receives this data without knowing the exact Protobuf message type.

Is there a way to unpack/deserialize the byte stream into a generic Protobuf message type?

message A {
    string nameA = 1;
    string numberA = 2;
}

message A {
    string nameB = 1;
    string numberB = 2;
}

I want to do the following:

::google::protobuf::Message temp;
temp->ParseFromString(inputString);

However, the protobuf compiler wants me to define the 'temp' variable with a specific message type like this:

A temp;
temp->ParseFromString(inputString);

The difference here is that A is an exact message type from my .proto file. I want to use the generic Protobuf message type to unpack the byte stream in.

  • 1
    There is very little one can do with a protobuf message without the message type. What is the use case? – Jeff Garrett Aug 04 '23 at 01:21
  • Does this answer your question? [How to determine message type in protobuf so that I can use that type.parsefrom(byte\[ \])](https://stackoverflow.com/questions/30564404/how-to-determine-message-type-in-protobuf-so-that-i-can-use-that-type-parsefrom) – kiner_shah Aug 04 '23 at 08:06
  • Or you may use the solution from here: https://stackoverflow.com/q/56247392/4688321 – kiner_shah Aug 04 '23 at 08:09

0 Answers0