cmd/protoc-gen-go: generate enums
This produces exactly the same output (to the best of my ability to
determine) as github.com/golang/protobuf.
Change-Id: Ib60e7a836efb1eb0e5167b30458049ec239e7903
Reviewed-on: https://go-review.googlesource.com/134695
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/cmd/protoc-gen-go/testdata/proto2/enum.pb.go b/cmd/protoc-gen-go/testdata/proto2/enum.pb.go
new file mode 100644
index 0000000..85b2fad
--- /dev/null
+++ b/cmd/protoc-gen-go/testdata/proto2/enum.pb.go
@@ -0,0 +1,278 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// source: proto2/enum.proto
+
+package proto2
+
+import proto "github.com/golang/protobuf/proto"
+
+// EnumType1 comment.
+type EnumType1 int32
+
+const (
+ // EnumType1_ONE comment.
+ EnumType1_ONE EnumType1 = 1
+ // EnumType1_TWO comment.
+ EnumType1_TWO EnumType1 = 2
+)
+
+var EnumType1_name = map[int32]string{
+ 1: "ONE",
+ 2: "TWO",
+}
+
+var EnumType1_value = map[string]int32{
+ "ONE": 1,
+ "TWO": 2,
+}
+
+func (x EnumType1) Enum() *EnumType1 {
+ p := new(EnumType1)
+ *p = x
+ return p
+}
+
+func (x EnumType1) String() string {
+ return proto.EnumName(EnumType1_name, int32(x))
+}
+
+func (x *EnumType1) UnmarshalJSON(data []byte) error {
+ value, err := proto.UnmarshalJSONEnum(EnumType1_value, data, "EnumType1")
+ if err != nil {
+ return err
+ }
+ *x = EnumType1(value)
+ return nil
+}
+
+func (EnumType1) EnumDescriptor() ([]byte, []int) {
+ return fileDescriptor_de9f68860d540858, []int{0}
+}
+
+type EnumType2 int32
+
+const (
+ EnumType2_duplicate1 EnumType2 = 1
+ 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,
+}
+
+func (x EnumType2) Enum() *EnumType2 {
+ p := new(EnumType2)
+ *p = x
+ return p
+}
+
+func (x EnumType2) String() string {
+ return proto.EnumName(EnumType2_name, int32(x))
+}
+
+func (x *EnumType2) UnmarshalJSON(data []byte) error {
+ value, err := proto.UnmarshalJSONEnum(EnumType2_value, data, "EnumType2")
+ if err != nil {
+ return err
+ }
+ *x = EnumType2(value)
+ return nil
+}
+
+func (EnumType2) EnumDescriptor() ([]byte, []int) {
+ return fileDescriptor_de9f68860d540858, []int{1}
+}
+
+// NestedEnumType1A comment.
+type EnumContainerMessage1_NestedEnumType1A int32
+
+const (
+ // NestedEnumType1A_VALUE comment.
+ 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,
+}
+
+func (x EnumContainerMessage1_NestedEnumType1A) Enum() *EnumContainerMessage1_NestedEnumType1A {
+ p := new(EnumContainerMessage1_NestedEnumType1A)
+ *p = x
+ return p
+}
+
+func (x EnumContainerMessage1_NestedEnumType1A) String() string {
+ return proto.EnumName(EnumContainerMessage1_NestedEnumType1A_name, int32(x))
+}
+
+func (x *EnumContainerMessage1_NestedEnumType1A) UnmarshalJSON(data []byte) error {
+ value, err := proto.UnmarshalJSONEnum(EnumContainerMessage1_NestedEnumType1A_value, data, "EnumContainerMessage1_NestedEnumType1A")
+ if err != nil {
+ return err
+ }
+ *x = EnumContainerMessage1_NestedEnumType1A(value)
+ return nil
+}
+
+func (EnumContainerMessage1_NestedEnumType1A) EnumDescriptor() ([]byte, []int) {
+ return fileDescriptor_de9f68860d540858, []int{0, 0}
+}
+
+type EnumContainerMessage1_NestedEnumType1B int32
+
+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,
+}
+
+func (x EnumContainerMessage1_NestedEnumType1B) Enum() *EnumContainerMessage1_NestedEnumType1B {
+ p := new(EnumContainerMessage1_NestedEnumType1B)
+ *p = x
+ return p
+}
+
+func (x EnumContainerMessage1_NestedEnumType1B) String() string {
+ return proto.EnumName(EnumContainerMessage1_NestedEnumType1B_name, int32(x))
+}
+
+func (x *EnumContainerMessage1_NestedEnumType1B) UnmarshalJSON(data []byte) error {
+ value, err := proto.UnmarshalJSONEnum(EnumContainerMessage1_NestedEnumType1B_value, data, "EnumContainerMessage1_NestedEnumType1B")
+ if err != nil {
+ return err
+ }
+ *x = EnumContainerMessage1_NestedEnumType1B(value)
+ return nil
+}
+
+func (EnumContainerMessage1_NestedEnumType1B) EnumDescriptor() ([]byte, []int) {
+ return fileDescriptor_de9f68860d540858, []int{0, 1}
+}
+
+type EnumContainerMessage1 struct {
+}
+
+// NestedEnumType2A comment.
+type EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A int32
+
+const (
+ // NestedEnumType2A_VALUE comment.
+ 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,
+}
+
+func (x EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A) Enum() *EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A {
+ p := new(EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A)
+ *p = x
+ return p
+}
+
+func (x EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A) String() string {
+ return proto.EnumName(EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A_name, int32(x))
+}
+
+func (x *EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A) UnmarshalJSON(data []byte) error {
+ value, err := proto.UnmarshalJSONEnum(EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A_value, data, "EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A")
+ if err != nil {
+ return err
+ }
+ *x = EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A(value)
+ return nil
+}
+
+func (EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A) EnumDescriptor() ([]byte, []int) {
+ return fileDescriptor_de9f68860d540858, []int{0, 0, 0}
+}
+
+type EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B int32
+
+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,
+}
+
+func (x EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B) Enum() *EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B {
+ p := new(EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B)
+ *p = x
+ return p
+}
+
+func (x EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B) String() string {
+ return proto.EnumName(EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B_name, int32(x))
+}
+
+func (x *EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B) UnmarshalJSON(data []byte) error {
+ value, err := proto.UnmarshalJSONEnum(EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B_value, data, "EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B")
+ if err != nil {
+ return err
+ }
+ *x = EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B(value)
+ return nil
+}
+
+func (EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B) EnumDescriptor() ([]byte, []int) {
+ return fileDescriptor_de9f68860d540858, []int{0, 0, 1}
+}
+
+type EnumContainerMessage1_EnumContainerMessage2 struct {
+}
+
+func init() {
+ proto.RegisterEnum("goproto.protoc.proto2.EnumType1", EnumType1_name, EnumType1_value)
+ proto.RegisterEnum("goproto.protoc.proto2.EnumType2", EnumType2_name, EnumType2_value)
+ proto.RegisterEnum("goproto.protoc.proto2.EnumContainerMessage1_NestedEnumType1A", EnumContainerMessage1_NestedEnumType1A_name, EnumContainerMessage1_NestedEnumType1A_value)
+ proto.RegisterEnum("goproto.protoc.proto2.EnumContainerMessage1_NestedEnumType1B", EnumContainerMessage1_NestedEnumType1B_name, EnumContainerMessage1_NestedEnumType1B_value)
+ proto.RegisterEnum("goproto.protoc.proto2.EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A", EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A_name, EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2A_value)
+ proto.RegisterEnum("goproto.protoc.proto2.EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B", EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B_name, EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B_value)
+}
+
+func init() { proto.RegisterFile("proto2/enum.proto", fileDescriptor_de9f68860d540858) }
+
+var fileDescriptor_de9f68860d540858 = []byte{
+ // 242 bytes of a gzipped FileDescriptorProto
+ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x90, 0xb1, 0x4b, 0xc4, 0x30,
+ 0x14, 0xc6, 0xcd, 0x39, 0x88, 0x19, 0x34, 0x56, 0x6e, 0x39, 0x70, 0xb9, 0x45, 0x38, 0xb8, 0x86,
+ 0x64, 0x13, 0xa7, 0x56, 0xb3, 0x69, 0x6f, 0xb0, 0x2a, 0xb8, 0x1c, 0xa1, 0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