gpt4 book ai didi

How to enable reflection for message created with DynamicMessageFactory?(如何为使用DynamicMessageFactory创建的消息启用反射?)

转载 作者:bug小助手 更新时间:2023-10-24 23:23:41 30 4
gpt4 key购买 nike



Code that creates a message:

创建消息的代码:


std::unique_ptr<Message> MessagePacker::BuildMessage() const {
google::protobuf::DynamicMessageFactory factory;
Message* msg = factory.GetPrototype(descriptor_)->New();
return std::unique_ptr<Message>(msg);
}

Test code:

测试代码:


  MessagePacker packer(HelloRequest::descriptor());
auto result = packer.BuildMessage();
ASSERT_NE(result, nullptr);
std::cerr << result->GetReflection() << std::endl;

Reflection is null. Can't get field values, can't do DebugString.

反射为空。无法获取字段值,无法执行DebugString。


How can I enable the reflection?

如何启用反射?


This returns a non-null pointer: HelloRequest().GetReflection()

这将返回一个非空指针:HelloRequest().GetReflect()


更多回答
优秀答案推荐
更多回答

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com