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

2021-01-20 14:07:47 +08:00
 wohenfuyou

我得测试代码,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 代码出现了问题。。

1752 次点击
所在节点    C++
1 条回复
terryching
2021-01-22 07:57:19 +08:00
string *是内部使用的,你用接口获取和设置都是 string

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/746678

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX