我是protobuf使用的新手。
我打算用enum(s)编写protobuf def。
有没有办法提供id,值和描述。
编译后我希望生成的枚举应该等效于下面的例子
enum Sample{
W(0, "W"), P(0, "P"), C(0, "C"), B(0, "B")
private final int id;
private final String value;
private Status(int id, String value) {
this.id= id;
this.value = value;
}
}
非常感谢任何帮助。
答案 0 :(得分:2)
在您的示例中无法准确生成Java枚举,但您可以使用"自定义选项"向protobuf声明添加任意注释。请参阅the documentation(稍微向下滚动到"自定义选项")。
import "google/protobuf/descriptor.proto";
extend google.protobuf.EnumValueOptions {
optional string name = 51234;
}
enum MyEnum {
FOO = 0 [(name) = "foo"];
BAR = 1 [(name) = "bar"];
}
可以通过EnumValueDescriptor
界面访问注释。