我的proto文件中有两个枚举,它们定义了几乎相同的值。
有可能删掉其中一个并留下一个别名来保持所有代码的工作吗?
示例:
enum A {
a = 0;
b = 1;
}
enum B {
a = 0;
b = 1;
}
我想在c++中有一些类似typedef的东西:
enum A {
a = 0;
b = 1;
}
typedef A B;
我在文档中没有找到这个。有什么变通办法吗?
这是一个老问题,但如果有些人仍然感兴趣,现在可以使用protobuf 在枚举上创建别名
enum EnumAllowingAlias {
option allow_alias = true;
UNKNOWN = 0;
STARTED = 1;
RUNNING = 1;
}
enum EnumNotAllowingAlias {
UNKNOWN = 0;
STARTED = 1;
// RUNNING = 1; // Uncommenting this line will cause a compile error inside Google and a warning message outside.
}
如官方文件所述。您只需要通过添加option allow_alias = true;
来启用别名选项
从protobuf版本3开始,这是不可能的。