C++ equivalent of Python's “construct” library

本秂侑毒 提交于 2019-12-10 11:38:25

问题


I'm looking for a library equivalent Python's "construct", maybe somebody has ported it.

Construct is a powerful declarative parser for binary data.

It is based on the concept of defining data structures in a declarative manner, rather than procedural code: Simple constructs can be combined hierarchically to form increasingly complex data structures. It's the first library that makes parsing fun, instead of the usual headache it is today.

This is similar question for java. Java equivalent of Python's "construct" library

Thanks.


回答1:


You might be interested in taking a look at Protocol Buffers. This library will let you write a description of your data in an intermediate language that can be compiled to C++, Java or python.




回答2:


For reference the OP is talking about this library called Construct. The library allows you to build parsers/constructors that can both parse and reconstruct the original binary data stream. "Construct is a powerful declarative and symmetrical parser and builder for binary data." This distinction is important when searching for a library similar to Construct. It really is unique and is a feature I really want in C++.

The closest library I can find is called binpac. However it is only creates a parser and is an external tool that generates C++ code.




回答3:


Why yes, structs, native to C and C++. Unless you want the ability to produce structs with a set of fields that can only be determined at runtime; in this case, malloc (to allocate the memory the struct variable will need) and some memcpys (to write data to the struct variable) should do the trick.



来源:https://stackoverflow.com/questions/9108425/c-equivalent-of-pythons-construct-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!