title: Meta language to code generate packed structs for ANSI-C and C# Structs
body: <p>I'm trying to find a "meta language" that can be used to define a structure and get/set code for members. The catch is that the structure already exists in code, and this "meta language" would serve as bit-for-bit replacement of the original hand-coded structure to allow the headers describing the structures to be generated.  The point is that the structures are used as part of a protocol between a C# application and an embedded device (not linux based, think smaller and more constrained like a PIC or CM0.)
  The meta language would act as</p>
  
  <ul>
  <li>Documentation for the structure members</li>
  <li>Generate C# structs and implementation for get/set operations</li>
  <li>Generate packed ANSI-C structs and get/set functions</li>
  </ul>
  
  <p>The meta language would need to support</p>
  
  <ul>
  <li>enumeration definitions (of a specified size - ie uint16_t, uint8_t, or smaller as for multi-bit enumerations)</li>
  <li>bit-arrays (of specified size - ie 48-bit array is packed into 6 bytes,)</li>
  <li>bit-structure/enumeration arrays (of specified size - ie a 2-bit structure of 48 indexes is 12 bytes,)</li>
  <li>specification for endianness and bit-order,</li>
  <li>generate binary structures that can be read directly by either the generated ANSI-C code or the C-sharp code for the purpose of sending over a network.</li>
  </ul>
  
  <p>It would also be nice to have some limited validation of the data when received.</p>
  
  <p>So far I've looked at</p>
  
  <ul>
  <li>BSON</li>
  <li>Etch</li>
  <li>Hessian Avro</li>
  <li>ICE</li>
  <li>MessagePack</li>
  <li>Protocol Buffers</li>
  <li>Thrift</li>
  </ul>
  
  <p>All of these are great for documentation and when building a new protocol, but trying to maintain compatibility with an existing protocol and these fall short due to the type encoding inherent in the data marshaling.</p>
  
  <p>I've also looked at ASN.1 for ECN encoding, but that seems to be too unreadable causing issue with Documentation.</p>
  
  <p>I've looked at <a href="https://stackoverflow.com/questions/12117407/generating-c-sharp-structure-from-c-structure">Generating C# structure from C structure</a> but there wasn't a good option there.</p>
  
  <p>Any recommendations?</p>