protobuf 版本3.12.1
Importer 动态读入proto文件原型DescriptorPoolDynamicMessageFactory 生产Message message Test {
optional string name = 1;
} Importer import(&tree, nullptr);
// 可以加载多个文件(依赖)
import.Import("/path/test.proto");
import.Import("/path/other.proto");
auto pool = import.pool();
auto desc = pool->FindFileByName("test.proto");
google::protobuf::DynamicMessageFactory factory;
const google::protobuf::Message *prototype_msg = factory.GetPrototype("Test");
auto instance = prototype_msg->New();
instance->ParseFromString(contents);原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。