如何生成 C++带有 Apache Avro 的标头(python 脚本)
我有兴趣使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想做到这一点的唯一方法是:
-- 正则表达式
-- 文件系统
-- 系统
--program_options
构建 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
您现在可以生成头文件(仍在虚拟机的终端窗口中):
请注意,即使生成 C++ 文件后,您仍然无法在 Windows 中使用它进行构建(即使您拥有正确的权限)依赖项包括 avro-cpp-1.5.1/api。Avro 依赖于 GNU 库(例如 sys/uio.h),我还不确定如何具体解决它们。
About the only way I figured to do this is to:
-- regex
-- filesystem
-- system
-- program_options
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):
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.
我发现需要 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/