Reputation: 1
when I use protobuf compile java specifity enum,my enum.proto code:
enum QosP{
AT_MOST_ONCE = 0;
AT_LEAST_ONCE = 1;
EXACTLY_ONCE = 2;
required int32 val = AT_MOST_ONCE.value;
}
I always get a error,as follow : Missing numeric value for enum constant. required int32 val always can not compile.plz I need help.
I try to use proto2 and proto3 to compile,and find many document,but solution this problem.
I want to use protobuf comiple java enum, structure is as follow:
enum QosP{
AT_MOST_ONCE = 0;
AT_LEAST_ONCE = 1;
EXACTLY_ONCE = 2;
required int32 val = AT_MOST_ONCE.value;
}
Upvotes: 0
Views: 193
Reputation: 6302
The enum declaration and usage should be done separately.
First declare the enum as a type:
enum QosP {
AT_MOST_ONCE = 0;
AT_LEAST_ONCE = 1;
EXACTLY_ONCE = 2;
}
Then use the enum to define the type of a field. A default value can be defined too:
message Something {
QosP val = 1 [default = AT_LEAST_ONCE];
}
Upvotes: 1