Decode protobuf without proto files in python

227 views Asked by At

I would like to decode protobuf.

Example of the protobuf data: 0a06282c0241057a10011805220d080510bea3f493062a03010c1628f1a6f493063002382b4001481482010f383634333233303532343736343839

I can Decoding online (e.g. via https://protobuf-decoder.netlify.app/) works fine.

The website decode Protobuf without having the original .proto files. And all decoding is done locally via JavaScript (Contribute on GitHub).

How can I do this in python?

I try this solution but not exist .proto file.

1

There are 1 answers

2
jpa On

Take the raw decoding from that site and you write a .proto file yourself.

For example, taking the first rows of the output:

Byte Range  Field Number    Type    Content
0-8                 1       string  (,Az
8-10                2       varint  As Int: 1
                                    As Signed Int: -1
10-12               3       varint  As Int: 5
                                    As Signed Int: -3

you would write:

message MyMessage {
    string field1 = 1;
    int32 field2 = 2;
    int32 field3 = 3;
}

Once you figure out what the fields actually mean, you can assign more sensible names instead of fieldX. If you aren't interested in some of the fields, you can leave them out of the .proto file and the protobuf decoder will ignore them.