2

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.

Patrick Desjardins
  • 136,852
  • 88
  • 292
  • 341
OJW
  • 4,514
  • 6
  • 40
  • 48

3 Answers3

5

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
  • 733,204
  • 149
  • 1,241
  • 1,454
  • 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 Dec 15 '08 at 21:50
  • 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 Dec 15 '08 at 22:10
  • @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 Dec 15 '08 at 22:36
2

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.

albert
  • 8,285
  • 3
  • 19
  • 32
Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
  • 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 Dec 15 '08 at 22:13
1

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
  • 15,990
  • 10
  • 70
  • 110