1

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
RHaguiuda
  • 3,207
  • 9
  • 37
  • 55
  • Check out the selected answer to http://stackoverflow.com/questions/2480116/marshalling-a-big-endian-byte-collection-into-a-struct-in-order-to-pull-out-valu – Matthew Mar 09 '12 at 18:59

1 Answers1

2

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".

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900