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()
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!