GoogleProtobuf repeated messages

298 Views Asked by At

I have a .proto file which consists of following messages:

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

In my pb.h file there are following functions:

class BuildConfig:

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

class A:

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

I am trying to access Head and Value like this:

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

However, it does not work with the following error : No member named 'GetInputs' in 'google::protobuf::RepeatedPtrFieldNBuildModels::NProto::A'

1

There are 1 best solutions below

0
273K On

What protobuf syntax do you use? What protogen do you use? Neither of known me protogen generates the C++ methods GetOptions and GetInputs. This works for me after Google protogen with syntax = "proto3";:

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