大佬教程收集整理的这篇文章主要介绍了将整个 C++ 数据结构转换/转换为 protobuf 消息实例,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的代码包含多个复杂的 C++ 数据结构,我想将它们保存到磁盘以便以后反序列化以再次使用。 让我们举一个例子来轻松理解我想要做什么。我有以下 C++ 结构:
struct myCstruct
{
int id;
OtherStructType ot;
std::vector<std::string> my_array;
std::vector<StructType_2> my_other_array;
};
我编写了等效的 .proto
文件来表示 @H_271_5@myCstruct:
Syntax = "proto3";
import "OtherStructType.proto"; // OtherStructType proto code is here
import "3drStructType.proto"; // 3drStructType proto code is here
package my_ns;
message myCstruct{
int32 ID = 1;
OtherStructType ot = 2;
repeated String my_array = 3;
repeated StructType_2 my_other_array = 4;
}
在我的代码中的某处,我有一个引用 foo
实例的变量 @H_271_5@myCstruct。鉴于我已经编译了 @H_271_5@my_ns::myCstruct 文件并将生成的 C++ 文件包含在我的项目中,我现在如何将 var 转换为类型 .proto
?:
struct myCstruct var = some_func();
my_ns::myCstruct proto_struct;
// How can I dump the content of var into proto_struct???
我知道 protobuf
创建方法来设置属性,但我想在 protobuf 类实例中转储 C++ 结构的全部内容。我不想:
struct myCstruct var = some_func();
my_ns::myCstruct proto_struct;
proto_struct_set_ID(var.ID);
proto_struct_set_ot(var.ot);
...
感谢任何帮助。
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的将整个 C++ 数据结构转换/转换为 protobuf 消息实例全部内容,希望文章能够帮你解决将整个 C++ 数据结构转换/转换为 protobuf 消息实例所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。