views:

411

answers:

6

If you have a binary file format (or packet format) which is described as a C structure, are there any programs which will parse the structure and turn it into neat documentation on your protocol?

The struct would of course contain arrays, other structures, etc., as necessary to describe the format. The documentation would probably need to include things like packing, endianness, etc.

+2  A: 

Doxygen is a commonly-used documentation generator. However, if you want to get useful documentation, you'll probably have to mark up your structure definitions with doc comments.

Adam Rosenfield
Though Doxygen is more for providing a hypertext way of browsing around your code than for creating a document? Visually, doxygen's output will end looking very similar to the C header that you gave it as input?
OJW
+4  A: 

Maybe you should think about this a different way.

"Can I create a documentation format for my packet for which I can generate a C struct?"

Consider for example using XML to define the packet structure and add elements for comments and so forth. It wil be fairly easy to write a simple program that transformed it into an actual C structure

JaredPar
at least give a reason. Down voting a legitimate answer without a comment is plain rude. If you think I'm wrong enough to down vote, you should have at least a sentence to say about it.
JaredPar
Well, I don't know about the other guy, but I voted you up. This is the right way to go. Describe, generate. One description can be used to generate many kinds of code, and many kinds of documentation. However, I disagree that writing the generator is simple. Worth it? Yes. Simple? If you're lucky.
Troy Howard
yes, you could start with a different format (your own design of XML file, yEd graph, etc instead of a C header) but does that really modify the question so much?I'm more interested in tools which actually exist to use now, rather than ideas for a new software project to do.
OJW
@ojw. I'm guessing there are currently generators out there that would do pretty much exactly this. However I don't know of any off hand. Most of my work with generators has been for in house projects. The generators were fast, cheap and easy to write. Sharing would have required more effort
JaredPar
A: 

as JaredPar says, an alternate phrasing of this question is:

"What is a good method for describing binary structures?

e.g. something like ABNF but capable of doing bit-packing, endianness, etc.

preferably there would be existing tools to generate not just documentation, but C headers, unpack or struct patterns, and validation tools based on the description"

OJW
There are some tools like that. See [my previous response][1][1]: http://stackoverflow.com/questions/321423/parsing-binary-data-in-c#323123
bortzmeyer
@bortzmeyer: that was the best answer - but it's in a comment so I can't upvote it or anything
OJW
A: 

Of course, if such a thing existed, it would be used to write protocol dissectors for WireShark - the fact that each dissector is implemented in C code implies that it's difficult to express binary formats in a generic way

OJW
They exist. See http://stackoverflow.com/questions/321423/parsing-binary-data-in-c#323123
bortzmeyer
A: 

If you know perl you can try playing with Jeeves:

https://www.rodhughes.com/perl/advprog/examples/Jeeves/

(This source is there; I assume it's all right to use. ;) )

I'm trying to work out something similar to what you need: a parser for structured binary data. I'm looking to Jeeves to output parsing classes in C++ from a meta format. The default parser for Jeeves allows for adding additional tags to each member of a class definition. This would let you automatically include information about endianness, alignment, etc. in comments within your classes (and, of course, implement them in your code).

John at CashCommons