Search code examples
c++enumsprotocol-buffers

How to use the enum of one .proto file in another file?


For CPP programming, I have defined a enum in a .proto file and I have to use the same enum in another .proto file.

//first.proto
package A;
enum foo
{
    COUNTRY_UNKNOWN = 0;
    COUNTRY_INDIA = 1;
}

I want to use the foo data structure in another .proto file like this:

//second.proto
package B;
message bar
{
    foo currentCountry = 1;
}

I tried to just import package A into second.proto file but it is not able to work. I'm new to protobuf and CPP programming. Please guide.


Solution

  • update like this:

    import 'first.proto';
    package B;
    message
    {
        A.foo currentCountry = 1;
    }