V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
wohenfuyou
V2EX  ›  C++

关于 protobuf proto 类型映射到 c++类型

  •  
  •   wohenfuyou · Jan 20, 2021 · 2106 views
    This topic created in 1935 days ago, the information mentioned may be changed or developed.

    我得测试代码,proto bytes 类型代码生成 c++类型是 string*,官方文档写的是 string

    proto 文件:

    message RTKEY
    {
    optional int64 id1 = 1;
    optional int64 id2 = 2;
    };

    message ControlArea
    {
    optional RTKEY id = 1;
    optional bytes name = 2;
    optional RTKEY parent = 3;
    optional int32 level = 4;
    optional bool remove_fg = 5;
    }

    自动生成的代码文件:

    ::mytest::RTKEY* id_;
    ::std::string* name_;
    ::mytest::RTKEY* parent_;
    ::google::protobuf::int32 level_;
    bool remove_fg_;

    为什么生成的代码里是 string类型呢?因为这个 string 代码出现了问题。。

    1 replies    2021-01-22 07:57:19 +08:00
    terryching
        1
    terryching  
       Jan 22, 2021 via Android
    string *是内部使用的,你用接口获取和设置都是 string
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3465 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 10:41 · PVG 18:41 · LAX 03:41 · JFK 06:41
    ♥ Do have faith in what you're doing.