Aadil Hoda
Aadil Hoda

Reputation: 105

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.

Upvotes: 8

Views: 4821

Answers (1)

Hancel Lin
Hancel Lin

Reputation: 375

update like this:

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

Upvotes: 10

Related Questions