如何生成 C++带有 Apache Avro 的标头(python 脚本)

发布于 2024-11-28 04:12:29 字数 1680 浏览 3 评论 0原文

我有兴趣使用 Apache Avro 的代码生成工具(即 python 脚本)生成 C++ 标头。 根据文档应该相当容易做,但我通常不使用 python,所以事情对我来说看起来有点奇怪。

说明指出:

生成代码的过程分为两步:

precompile < imaginary > imaginary.flat

预编译步骤将架构转换为代码生成器使用的中间格式。该中间文件只是模式的基于文本的表示,通过模式类型的树结构的深度优先遍历进行扁平化。

python scripts/gen-cppcode.py --input=example.flat --output=example.hh –-namespace=Math

这告诉代码生成器读取您的扁平架构作为其输入,并在 example.hh 中生成 C++ 头文件。可选参数名称空间会将对象放入该名称空间中...

我的问题(不,我不能去看医生或使用霜):

我没有看到任何详细解释如何预编译的内容。该文档看起来好像如果我只是在命令提示符中键入“预编译”并提供命令行参数,那么事情就会神奇地工作,但预编译不是有效的 Windows 命令。 那么在 Windows 上预编译的正确方法是什么?如果有人知道如何做,请告诉我!

我还尝试运行 gen-cppcode .py 脚本,但它在第 316 行出现错误(我怀疑这可能是因为我没有预编译架构而发生的):

def doEnum(args):
    structDef = enumTemplate;
    typename = args[1]
    structDef = structDef.replace('$name$', typename)
    end = False
    symbols = '';
    firstsymbol = '';
    while not end:
        line = getNextLine()
        if line[0] == 'end': end = True
        elif line[0] == 'name':
            if symbols== '' :
                firstsymbol = line[1]
            else :
                symbols += ', '
            symbols += line[1]
        else: print "error" // <-- Syntax Error: invalid syntax
    structDef = structDef.replace('$enumsymbols$', symbols);
    structDef = structDef.replace('$firstsymbol$', firstsymbol);
    addStruct(typename, structDef)
    return (typename,typename)

I am interested in generating a C++ header using Apache Avro's code generation tool (i.e. the python script). According to the documentation it should be fairly easy to do, but I don't usually use python, so things look kinda strange to me.

The instructions state:

To generate the code is a two step process:

precompile < imaginary > imaginary.flat

The precompile step converts the schema into an intermediate format that is used by the code generator. This intermediate file is just a text-based representation of the schema, flattened by a depth-first-traverse of the tree structure of the schema types.

python scripts/gen-cppcode.py --input=example.flat --output=example.hh –-namespace=Math

This tells the code generator to read your flattened schema as its input, and generate a C++ header file in example.hh. The optional argument namespace will put the objects in that namespace...

My Issue (no, I can't see a doctor or use a cream for it):

I don't see anything that explains in details how to precompile. The documentation makes it seem like if I just type "precompile" in the command prompt and supply the command line arguments, then things would magically work, but precompile is not a valid Windows command. So what's the proper way to precompile on Windows? If anybody knows how to do it, then PLEASE let me know!

I also tried to run the gen-cppcode.py script, but it gets an error in line 316 (which, I suspect, may be happening because I didn't precompile the schema):

def doEnum(args):
    structDef = enumTemplate;
    typename = args[1]
    structDef = structDef.replace('$name
, typename)
    end = False
    symbols = '';
    firstsymbol = '';
    while not end:
        line = getNextLine()
        if line[0] == 'end': end = True
        elif line[0] == 'name':
            if symbols== '' :
                firstsymbol = line[1]
            else :
                symbols += ', '
            symbols += line[1]
        else: print "error" // <-- Syntax Error: invalid syntax
    structDef = structDef.replace('$enumsymbols
, symbols);
    structDef = structDef.replace('$firstsymbol
, firstsymbol);
    addStruct(typename, structDef)
    return (typename,typename)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纸伞微斜 2024-12-05 04:12:29

我想做到这一点的唯一方法是:

  1. 下载 VirtualBox。
  2. 安装 Ubuntu(或其他发行版)。
  3. 下载阿夫罗。
  4. 安装cmake。
  5. 安装 C++ 编译器(构建必需)。
  6. 安装 boost、flex、bison (sudo apt-get install boost flex bison);顺便说一句,您将特别需要这些 boost 库:
    -- 正则表达式
    -- 文件系统
    -- 系统
    --program_options
  7. 构建 Avro:

    $ tar xf avro-cpp-1.5.1.tar.gz
    $ cd avro-cpp-1.5.1
    $ cmake -G "Unix Makefiles"
    $ make -j3
    $ build/precompile file.input file.flatoutput

您现在可以生成头文件(仍在虚拟机的终端窗口中):

python 脚本/gen-cppcode.py --input=example.flat --output=example.hh

请注意,即使生成 C++ 文件后,您仍然无法在 Windows 中使用它进行构建(即使您拥有正确的权限)依赖项包括 avro-cpp-1.5.1/api。Avro 依赖于 GNU 库(例如 sys/uio.h),我还不确定如何具体解决它们。

About the only way I figured to do this is to:

  1. Download VirtualBox.
  2. Install Ubuntu (or another distro).
  3. Download Avro.
  4. Install cmake.
  5. Install the C++ compilers (build essential).
  6. Install boost, flex, bison (sudo apt-get install boost flex bison); btw, you will specifically need these boost libraries:
    -- regex
    -- filesystem
    -- system
    -- program_options
  7. Build Avro:

    $ tar xf avro-cpp-1.5.1.tar.gz
    $ cd avro-cpp-1.5.1
    $ cmake -G "Unix Makefiles"
    $ make -j3
    $ build/precompile file.input file.flatoutput

You can now generate a header file (still in the terminal window of the VM):

python scripts/gen-cppcode.py --input=example.flat --output=example.hh

Note that even after you generate the C++ file, you will still be unable to build with it in Windows (even if you have the right dependency includes to the avro-cpp-1.5.1/api. Avro has dependencies on GNU libraries (such as sys/uio.h) and I'm not sure how to specifically resolve them yet.

雨巷深深 2024-12-05 04:12:29

我发现需要 python 版本 2 才能运行 gen-cppcode.py

https:/ /www.python.org/downloads/

I found that it is required python version 2 to run gen-cppcode.py

https://www.python.org/downloads/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文