我目前正在使用 Google Protocol Buffers重新审视一个项目。
在项目中,我想利用协议缓冲区的描述符和反射功能。
官方文档说明.proto文件的注释可以读取:
DebugStringWithOptions(),在消息或描述符上调用。GetSourceLocation(),在描述符上调用。我无法检索评论,因此我认为我做错了什么,或者该功能尚未在 Protocol Buffers 中完全实现。
下面是一些代码片段:
google::protobuf::DebugStringOptions options;
options.include_comments = true;
std::cout << "google::protobuf::Descriptor::DebugStringWithOptions(): "
<< message.descriptor()->DebugStringWithOptions(options) << std::endl
<< std::endl;
const google::protobuf::FieldDescriptor* field_descriptor{
message.descriptor()->field(1)};
// TODO(wolters): Why doesn't this work?
google::protobuf::SourceLocation* source_location{
new google::protobuf::SourceLocation};
field_descriptor->GetSourceLocation(source_location);
// if (field_descriptor->GetSourceLocation(source_location)) {
std::cout << "start_line: " << source_location->leading_comments
<< std::endl;
std::cout << "end_line: " << source_location->leading_comments << std::endl;
std::cout << "start_column: " << source_location->start_column …Run Code Online (Sandbox Code Playgroud)