cmd/protoc-gen-go: group enum map vars in blocks

Since the enum maps are here to stay, group the declarations together
in a var block for better readability in godoc.

Change-Id: I9a313266539e9a60781f98b80a5293379f82607b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/189077
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Joe Tsai 2019-08-05 18:38:48 -07:00
parent d29a71bff0
commit 9b8a433283
28 changed files with 6038 additions and 5748 deletions

View File

@ -26,10 +26,6 @@ import (
)
const (
// generateEnumMapVars specifies whether to generate enum maps,
// which provide a bi-directional mapping between enum numbers and names.
generateEnumMapVars = true
// generateEnumJSONMethods specifies whether to generate the UnmarshalJSON
// method for proto2 enums.
generateEnumJSONMethods = true
@ -294,33 +290,25 @@ func genEnum(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, enum
g.P(")")
g.P()
// Enum value mapping (number -> name).
if generateEnumMapVars {
nameMap := enum.GoIdent.GoName + "_name"
g.P("var ", nameMap, " = map[int32]string{")
generated := make(map[protoreflect.EnumNumber]bool)
for _, value := range enum.Values {
duplicate := ""
if _, present := generated[value.Desc.Number()]; present {
duplicate = "// Duplicate value: "
}
g.P(duplicate, value.Desc.Number(), ": ", strconv.Quote(string(value.Desc.Name())), ",")
generated[value.Desc.Number()] = true
// Enum value maps.
g.P("// Enum value maps for ", enum.GoIdent, ".")
g.P("var (")
g.P(enum.GoIdent.GoName+"_name", " = map[int32]string{")
for _, value := range enum.Values {
duplicate := ""
if value.Desc != enum.Desc.Values().ByNumber(value.Desc.Number()) {
duplicate = "// Duplicate value: "
}
g.P("}")
g.P()
g.P(duplicate, value.Desc.Number(), ": ", strconv.Quote(string(value.Desc.Name())), ",")
}
// Enum value mapping (name -> number).
if generateEnumMapVars {
valueMap := enum.GoIdent.GoName + "_value"
g.P("var ", valueMap, " = map[string]int32{")
for _, value := range enum.Values {
g.P(strconv.Quote(string(value.Desc.Name())), ": ", value.Desc.Number(), ",")
}
g.P("}")
g.P()
g.P("}")
g.P(enum.GoIdent.GoName+"_value", " = map[string]int32{")
for _, value := range enum.Values {
g.P(strconv.Quote(string(value.Desc.Name())), ": ", value.Desc.Number(), ",")
}
g.P("}")
g.P(")")
g.P()
// Enum method.
//

View File

@ -24,13 +24,15 @@ const (
AnnotationsTestEnum_ANNOTATIONS_TEST_ENUM_VALUE AnnotationsTestEnum = 0
)
var AnnotationsTestEnum_name = map[int32]string{
0: "ANNOTATIONS_TEST_ENUM_VALUE",
}
var AnnotationsTestEnum_value = map[string]int32{
"ANNOTATIONS_TEST_ENUM_VALUE": 0,
}
// Enum value maps for AnnotationsTestEnum.
var (
AnnotationsTestEnum_name = map[int32]string{
0: "ANNOTATIONS_TEST_ENUM_VALUE",
}
AnnotationsTestEnum_value = map[string]int32{
"ANNOTATIONS_TEST_ENUM_VALUE": 0,
}
)
func (x AnnotationsTestEnum) Enum() *AnnotationsTestEnum {
p := new(AnnotationsTestEnum)

View File

@ -1 +1 @@
annotation:{path:5 path:0 source_file:"annotations/annotations.proto" begin:590 end:609} annotation:{path:5 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:626 end:673} annotation:{path:4 path:0 source_file:"annotations/annotations.proto" begin:1904 end:1926} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:2070 end:2090} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:2984 end:3007}
annotation:{path:5 path:0 source_file:"annotations/annotations.proto" begin:590 end:609} annotation:{path:5 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:626 end:673} annotation:{path:4 path:0 source_file:"annotations/annotations.proto" begin:1953 end:1975} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:2119 end:2139} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:3033 end:3056}

View File

@ -23,13 +23,15 @@ const (
DeprecatedEnum_DEPRECATED DeprecatedEnum = 0 // Deprecated: Do not use.
)
var DeprecatedEnum_name = map[int32]string{
0: "DEPRECATED",
}
var DeprecatedEnum_value = map[string]int32{
"DEPRECATED": 0,
}
// Enum value maps for DeprecatedEnum.
var (
DeprecatedEnum_name = map[int32]string{
0: "DEPRECATED",
}
DeprecatedEnum_value = map[string]int32{
"DEPRECATED": 0,
}
)
func (x DeprecatedEnum) Enum() *DeprecatedEnum {
p := new(DeprecatedEnum)

View File

@ -27,13 +27,15 @@ const (
Enum_ZERO Enum = 0
)
var Enum_name = map[int32]string{
0: "ZERO",
}
var Enum_value = map[string]int32{
"ZERO": 0,
}
// Enum value maps for Enum.
var (
Enum_name = map[int32]string{
0: "ZERO",
}
Enum_value = map[string]int32{
"ZERO": 0,
}
)
func (x Enum) Enum() *Enum {
p := new(Enum)

View File

@ -26,13 +26,15 @@ const (
Enum_ZERO Enum = 0
)
var Enum_name = map[int32]string{
0: "ZERO",
}
var Enum_value = map[string]int32{
"ZERO": 0,
}
// Enum value maps for Enum.
var (
Enum_name = map[int32]string{
0: "ZERO",
}
Enum_value = map[string]int32{
"ZERO": 0,
}
)
func (x Enum) Enum() *Enum {
p := new(Enum)

View File

@ -31,13 +31,15 @@ const (
E_ZERO E = 0
)
var E_name = map[int32]string{
0: "ZERO",
}
var E_value = map[string]int32{
"ZERO": 0,
}
// Enum value maps for E.
var (
E_name = map[int32]string{
0: "ZERO",
}
E_value = map[string]int32{
"ZERO": 0,
}
)
func (x E) Enum() *E {
p := new(E)
@ -82,13 +84,15 @@ const (
M_M_ZERO M_Subenum = 0
)
var M_Subenum_name = map[int32]string{
0: "M_ZERO",
}
var M_Subenum_value = map[string]int32{
"M_ZERO": 0,
}
// Enum value maps for M_Subenum.
var (
M_Subenum_name = map[int32]string{
0: "M_ZERO",
}
M_Subenum_value = map[string]int32{
"M_ZERO": 0,
}
)
func (x M_Subenum) Enum() *M_Subenum {
p := new(M_Subenum)
@ -133,13 +137,15 @@ const (
M_Submessage_M_SUBMESSAGE_ZERO M_Submessage_Submessage_Subenum = 0
)
var M_Submessage_Submessage_Subenum_name = map[int32]string{
0: "M_SUBMESSAGE_ZERO",
}
var M_Submessage_Submessage_Subenum_value = map[string]int32{
"M_SUBMESSAGE_ZERO": 0,
}
// Enum value maps for M_Submessage_Submessage_Subenum.
var (
M_Submessage_Submessage_Subenum_name = map[int32]string{
0: "M_SUBMESSAGE_ZERO",
}
M_Submessage_Submessage_Subenum_value = map[string]int32{
"M_SUBMESSAGE_ZERO": 0,
}
)
func (x M_Submessage_Submessage_Subenum) Enum() *M_Submessage_Submessage_Subenum {
p := new(M_Submessage_Submessage_Subenum)

View File

@ -24,13 +24,15 @@ const (
E1_E1_ZERO E1 = 0
)
var E1_name = map[int32]string{
0: "E1_ZERO",
}
var E1_value = map[string]int32{
"E1_ZERO": 0,
}
// Enum value maps for E1.
var (
E1_name = map[int32]string{
0: "E1_ZERO",
}
E1_value = map[string]int32{
"E1_ZERO": 0,
}
)
func (x E1) Enum() *E1 {
p := new(E1)

View File

@ -24,13 +24,15 @@ const (
Enum_ZERO Enum = 0
)
var Enum_name = map[int32]string{
0: "ZERO",
}
var Enum_value = map[string]int32{
"ZERO": 0,
}
// Enum value maps for Enum.
var (
Enum_name = map[int32]string{
0: "ZERO",
}
Enum_value = map[string]int32{
"ZERO": 0,
}
)
func (x Enum) Enum() *Enum {
p := new(Enum)

View File

@ -28,15 +28,17 @@ const (
EnumType1_TWO EnumType1 = 2
)
var EnumType1_name = map[int32]string{
1: "ONE",
2: "TWO",
}
var EnumType1_value = map[string]int32{
"ONE": 1,
"TWO": 2,
}
// Enum value maps for EnumType1.
var (
EnumType1_name = map[int32]string{
1: "ONE",
2: "TWO",
}
EnumType1_value = map[string]int32{
"ONE": 1,
"TWO": 2,
}
)
func (x EnumType1) Enum() *EnumType1 {
p := new(EnumType1)
@ -82,15 +84,17 @@ const (
EnumType2_duplicate2 EnumType2 = 1
)
var EnumType2_name = map[int32]string{
1: "duplicate1",
// Duplicate value: 1: "duplicate2",
}
var EnumType2_value = map[string]int32{
"duplicate1": 1,
"duplicate2": 1,
}
// Enum value maps for EnumType2.
var (
EnumType2_name = map[int32]string{
1: "duplicate1",
// Duplicate value: 1: "duplicate2",
}
EnumType2_value = map[string]int32{
"duplicate1": 1,
"duplicate2": 1,
}
)
func (x EnumType2) Enum() *EnumType2 {
p := new(EnumType2)
@ -137,13 +141,15 @@ const (
EnumContainerMessage1_NESTED_1A_VALUE EnumContainerMessage1_NestedEnumType1A = 0
)
var EnumContainerMessage1_NestedEnumType1A_name = map[int32]string{
0: "NESTED_1A_VALUE",
}
var EnumContainerMessage1_NestedEnumType1A_value = map[string]int32{
"NESTED_1A_VALUE": 0,
}
// Enum value maps for EnumContainerMessage1_NestedEnumType1A.
var (
EnumContainerMessage1_NestedEnumType1A_name = map[int32]string{
0: "NESTED_1A_VALUE",
}
EnumContainerMessage1_NestedEnumType1A_value = map[string]int32{
"NESTED_1A_VALUE": 0,
}
)
func (x EnumContainerMessage1_NestedEnumType1A) Enum() *EnumContainerMessage1_NestedEnumType1A {
p := new(EnumContainerMessage1_NestedEnumType1A)
@ -188,13 +194,15 @@ const (
EnumContainerMessage1_NESTED_1B_VALUE EnumContainerMessage1_NestedEnumType1B = 0
)
var EnumContainerMessage1_NestedEnumType1B_name = map[int32]string{
0: "NESTED_1B_VALUE",
}
var EnumContainerMessage1_NestedEnumType1B_value = map[string]int32{
"NESTED_1B_VALUE": 0,
}
// Enum value maps for EnumContainerMessage1_NestedEnumType1B.
var (
EnumContainerMessage1_NestedEnumType1B_name = map[int32]string{
0: "NESTED_1B_VALUE",
}
EnumContainerMessage1_NestedEnumType1B_value = map[string]int32{
"NESTED_1B_VALUE": 0,
}
)
func (x EnumContainerMessage1_NestedEnumType1B) Enum() *EnumContainerMessage1_NestedEnumType1B {
p := new(EnumContainerMessage1_NestedEnumType1B)
@ -241,13 +249,15 @@ const (
EnumContainerMessage1_EnumContainerMessage2_NESTED_2A_VALUE EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A = 0
)
var EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A_name = map[int32]string{
0: "NESTED_2A_VALUE",
}
var EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A_value = map[string]int32{
"NESTED_2A_VALUE": 0,
}
// Enum value maps for EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A.
var (
EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A_name = map[int32]string{
0: "NESTED_2A_VALUE",
}
EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A_value = map[string]int32{
"NESTED_2A_VALUE": 0,
}
)
func (x EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A) Enum() *EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A {
p := new(EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A)
@ -292,13 +302,15 @@ const (
EnumContainerMessage1_EnumContainerMessage2_NESTED_2B_VALUE EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B = 0
)
var EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B_name = map[int32]string{
0: "NESTED_2B_VALUE",
}
var EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B_value = map[string]int32{
"NESTED_2B_VALUE": 0,
}
// Enum value maps for EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B.
var (
EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B_name = map[int32]string{
0: "NESTED_2B_VALUE",
}
EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B_value = map[string]int32{
"NESTED_2B_VALUE": 0,
}
)
func (x EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B) Enum() *EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B {
p := new(EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B)

View File

@ -26,15 +26,17 @@ const (
FieldTestMessage_ONE FieldTestMessage_Enum = 1
)
var FieldTestMessage_Enum_name = map[int32]string{
0: "ZERO",
1: "ONE",
}
var FieldTestMessage_Enum_value = map[string]int32{
"ZERO": 0,
"ONE": 1,
}
// Enum value maps for FieldTestMessage_Enum.
var (
FieldTestMessage_Enum_name = map[int32]string{
0: "ZERO",
1: "ONE",
}
FieldTestMessage_Enum_value = map[string]int32{
"ZERO": 0,
"ONE": 1,
}
)
func (x FieldTestMessage_Enum) Enum() *FieldTestMessage_Enum {
p := new(FieldTestMessage_Enum)

View File

@ -26,17 +26,19 @@ const (
Enum_TWO Enum = 2
)
var Enum_name = map[int32]string{
0: "ZERO",
1: "ONE",
2: "TWO",
}
var Enum_value = map[string]int32{
"ZERO": 0,
"ONE": 1,
"TWO": 2,
}
// Enum value maps for Enum.
var (
Enum_name = map[int32]string{
0: "ZERO",
1: "ONE",
2: "TWO",
}
Enum_value = map[string]int32{
"ZERO": 0,
"ONE": 1,
"TWO": 2,
}
)
func (x Enum) Enum() *Enum {
p := new(Enum)

View File

@ -24,13 +24,15 @@ const (
FieldTestMessage_ZERO FieldTestMessage_Enum = 0
)
var FieldTestMessage_Enum_name = map[int32]string{
0: "ZERO",
}
var FieldTestMessage_Enum_value = map[string]int32{
"ZERO": 0,
}
// Enum value maps for FieldTestMessage_Enum.
var (
FieldTestMessage_Enum_name = map[int32]string{
0: "ZERO",
}
FieldTestMessage_Enum_value = map[string]int32{
"ZERO": 0,
}
)
func (x FieldTestMessage_Enum) Enum() *FieldTestMessage_Enum {
p := new(FieldTestMessage_Enum)

View File

@ -34,17 +34,19 @@ const (
Enum_TEN Enum = 10
)
var Enum_name = map[int32]string{
1: "ONE",
2: "TWO",
10: "TEN",
}
var Enum_value = map[string]int32{
"ONE": 1,
"TWO": 2,
"TEN": 10,
}
// Enum value maps for Enum.
var (
Enum_name = map[int32]string{
1: "ONE",
2: "TWO",
10: "TEN",
}
Enum_value = map[string]int32{
"ONE": 1,
"TWO": 2,
"TEN": 10,
}
)
func (x Enum) Enum() *Enum {
p := new(Enum)
@ -91,17 +93,19 @@ const (
Enums_DIEZ Enums_NestedEnum = 10
)
var Enums_NestedEnum_name = map[int32]string{
1: "UNO",
2: "DOS",
10: "DIEZ",
}
var Enums_NestedEnum_value = map[string]int32{
"UNO": 1,
"DOS": 2,
"DIEZ": 10,
}
// Enum value maps for Enums_NestedEnum.
var (
Enums_NestedEnum_name = map[int32]string{
1: "UNO",
2: "DOS",
10: "DIEZ",
}
Enums_NestedEnum_value = map[string]int32{
"UNO": 1,
"DOS": 2,
"DIEZ": 10,
}
)
func (x Enums_NestedEnum) Enum() *Enums_NestedEnum {
p := new(Enums_NestedEnum)

View File

@ -27,19 +27,21 @@ const (
Enum_TEN Enum = 10
)
var Enum_name = map[int32]string{
0: "ZERO",
1: "ONE",
2: "TWO",
10: "TEN",
}
var Enum_value = map[string]int32{
"ZERO": 0,
"ONE": 1,
"TWO": 2,
"TEN": 10,
}
// Enum value maps for Enum.
var (
Enum_name = map[int32]string{
0: "ZERO",
1: "ONE",
2: "TWO",
10: "TEN",
}
Enum_value = map[string]int32{
"ZERO": 0,
"ONE": 1,
"TWO": 2,
"TEN": 10,
}
)
func (x Enum) Enum() *Enum {
p := new(Enum)
@ -77,19 +79,21 @@ const (
Enums_DIEZ Enums_NestedEnum = 10
)
var Enums_NestedEnum_name = map[int32]string{
0: "CERO",
1: "UNO",
2: "DOS",
10: "DIEZ",
}
var Enums_NestedEnum_value = map[string]int32{
"CERO": 0,
"UNO": 1,
"DOS": 2,
"DIEZ": 10,
}
// Enum value maps for Enums_NestedEnum.
var (
Enums_NestedEnum_name = map[int32]string{
0: "CERO",
1: "UNO",
2: "DOS",
10: "DIEZ",
}
Enums_NestedEnum_value = map[string]int32{
"CERO": 0,
"UNO": 1,
"DOS": 2,
"DIEZ": 10,
}
)
func (x Enums_NestedEnum) Enum() *Enums_NestedEnum {
p := new(Enums_NestedEnum)

View File

@ -28,21 +28,23 @@ const (
WireFormat_TEXT_FORMAT WireFormat = 4
)
var WireFormat_name = map[int32]string{
0: "UNSPECIFIED",
1: "PROTOBUF",
2: "JSON",
3: "JSPB",
4: "TEXT_FORMAT",
}
var WireFormat_value = map[string]int32{
"UNSPECIFIED": 0,
"PROTOBUF": 1,
"JSON": 2,
"JSPB": 3,
"TEXT_FORMAT": 4,
}
// Enum value maps for WireFormat.
var (
WireFormat_name = map[int32]string{
0: "UNSPECIFIED",
1: "PROTOBUF",
2: "JSON",
3: "JSPB",
4: "TEXT_FORMAT",
}
WireFormat_value = map[string]int32{
"UNSPECIFIED": 0,
"PROTOBUF": 1,
"JSON": 2,
"JSPB": 3,
"TEXT_FORMAT": 4,
}
)
func (x WireFormat) Enum() *WireFormat {
p := new(WireFormat)
@ -90,23 +92,25 @@ const (
TestCategory_TEXT_FORMAT_TEST TestCategory = 5
)
var TestCategory_name = map[int32]string{
0: "UNSPECIFIED_TEST",
1: "BINARY_TEST",
2: "JSON_TEST",
3: "JSON_IGNORE_UNKNOWN_PARSING_TEST",
4: "JSPB_TEST",
5: "TEXT_FORMAT_TEST",
}
var TestCategory_value = map[string]int32{
"UNSPECIFIED_TEST": 0,
"BINARY_TEST": 1,
"JSON_TEST": 2,
"JSON_IGNORE_UNKNOWN_PARSING_TEST": 3,
"JSPB_TEST": 4,
"TEXT_FORMAT_TEST": 5,
}
// Enum value maps for TestCategory.
var (
TestCategory_name = map[int32]string{
0: "UNSPECIFIED_TEST",
1: "BINARY_TEST",
2: "JSON_TEST",
3: "JSON_IGNORE_UNKNOWN_PARSING_TEST",
4: "JSPB_TEST",
5: "TEXT_FORMAT_TEST",
}
TestCategory_value = map[string]int32{
"UNSPECIFIED_TEST": 0,
"BINARY_TEST": 1,
"JSON_TEST": 2,
"JSON_IGNORE_UNKNOWN_PARSING_TEST": 3,
"JSPB_TEST": 4,
"TEXT_FORMAT_TEST": 5,
}
)
func (x TestCategory) Enum() *TestCategory {
p := new(TestCategory)

View File

@ -27,17 +27,19 @@ const (
ForeignEnumProto2_FOREIGN_BAZ ForeignEnumProto2 = 2
)
var ForeignEnumProto2_name = map[int32]string{
0: "FOREIGN_FOO",
1: "FOREIGN_BAR",
2: "FOREIGN_BAZ",
}
var ForeignEnumProto2_value = map[string]int32{
"FOREIGN_FOO": 0,
"FOREIGN_BAR": 1,
"FOREIGN_BAZ": 2,
}
// Enum value maps for ForeignEnumProto2.
var (
ForeignEnumProto2_name = map[int32]string{
0: "FOREIGN_FOO",
1: "FOREIGN_BAR",
2: "FOREIGN_BAZ",
}
ForeignEnumProto2_value = map[string]int32{
"FOREIGN_FOO": 0,
"FOREIGN_BAR": 1,
"FOREIGN_BAZ": 2,
}
)
func (x ForeignEnumProto2) Enum() *ForeignEnumProto2 {
p := new(ForeignEnumProto2)
@ -85,19 +87,21 @@ const (
TestAllTypesProto2_NEG TestAllTypesProto2_NestedEnum = -1
)
var TestAllTypesProto2_NestedEnum_name = map[int32]string{
0: "FOO",
1: "BAR",
2: "BAZ",
-1: "NEG",
}
var TestAllTypesProto2_NestedEnum_value = map[string]int32{
"FOO": 0,
"BAR": 1,
"BAZ": 2,
"NEG": -1,
}
// Enum value maps for TestAllTypesProto2_NestedEnum.
var (
TestAllTypesProto2_NestedEnum_name = map[int32]string{
0: "FOO",
1: "BAR",
2: "BAZ",
-1: "NEG",
}
TestAllTypesProto2_NestedEnum_value = map[string]int32{
"FOO": 0,
"BAR": 1,
"BAZ": 2,
"NEG": -1,
}
)
func (x TestAllTypesProto2_NestedEnum) Enum() *TestAllTypesProto2_NestedEnum {
p := new(TestAllTypesProto2_NestedEnum)

View File

@ -32,17 +32,19 @@ const (
ForeignEnum_FOREIGN_BAZ ForeignEnum = 2
)
var ForeignEnum_name = map[int32]string{
0: "FOREIGN_FOO",
1: "FOREIGN_BAR",
2: "FOREIGN_BAZ",
}
var ForeignEnum_value = map[string]int32{
"FOREIGN_FOO": 0,
"FOREIGN_BAR": 1,
"FOREIGN_BAZ": 2,
}
// Enum value maps for ForeignEnum.
var (
ForeignEnum_name = map[int32]string{
0: "FOREIGN_FOO",
1: "FOREIGN_BAR",
2: "FOREIGN_BAZ",
}
ForeignEnum_value = map[string]int32{
"FOREIGN_FOO": 0,
"FOREIGN_BAR": 1,
"FOREIGN_BAZ": 2,
}
)
func (x ForeignEnum) Enum() *ForeignEnum {
p := new(ForeignEnum)
@ -80,19 +82,21 @@ const (
TestAllTypesProto3_NEG TestAllTypesProto3_NestedEnum = -1
)
var TestAllTypesProto3_NestedEnum_name = map[int32]string{
0: "FOO",
1: "BAR",
2: "BAZ",
-1: "NEG",
}
var TestAllTypesProto3_NestedEnum_value = map[string]int32{
"FOO": 0,
"BAR": 1,
"BAZ": 2,
"NEG": -1,
}
// Enum value maps for TestAllTypesProto3_NestedEnum.
var (
TestAllTypesProto3_NestedEnum_name = map[int32]string{
0: "FOO",
1: "BAR",
2: "BAZ",
-1: "NEG",
}
TestAllTypesProto3_NestedEnum_value = map[string]int32{
"FOO": 0,
"BAR": 1,
"BAZ": 2,
"NEG": -1,
}
)
func (x TestAllTypesProto3_NestedEnum) Enum() *TestAllTypesProto3_NestedEnum {
p := new(TestAllTypesProto3_NestedEnum)
@ -132,23 +136,25 @@ const (
TestAllTypesProto3_bAz TestAllTypesProto3_AliasedEnum = 2
)
var TestAllTypesProto3_AliasedEnum_name = map[int32]string{
0: "ALIAS_FOO",
1: "ALIAS_BAR",
2: "ALIAS_BAZ",
// Duplicate value: 2: "QUX",
// Duplicate value: 2: "qux",
// Duplicate value: 2: "bAz",
}
var TestAllTypesProto3_AliasedEnum_value = map[string]int32{
"ALIAS_FOO": 0,
"ALIAS_BAR": 1,
"ALIAS_BAZ": 2,
"QUX": 2,
"qux": 2,
"bAz": 2,
}
// Enum value maps for TestAllTypesProto3_AliasedEnum.
var (
TestAllTypesProto3_AliasedEnum_name = map[int32]string{
0: "ALIAS_FOO",
1: "ALIAS_BAR",
2: "ALIAS_BAZ",
// Duplicate value: 2: "QUX",
// Duplicate value: 2: "qux",
// Duplicate value: 2: "bAz",
}
TestAllTypesProto3_AliasedEnum_value = map[string]int32{
"ALIAS_FOO": 0,
"ALIAS_BAR": 1,
"ALIAS_BAZ": 2,
"QUX": 2,
"qux": 2,
"bAz": 2,
}
)
func (x TestAllTypesProto3_AliasedEnum) Enum() *TestAllTypesProto3_AliasedEnum {
p := new(TestAllTypesProto3_AliasedEnum)

View File

@ -27,17 +27,19 @@ const (
ForeignEnum_FOREIGN_BAZ ForeignEnum = 6
)
var ForeignEnum_name = map[int32]string{
4: "FOREIGN_FOO",
5: "FOREIGN_BAR",
6: "FOREIGN_BAZ",
}
var ForeignEnum_value = map[string]int32{
"FOREIGN_FOO": 4,
"FOREIGN_BAR": 5,
"FOREIGN_BAZ": 6,
}
// Enum value maps for ForeignEnum.
var (
ForeignEnum_name = map[int32]string{
4: "FOREIGN_FOO",
5: "FOREIGN_BAR",
6: "FOREIGN_BAZ",
}
ForeignEnum_value = map[string]int32{
"FOREIGN_FOO": 4,
"FOREIGN_BAR": 5,
"FOREIGN_BAZ": 6,
}
)
func (x ForeignEnum) Enum() *ForeignEnum {
p := new(ForeignEnum)
@ -82,13 +84,15 @@ const (
TestReservedEnumFields_RESERVED_ENUM TestReservedEnumFields = 0
)
var TestReservedEnumFields_name = map[int32]string{
0: "RESERVED_ENUM",
}
var TestReservedEnumFields_value = map[string]int32{
"RESERVED_ENUM": 0,
}
// Enum value maps for TestReservedEnumFields.
var (
TestReservedEnumFields_name = map[int32]string{
0: "RESERVED_ENUM",
}
TestReservedEnumFields_value = map[string]int32{
"RESERVED_ENUM": 0,
}
)
func (x TestReservedEnumFields) Enum() *TestReservedEnumFields {
p := new(TestReservedEnumFields)
@ -136,19 +140,21 @@ const (
TestAllTypes_NEG TestAllTypes_NestedEnum = -1
)
var TestAllTypes_NestedEnum_name = map[int32]string{
0: "FOO",
1: "BAR",
2: "BAZ",
-1: "NEG",
}
var TestAllTypes_NestedEnum_value = map[string]int32{
"FOO": 0,
"BAR": 1,
"BAZ": 2,
"NEG": -1,
}
// Enum value maps for TestAllTypes_NestedEnum.
var (
TestAllTypes_NestedEnum_name = map[int32]string{
0: "FOO",
1: "BAR",
2: "BAZ",
-1: "NEG",
}
TestAllTypes_NestedEnum_value = map[string]int32{
"FOO": 0,
"BAR": 1,
"BAZ": 2,
"NEG": -1,
}
)
func (x TestAllTypes_NestedEnum) Enum() *TestAllTypes_NestedEnum {
p := new(TestAllTypes_NestedEnum)
@ -192,13 +198,15 @@ const (
TestDeprecatedMessage_DEPRECATED TestDeprecatedMessage_DeprecatedEnum = 0 // Deprecated: Do not use.
)
var TestDeprecatedMessage_DeprecatedEnum_name = map[int32]string{
0: "DEPRECATED",
}
var TestDeprecatedMessage_DeprecatedEnum_value = map[string]int32{
"DEPRECATED": 0,
}
// Enum value maps for TestDeprecatedMessage_DeprecatedEnum.
var (
TestDeprecatedMessage_DeprecatedEnum_name = map[int32]string{
0: "DEPRECATED",
}
TestDeprecatedMessage_DeprecatedEnum_value = map[string]int32{
"DEPRECATED": 0,
}
)
func (x TestDeprecatedMessage_DeprecatedEnum) Enum() *TestDeprecatedMessage_DeprecatedEnum {
p := new(TestDeprecatedMessage_DeprecatedEnum)

View File

@ -24,13 +24,15 @@ const (
ImportEnum_IMPORT_ZERO ImportEnum = 0
)
var ImportEnum_name = map[int32]string{
0: "IMPORT_ZERO",
}
var ImportEnum_value = map[string]int32{
"IMPORT_ZERO": 0,
}
// Enum value maps for ImportEnum.
var (
ImportEnum_name = map[int32]string{
0: "IMPORT_ZERO",
}
ImportEnum_value = map[string]int32{
"IMPORT_ZERO": 0,
}
)
func (x ImportEnum) Enum() *ImportEnum {
p := new(ImportEnum)

View File

@ -27,19 +27,21 @@ const (
ForeignEnum_FOREIGN_BAZ ForeignEnum = 6
)
var ForeignEnum_name = map[int32]string{
0: "FOREIGN_ZERO",
4: "FOREIGN_FOO",
5: "FOREIGN_BAR",
6: "FOREIGN_BAZ",
}
var ForeignEnum_value = map[string]int32{
"FOREIGN_ZERO": 0,
"FOREIGN_FOO": 4,
"FOREIGN_BAR": 5,
"FOREIGN_BAZ": 6,
}
// Enum value maps for ForeignEnum.
var (
ForeignEnum_name = map[int32]string{
0: "FOREIGN_ZERO",
4: "FOREIGN_FOO",
5: "FOREIGN_BAR",
6: "FOREIGN_BAZ",
}
ForeignEnum_value = map[string]int32{
"FOREIGN_ZERO": 0,
"FOREIGN_FOO": 4,
"FOREIGN_BAR": 5,
"FOREIGN_BAZ": 6,
}
)
func (x ForeignEnum) Enum() *ForeignEnum {
p := new(ForeignEnum)
@ -77,19 +79,21 @@ const (
TestAllTypes_NEG TestAllTypes_NestedEnum = -1
)
var TestAllTypes_NestedEnum_name = map[int32]string{
0: "FOO",
1: "BAR",
2: "BAZ",
-1: "NEG",
}
var TestAllTypes_NestedEnum_value = map[string]int32{
"FOO": 0,
"BAR": 1,
"BAZ": 2,
"NEG": -1,
}
// Enum value maps for TestAllTypes_NestedEnum.
var (
TestAllTypes_NestedEnum_name = map[int32]string{
0: "FOO",
1: "BAR",
2: "BAZ",
-1: "NEG",
}
TestAllTypes_NestedEnum_value = map[string]int32{
"FOO": 0,
"BAR": 1,
"BAZ": 2,
"NEG": -1,
}
)
func (x TestAllTypes_NestedEnum) Enum() *TestAllTypes_NestedEnum {
p := new(TestAllTypes_NestedEnum)

View File

@ -24,13 +24,15 @@ const (
ImportEnum_IMPORT_ZERO ImportEnum = 0
)
var ImportEnum_name = map[int32]string{
0: "IMPORT_ZERO",
}
var ImportEnum_value = map[string]int32{
"IMPORT_ZERO": 0,
}
// Enum value maps for ImportEnum.
var (
ImportEnum_name = map[int32]string{
0: "IMPORT_ZERO",
}
ImportEnum_value = map[string]int32{
"IMPORT_ZERO": 0,
}
)
func (x ImportEnum) Enum() *ImportEnum {
p := new(ImportEnum)

View File

@ -25,13 +25,15 @@ const (
Enum1_ONE Enum1 = 1
)
var Enum1_name = map[int32]string{
1: "ONE",
}
var Enum1_value = map[string]int32{
"ONE": 1,
}
// Enum value maps for Enum1.
var (
Enum1_name = map[int32]string{
1: "ONE",
}
Enum1_value = map[string]int32{
"ONE": 1,
}
)
func (x Enum1) Enum() *Enum1 {
p := new(Enum1)
@ -76,13 +78,15 @@ const (
Enum2_UNO Enum2 = 1
)
var Enum2_name = map[int32]string{
1: "UNO",
}
var Enum2_value = map[string]int32{
"UNO": 1,
}
// Enum value maps for Enum2.
var (
Enum2_name = map[int32]string{
1: "UNO",
}
Enum2_value = map[string]int32{
"UNO": 1,
}
)
func (x Enum2) Enum() *Enum2 {
p := new(Enum2)
@ -127,13 +131,15 @@ const (
Enum3_YI Enum3 = 1
)
var Enum3_name = map[int32]string{
1: "YI",
}
var Enum3_value = map[string]int32{
"YI": 1,
}
// Enum value maps for Enum3.
var (
Enum3_name = map[int32]string{
1: "YI",
}
Enum3_value = map[string]int32{
"YI": 1,
}
)
func (x Enum3) Enum() *Enum3 {
p := new(Enum3)

View File

@ -53,47 +53,49 @@ const (
FieldDescriptorProto_TYPE_SINT64 FieldDescriptorProto_Type = 18
)
var FieldDescriptorProto_Type_name = map[int32]string{
1: "TYPE_DOUBLE",
2: "TYPE_FLOAT",
3: "TYPE_INT64",
4: "TYPE_UINT64",
5: "TYPE_INT32",
6: "TYPE_FIXED64",
7: "TYPE_FIXED32",
8: "TYPE_BOOL",
9: "TYPE_STRING",
10: "TYPE_GROUP",
11: "TYPE_MESSAGE",
12: "TYPE_BYTES",
13: "TYPE_UINT32",
14: "TYPE_ENUM",
15: "TYPE_SFIXED32",
16: "TYPE_SFIXED64",
17: "TYPE_SINT32",
18: "TYPE_SINT64",
}
var FieldDescriptorProto_Type_value = map[string]int32{
"TYPE_DOUBLE": 1,
"TYPE_FLOAT": 2,
"TYPE_INT64": 3,
"TYPE_UINT64": 4,
"TYPE_INT32": 5,
"TYPE_FIXED64": 6,
"TYPE_FIXED32": 7,
"TYPE_BOOL": 8,
"TYPE_STRING": 9,
"TYPE_GROUP": 10,
"TYPE_MESSAGE": 11,
"TYPE_BYTES": 12,
"TYPE_UINT32": 13,
"TYPE_ENUM": 14,
"TYPE_SFIXED32": 15,
"TYPE_SFIXED64": 16,
"TYPE_SINT32": 17,
"TYPE_SINT64": 18,
}
// Enum value maps for FieldDescriptorProto_Type.
var (
FieldDescriptorProto_Type_name = map[int32]string{
1: "TYPE_DOUBLE",
2: "TYPE_FLOAT",
3: "TYPE_INT64",
4: "TYPE_UINT64",
5: "TYPE_INT32",
6: "TYPE_FIXED64",
7: "TYPE_FIXED32",
8: "TYPE_BOOL",
9: "TYPE_STRING",
10: "TYPE_GROUP",
11: "TYPE_MESSAGE",
12: "TYPE_BYTES",
13: "TYPE_UINT32",
14: "TYPE_ENUM",
15: "TYPE_SFIXED32",
16: "TYPE_SFIXED64",
17: "TYPE_SINT32",
18: "TYPE_SINT64",
}
FieldDescriptorProto_Type_value = map[string]int32{
"TYPE_DOUBLE": 1,
"TYPE_FLOAT": 2,
"TYPE_INT64": 3,
"TYPE_UINT64": 4,
"TYPE_INT32": 5,
"TYPE_FIXED64": 6,
"TYPE_FIXED32": 7,
"TYPE_BOOL": 8,
"TYPE_STRING": 9,
"TYPE_GROUP": 10,
"TYPE_MESSAGE": 11,
"TYPE_BYTES": 12,
"TYPE_UINT32": 13,
"TYPE_ENUM": 14,
"TYPE_SFIXED32": 15,
"TYPE_SFIXED64": 16,
"TYPE_SINT32": 17,
"TYPE_SINT64": 18,
}
)
func (x FieldDescriptorProto_Type) Enum() *FieldDescriptorProto_Type {
p := new(FieldDescriptorProto_Type)
@ -141,17 +143,19 @@ const (
FieldDescriptorProto_LABEL_REPEATED FieldDescriptorProto_Label = 3
)
var FieldDescriptorProto_Label_name = map[int32]string{
1: "LABEL_OPTIONAL",
2: "LABEL_REQUIRED",
3: "LABEL_REPEATED",
}
var FieldDescriptorProto_Label_value = map[string]int32{
"LABEL_OPTIONAL": 1,
"LABEL_REQUIRED": 2,
"LABEL_REPEATED": 3,
}
// Enum value maps for FieldDescriptorProto_Label.
var (
FieldDescriptorProto_Label_name = map[int32]string{
1: "LABEL_OPTIONAL",
2: "LABEL_REQUIRED",
3: "LABEL_REPEATED",
}
FieldDescriptorProto_Label_value = map[string]int32{
"LABEL_OPTIONAL": 1,
"LABEL_REQUIRED": 2,
"LABEL_REPEATED": 3,
}
)
func (x FieldDescriptorProto_Label) Enum() *FieldDescriptorProto_Label {
p := new(FieldDescriptorProto_Label)
@ -200,17 +204,19 @@ const (
FileOptions_LITE_RUNTIME FileOptions_OptimizeMode = 3
)
var FileOptions_OptimizeMode_name = map[int32]string{
1: "SPEED",
2: "CODE_SIZE",
3: "LITE_RUNTIME",
}
var FileOptions_OptimizeMode_value = map[string]int32{
"SPEED": 1,
"CODE_SIZE": 2,
"LITE_RUNTIME": 3,
}
// Enum value maps for FileOptions_OptimizeMode.
var (
FileOptions_OptimizeMode_name = map[int32]string{
1: "SPEED",
2: "CODE_SIZE",
3: "LITE_RUNTIME",
}
FileOptions_OptimizeMode_value = map[string]int32{
"SPEED": 1,
"CODE_SIZE": 2,
"LITE_RUNTIME": 3,
}
)
func (x FileOptions_OptimizeMode) Enum() *FileOptions_OptimizeMode {
p := new(FileOptions_OptimizeMode)
@ -258,17 +264,19 @@ const (
FieldOptions_STRING_PIECE FieldOptions_CType = 2
)
var FieldOptions_CType_name = map[int32]string{
0: "STRING",
1: "CORD",
2: "STRING_PIECE",
}
var FieldOptions_CType_value = map[string]int32{
"STRING": 0,
"CORD": 1,
"STRING_PIECE": 2,
}
// Enum value maps for FieldOptions_CType.
var (
FieldOptions_CType_name = map[int32]string{
0: "STRING",
1: "CORD",
2: "STRING_PIECE",
}
FieldOptions_CType_value = map[string]int32{
"STRING": 0,
"CORD": 1,
"STRING_PIECE": 2,
}
)
func (x FieldOptions_CType) Enum() *FieldOptions_CType {
p := new(FieldOptions_CType)
@ -318,17 +326,19 @@ const (
FieldOptions_JS_NUMBER FieldOptions_JSType = 2
)
var FieldOptions_JSType_name = map[int32]string{
0: "JS_NORMAL",
1: "JS_STRING",
2: "JS_NUMBER",
}
var FieldOptions_JSType_value = map[string]int32{
"JS_NORMAL": 0,
"JS_STRING": 1,
"JS_NUMBER": 2,
}
// Enum value maps for FieldOptions_JSType.
var (
FieldOptions_JSType_name = map[int32]string{
0: "JS_NORMAL",
1: "JS_STRING",
2: "JS_NUMBER",
}
FieldOptions_JSType_value = map[string]int32{
"JS_NORMAL": 0,
"JS_STRING": 1,
"JS_NUMBER": 2,
}
)
func (x FieldOptions_JSType) Enum() *FieldOptions_JSType {
p := new(FieldOptions_JSType)
@ -378,17 +388,19 @@ const (
MethodOptions_IDEMPOTENT MethodOptions_IdempotencyLevel = 2
)
var MethodOptions_IdempotencyLevel_name = map[int32]string{
0: "IDEMPOTENCY_UNKNOWN",
1: "NO_SIDE_EFFECTS",
2: "IDEMPOTENT",
}
var MethodOptions_IdempotencyLevel_value = map[string]int32{
"IDEMPOTENCY_UNKNOWN": 0,
"NO_SIDE_EFFECTS": 1,
"IDEMPOTENT": 2,
}
// Enum value maps for MethodOptions_IdempotencyLevel.
var (
MethodOptions_IdempotencyLevel_name = map[int32]string{
0: "IDEMPOTENCY_UNKNOWN",
1: "NO_SIDE_EFFECTS",
2: "IDEMPOTENT",
}
MethodOptions_IdempotencyLevel_value = map[string]int32{
"IDEMPOTENCY_UNKNOWN": 0,
"NO_SIDE_EFFECTS": 1,
"IDEMPOTENT": 2,
}
)
func (x MethodOptions_IdempotencyLevel) Enum() *MethodOptions_IdempotencyLevel {
p := new(MethodOptions_IdempotencyLevel)

View File

@ -29,13 +29,15 @@ const (
NullValue_NULL_VALUE NullValue = 0
)
var NullValue_name = map[int32]string{
0: "NULL_VALUE",
}
var NullValue_value = map[string]int32{
"NULL_VALUE": 0,
}
// Enum value maps for NullValue.
var (
NullValue_name = map[int32]string{
0: "NULL_VALUE",
}
NullValue_value = map[string]int32{
"NULL_VALUE": 0,
}
)
func (x NullValue) Enum() *NullValue {
p := new(NullValue)

View File

@ -30,15 +30,17 @@ const (
Syntax_SYNTAX_PROTO3 Syntax = 1
)
var Syntax_name = map[int32]string{
0: "SYNTAX_PROTO2",
1: "SYNTAX_PROTO3",
}
var Syntax_value = map[string]int32{
"SYNTAX_PROTO2": 0,
"SYNTAX_PROTO3": 1,
}
// Enum value maps for Syntax.
var (
Syntax_name = map[int32]string{
0: "SYNTAX_PROTO2",
1: "SYNTAX_PROTO3",
}
Syntax_value = map[string]int32{
"SYNTAX_PROTO2": 0,
"SYNTAX_PROTO3": 1,
}
)
func (x Syntax) Enum() *Syntax {
p := new(Syntax)
@ -111,49 +113,51 @@ const (
Field_TYPE_SINT64 Field_Kind = 18
)
var Field_Kind_name = map[int32]string{
0: "TYPE_UNKNOWN",
1: "TYPE_DOUBLE",
2: "TYPE_FLOAT",
3: "TYPE_INT64",
4: "TYPE_UINT64",
5: "TYPE_INT32",
6: "TYPE_FIXED64",
7: "TYPE_FIXED32",
8: "TYPE_BOOL",
9: "TYPE_STRING",
10: "TYPE_GROUP",
11: "TYPE_MESSAGE",
12: "TYPE_BYTES",
13: "TYPE_UINT32",
14: "TYPE_ENUM",
15: "TYPE_SFIXED32",
16: "TYPE_SFIXED64",
17: "TYPE_SINT32",
18: "TYPE_SINT64",
}
var Field_Kind_value = map[string]int32{
"TYPE_UNKNOWN": 0,
"TYPE_DOUBLE": 1,
"TYPE_FLOAT": 2,
"TYPE_INT64": 3,
"TYPE_UINT64": 4,
"TYPE_INT32": 5,
"TYPE_FIXED64": 6,
"TYPE_FIXED32": 7,
"TYPE_BOOL": 8,
"TYPE_STRING": 9,
"TYPE_GROUP": 10,
"TYPE_MESSAGE": 11,
"TYPE_BYTES": 12,
"TYPE_UINT32": 13,
"TYPE_ENUM": 14,
"TYPE_SFIXED32": 15,
"TYPE_SFIXED64": 16,
"TYPE_SINT32": 17,
"TYPE_SINT64": 18,
}
// Enum value maps for Field_Kind.
var (
Field_Kind_name = map[int32]string{
0: "TYPE_UNKNOWN",
1: "TYPE_DOUBLE",
2: "TYPE_FLOAT",
3: "TYPE_INT64",
4: "TYPE_UINT64",
5: "TYPE_INT32",
6: "TYPE_FIXED64",
7: "TYPE_FIXED32",
8: "TYPE_BOOL",
9: "TYPE_STRING",
10: "TYPE_GROUP",
11: "TYPE_MESSAGE",
12: "TYPE_BYTES",
13: "TYPE_UINT32",
14: "TYPE_ENUM",
15: "TYPE_SFIXED32",
16: "TYPE_SFIXED64",
17: "TYPE_SINT32",
18: "TYPE_SINT64",
}
Field_Kind_value = map[string]int32{
"TYPE_UNKNOWN": 0,
"TYPE_DOUBLE": 1,
"TYPE_FLOAT": 2,
"TYPE_INT64": 3,
"TYPE_UINT64": 4,
"TYPE_INT32": 5,
"TYPE_FIXED64": 6,
"TYPE_FIXED32": 7,
"TYPE_BOOL": 8,
"TYPE_STRING": 9,
"TYPE_GROUP": 10,
"TYPE_MESSAGE": 11,
"TYPE_BYTES": 12,
"TYPE_UINT32": 13,
"TYPE_ENUM": 14,
"TYPE_SFIXED32": 15,
"TYPE_SFIXED64": 16,
"TYPE_SINT32": 17,
"TYPE_SINT64": 18,
}
)
func (x Field_Kind) Enum() *Field_Kind {
p := new(Field_Kind)
@ -196,19 +200,21 @@ const (
Field_CARDINALITY_REPEATED Field_Cardinality = 3
)
var Field_Cardinality_name = map[int32]string{
0: "CARDINALITY_UNKNOWN",
1: "CARDINALITY_OPTIONAL",
2: "CARDINALITY_REQUIRED",
3: "CARDINALITY_REPEATED",
}
var Field_Cardinality_value = map[string]int32{
"CARDINALITY_UNKNOWN": 0,
"CARDINALITY_OPTIONAL": 1,
"CARDINALITY_REQUIRED": 2,
"CARDINALITY_REPEATED": 3,
}
// Enum value maps for Field_Cardinality.
var (
Field_Cardinality_name = map[int32]string{
0: "CARDINALITY_UNKNOWN",
1: "CARDINALITY_OPTIONAL",
2: "CARDINALITY_REQUIRED",
3: "CARDINALITY_REPEATED",
}
Field_Cardinality_value = map[string]int32{
"CARDINALITY_UNKNOWN": 0,
"CARDINALITY_OPTIONAL": 1,
"CARDINALITY_REQUIRED": 2,
"CARDINALITY_REPEATED": 3,
}
)
func (x Field_Cardinality) Enum() *Field_Cardinality {
p := new(Field_Cardinality)