简体   繁体   English

记录C结构的程序?

[英]Program for documenting a C struct?

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? 如果你有一个被描述为C结构的二进制文件格式(或数据包格式),是否有任何程序可以解析结构并将其转换为协议的简洁文档?

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. 文档可能需要包含诸如打包,字节顺序等内容。

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?" “我可以为我的数据包创建一个文档格式,我可以生成一个C结构吗?”

Consider for example using XML to define the packet structure and add elements for comments and so forth. 例如,考虑使用XML来定义数据包结构并添加注释元素等等。 It wil be fairly easy to write a simple program that transformed it into an actual C structure 编写一个将其转换为实际C结构的简单程序会相当容易

Doxygen is a commonly-used doc umentation gen erator. Doxygen的是一个常用的DOC umentation 爱适易。 However, if you want to get useful documentation, you'll probably have to mark up your structure definitions with doc comments. 但是,如果您想获得有用的文档,则可能需要使用doc注释标记结构定义。

If you know perl you can try playing with Jeeves: 如果你认识perl,你可以尝试与Jeeves一起玩:

https://www.rodhughes.com/perl/advprog/examples/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. 我期待Jeeves从元格式输出C ++中的解析类。 The default parser for Jeeves allows for adding additional tags to each member of a class definition. Jeeves的默认解析器允许向类定义的每个成员添加其他标记。 This would let you automatically include information about endianness, alignment, etc. in comments within your classes (and, of course, implement them in your code). 这将允许您自动在类中的注释中包含有关字节顺序,对齐等的信息(当然,在代码中实现它们)。

as JaredPar says, an alternate phrasing of this question is: 正如JaredPar所说,这个问题的替代措辞是:

"What is a good method for describing binary structures? “描述二元结构的好方法是什么?

eg something like ABNF but capable of doing bit-packing, endianness, etc. 例如像ABNF这样的东西但能够进行比特打包,字节顺序等。

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" 优选地,现有工具不仅可以生成文档,还可以生成C头, 解包结构模式,以及基于描述的验证工具“

当然,如果存在这样的事情,它将用于为WireShark编写协议解析器 - 事实上每个解剖器都是用C代码实现的,这意味着很难以通用的方式表达二进制格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM