Home > front end >  Can the google protobuf library be used to serialize an unknown binary protobuf into a ruby object,
Can the google protobuf library be used to serialize an unknown binary protobuf into a ruby object,

Time:01-19

I understand that the binary protobuf format has no context (without the proto def), but all the same, I have a requirement to be able to deserialize it into a ruby object that can be enumerated and changed, and then reserialize the object back into binary protobuf format.

The google protobuf docs for ruby are really light in comparison to the other supported languages, so it isn't clear if this is possible, or how to go about it.

If the google protobuf library isn't the best choice, is there a better one (that supports all the protobuf versions)?

CodePudding user response:

No, the protocol buffer wire format is not self-describing. Without a schema file there's only a limited amount of information which can be extracted.

There is protoscope, a sort of decompiler. That will show you how much information you can get from the wire format, though it is not exact.

CodePudding user response:

After a bit of experimentation, I found that I couldn't get what I wanted from the Google library. However, the wire protocol is documented here, and there are only six variable types used.

In the end I created a simple class that can deserialize all the TLVs, and for the LEN type, recognise (and permute strings), recurse on embedded messages, and skip everything else.

  • Related