PaolaJ.
PaolaJ.

Reputation: 11532

Use enums from external class to avoid define in .proto?

I have three different format of messages in code and I made all three .proto files and compiled. I already have another, to say regular,class with lots of enums and I need to use that enums in all three classes. Is there any way to use enums from external-regular class and not to define in proto in all three files same enums ?

Upvotes: 4

Views: 2136

Answers (1)

poolie
poolie

Reputation: 9515

I'm not quite sure what you mean by an external-regular class...?

If you want to define the enum in C++, and then put it in a Protobuf, just put an int field in the proto.

But if you want a common enum used by multiple protos, you can use imports:

common.proto:

package foo_common;

enum Color {
    red = 1;
    black = 2;
}

tree.proto:

package foo_tree;

import "common.proto";

message Node {
     optional foo_common.Color color = 1;
};    

Upvotes: 2

Related Questions