Conversion between C structs (C++ POD) and google protobufs?

前端 未结 3 2004
南旧
南旧 2021-02-08 22:51

I have code that currently passes around a lot of (sometimes nested) C (or C++ Plain Old Data) structs and arrays.

I would like to convert these to/from google protobu

3条回答
  •  渐次进展
    2021-02-08 23:18

    I could not find a ready solution for this problem, if there is one, please let me know!

    If you decide to roll your own in python, the python bindings for gdb might be useful. You could then read the symbol table, find all structs defined in specified file, and iterate all struct members. Then use .strip_typedefs() to get the primitive type of each member and translate it to appropriate protobuf type.

    This is probably safer then a text parsers as it will handle types that depends on architecture, compiler flags, preprocessor macros, etc.

    I guess the code to convert to and from protobuf also could be generated from the struct member to message field relation, but does not sound easy.

提交回复
热议问题