【问题标题】:GoogleProtobuf repeated messagesGoogleProtobuf 重复消息
【发布时间】:2022-07-12 00:53:37
【问题描述】:

我有一个 .proto 文件,其中包含以下消息:

message A {
    message B {
        optional string Header = 1;
        optional string Value = 2;
    }
    repeated B Inputs = 1;
}
message BuildConfig {
    optional A Options = 1;
}

在我的 pb.h 文件中有以下函数:

类 BuildConfig:

inline const ::google::protobuf::RepeatedPtrField< ::NBuildModels::NProto::A >&
      GetOptions() const { return options(); }

A 类:

inline const ::google::protobuf::RepeatedPtrField< ::NBuildModels::NProto::A_B >&
      GetInputs() const { return inputs(); }  

我正在尝试像这样访问 Head 和 Value:

void foo(const NBuildModels::NProto::BuildConfig& config) {
auto a = config.GetOptions();
auto b = a.GetInputs();
}

但是,它不适用于以下错误:“google::protobuf::RepeatedPtrFieldNBuildModels::NProto::A”中没有名为“GetInputs”的成员

【问题讨论】:

    标签: c++ proto


    【解决方案1】:

    你使用什么 protobuf 语法?你用什么protogen?认识我protogen 都不会生成 C++ 方法GetOptionsGetInputs。在 Google protogensyntax = "proto3"; 之后,这对我有用:

    auto& a = config.options();
    auto& b = a.inputs();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-28
      • 2021-03-17
      • 2013-02-12
      • 1970-01-01
      • 2018-09-05
      • 2019-05-24
      • 2021-12-17
      • 1970-01-01
      相关资源
      最近更新 更多