简体   繁体   English

C ++等同于Python的“构造”库

[英]C++ equivalent of Python's “construct” library

I'm looking for a library equivalent Python's "construct", maybe somebody has ported it. 我正在寻找一个等效于Python的库“ construct”,也许有人已经移植了它。

Construct is a powerful declarative parser for binary data. Construct是一个强大的二进制数据声明式解析器。

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,这是类似的问题。 Java equivalent of Python's "construct" library Java等同于Python的“构造”库

Thanks. 谢谢。

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. 该库使您可以使用可编译为C ++,Java或python的中间语言编写数据描述。

For reference the OP is talking about this library called Construct . 作为参考,OP正在谈论这个称为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." “ Construct是一个功能强大的声明性和对称解析器,并且是二进制数据的构建器。” This distinction is important when searching for a library similar to Construct. 当搜索类似于Construct的库时,这一区别很重要。 It really is unique and is a feature I really want in C++. 它确实是唯一的,并且是我在C ++中真正想要的功能。

The closest library I can find is called binpac . 我可以找到的最接近的库称为binpac However it is only creates a parser and is an external tool that generates C++ code. 但是,它仅创建解析器,并且是生成C ++代码的外部工具。

Why yes, struct s, native to C and C++. 为什么是struct s,它是C和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 memcpy s (to write data to the struct variable) should do the trick. 在这种情况下, malloc (分配struct变量所需的内存)和一些memcpy s(将数据写入struct变量)应该可以解决问题。

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

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