Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protobuf Get Schema from Message Data

Just learned about protobuf and am thinking it is super cool and am wondering how I've never heard of it before. I understand it isn't meant for human eyes and is really for end to end transmission. What I am trying to find out, and haven't been able to find the answer yet. Is that if you are given the encoded messages if you can somehow unwrap it to find the fields + values.

The schema names are probably not there but even just being able to say this object has x number of fields and the values are x,y,z.

If it makes any difference (though it shouldn't) I'm using Apple's swift-protobuf (https://github.com/apple/swift-protobuf)

like image 563
utahwithak Avatar asked Nov 01 '25 12:11

utahwithak


1 Answers

The wire format is documented here: https://developers.google.com/protocol-buffers/docs/encoding

You can decode the top level message to some extent, but for embedded length-delimited fields you wouldn't know whether they represent strings or nested messages. Except for groups, all the wire types present in the encoded message can be mapped to multiple field types. For instance, 32 bit fields may store integers or floats. Length-delimited fields may contain nested messages or strings etc. The exact mapping is determined by the schema (= .proto files), which is typically known to the sender and receiver and not contained in the binary data.

Edit: Just trying to decode length-delimited fields as messages might actually work -- it seems quite unlikely that random data would fully conform to the message format...

like image 143
Stefan Haustein Avatar answered Nov 03 '25 08:11

Stefan Haustein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!