syntax = "proto3";
option csharp_namespace = "Demo";
option java_package = "Demo";
package Demo;
enum Scenario {
scenario_unknow=0;
type1=1;
scenario2=2;
}
enum Color {
COLOR_RED = 0;
COLOR_GREEN = 1;
COLOR_BLUE = 2;
}
生成的 C#代码
#region Enums
public enum Scenario {
[pbr::OriginalName("scenario_unknow")] Unknow = 0,
[pbr::OriginalName("type1")] Type1 = 1,
[pbr::OriginalName("scenario2")] _2 = 2,
}
public enum Color {
[pbr::OriginalName("COLOR_RED")] Red = 0,
[pbr::OriginalName("COLOR_GREEN")] Green = 1,
[pbr::OriginalName("COLOR_BLUE")] Blue = 2,
}
#endregion
java 代码
public enum Scenario
implements com.google.protobuf.ProtocolMessageEnum {
/**
* scenario_unknow = 0;
*/
scenario_unknow(0),
/**
* type1 = 1;
*/
type1(1),
/**
* scenario2 = 2;
*/
scenario2(2),
UNRECOGNIZED(-1),
;
}
public enum Color
implements com.google.protobuf.ProtocolMessageEnum {
/**
* COLOR_RED = 0;
*/
COLOR_RED(0),
/**
* COLOR_GREEN = 1;
*/
COLOR_GREEN(1),
/**
* COLOR_BLUE = 2;
*/
COLOR_BLUE(2),
UNRECOGNIZED(-1),
;
}
可以看到生成后的枚举成员中自动将枚举名称替换成空白了.这导致 Scenario.scenario2 生成的代码中成员名为 _2
也许这多半是by design的,但是,是否有选项可以控制这种行为?
谢谢