pythonprotocol-buffersdumpprotobuf-python

How to get type of a protobuf message from a raw protobuf buffer and the .proto files?


Let's say that I have dumped a protobuf message to a file called packet.bin .

Let's also say that I have the .proto files which describes many message types of which one is the type of the dumped message.

How can I determine which type of message the original message was with the use of the .proto files in python3?


Solution

  • Directly: you cannot. It is usually expected that you know externally (via documentation, or service definition such as gRPC) what type you are receiving.

    You can usually figure it out manually though; you could try all of them and see which works the best, or you could look at the payload via protoc's raw decode mode (or use tools such as https://protogen.marcgravell.com/decode), and again: try to figure it out from there.