解决GoogleProtocolBuffers 枚举的问题
发表于2018-06-05
有如下的proto文件:
syntax = "proto3"; enum GameType { Invalid = 0; RPG = 1; } enum ComputerType { Invalid = 0; PC = 1; }在编译的时候就会报错,因为要兼容C++,会有如下的报错:
test.proto:11:9: "Invalid" is already defined.
test.proto:11:9: Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it. Therefore, "Invalid" must be unique within the global scope, not just within "ComputerType".
test.proto:11:9: Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it. Therefore, "Invalid" must be unique within the global scope, not just within "ComputerType".
解决方法如下:
syntax = "proto3"; message GameType { enum Enum { Invalid = 0; RPG = 1; } } message ComputerType { enum Enum { Invalid = 0; PC = 1; } }但是呢,具体在运行的时候会有什么样的问题,目前我还没有遭遇,这只是提供了一个解决编译报错的方法。
还请各位自行斟酌!