json
lainegates
think more, code less.
展开
-
json 与 protobuf.any 互转
最近用到加载配置文件为 protobuf 的功能,因为多配置,需要使用protobuf.any功能。问题:写好json后,json 中的内容对应 protobuf.any 的部分无法正常解析网上搜索许久,最后还是鼓哥给力,一下找到了结果。解决方法:protobuf.any的实现原理为封装的protobuf.message转换的串+此message的类型(即type)。因此,官方的方案很直接,在对应protobuf.any部分的json串,添加一个json项@type,内容为type.googl原创 2021-12-06 16:51:38 · 2304 阅读 · 0 评论 -
c++ protobuf与json互转
需要添加的头文件#include <google/protobuf/message.h>#include <google/protobuf/util/json_util.h>#include <google/protobuf/text_format.h>json串与protobuf的message互转// json-string 转 protobuf messagegoogle::protobuf::util::JsonStringToMessage(con原创 2021-11-26 10:11:54 · 5634 阅读 · 4 评论