Search code examples
c#protocol-buffersdecodingdecoder

Decoding binary protocol messages not encoded by the same tool


I need to decode binary data (C#) represented by structures like this example:

struct Message
{
    byte id;
    int type;
    bool valid;
}

And the example binary data: 0x040000000201 where id=4, type=2, valid=true;

Can I use Thrift, Protocol Buffers, or any other tool to decode a binary data that was not encoded by the same tool? Can you give any suggestions on how do that?


Solution

  • No, basically. They are designed as platform-independent generic serialization tools that each follow a pre-defined protocol (/wire-format), meaning: the standard user doesn't usually need to know or care what the data looks like - it is the tool's job to abstract that away.

    In your case, the wire-format is pre-defined an is unlikely to be similar to any such tool. You will either need a more specific tool that allows you to specify very fine-grained protocol details, or you'll need to write code to serialize/deserialize manually.

    Ultimately it is not unlike asking "can I use JavaScriptSerializer to read my XML document?". To which the answer is simply: "no; JavaScriptSerializer expecs JSON and has no ability to specify or interpret XML particulars".