views:

124

answers:

2

What protocol definition do you recommend? I evaluated Google's protocol buffers, but it does not allow me to control the placement of fields in the packet being built. I assume the same is true for Thrift. My requirements are: 1. specify the location of fields in the packet 2. allow for bit fields 3. conditionals: a flag (bit field) = true means that data can appear at a later location in the packet 4. ability to define a packet structure by referring to another packet definition

Thank you.

("Flavor" on SourceForge, used for defining MPEG-4 might be a candidate, but I am looking for something that seems to have more of a community and preferably works in a .NET environment.)

A: 

How about C# itself?

eg

class MySimplePDLData {
  // format: name (or blank if padding), bit length, value (or blank if data),
  // name of presence flag field (or blank if no presence flag), C# type
  // one packet type per string, fields separated by pipes (|)
  string[] pdl = {

// MY-SIMPLE-PDL-START

  ",8,0xf8,|version,8,,Int32|type,8,,Int32|id1,64,,Int64",
  ...

// MY-SIMPLE-PDL-END

  };
}

If the data is already in memory, you don't need to do IO on a file format. From here you can either dynamically interpret packes or generate the necessary C# source code for packet recognition/pack/unpack, again using C# itself.

martinr
+2  A: 

I'd be interested in the reasons for your requirements. Why do you need to control the position of the fields? Why are bitfields important? Conditionals?

It sounds like you have a (more or less) fixed wire format for which you need to write a parser for, and in that case none of the existing popular protocol/serialization formats (Protobufs, Thrift, JSON, Yaml, etc.) will work for you.

A somewhat unorthodox approach is to use Erlang or Haskell, both of which have good support for parsing binary protocols.

JesperE
I need to control the position of the fields because the protocol defintion that we work with demands this. Bitfields are important, again because the protocol defines this. Conditionals are necessary because a field set can demand that another field be created. I will check your lead about Erlang and Haskell.
Mr. T.

related questions