internal/cmd/generate-protos: generate internal descfield package
Generate a list of descriptor fields from the descriptor.proto itself
as an internal package. Use these fields for the internal implementation.
Change-Id: Ib1ab0c5c6deb332ba6c8018ef55136b7e5974944
Reviewed-on: https://go-review.googlesource.com/c/164864
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/cmd/protoc-gen-go/annotation_test.go b/cmd/protoc-gen-go/annotation_test.go
index 7463215..8f6adb4 100644
--- a/cmd/protoc-gen-go/annotation_test.go
+++ b/cmd/protoc-gen-go/annotation_test.go
@@ -10,6 +10,7 @@
"testing"
"github.com/golang/protobuf/proto"
+ "github.com/golang/protobuf/v2/internal/descfield"
"github.com/golang/protobuf/v2/internal/scalar"
descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
@@ -35,19 +36,19 @@
path []int32
}{{
"type ", "AnnotationsTestEnum", " int32",
- []int32{5 /* enum_type */, 0},
+ []int32{descfield.FileDescriptorProto_EnumType, 0},
}, {
"\t", "AnnotationsTestEnum_ANNOTATIONS_TEST_ENUM_VALUE", " AnnotationsTestEnum = 0",
- []int32{5 /* enum_type */, 0, 2 /* value */, 0},
+ []int32{descfield.FileDescriptorProto_EnumType, 0, descfield.EnumDescriptorProto_Value, 0},
}, {
"type ", "AnnotationsTestMessage", " struct {",
- []int32{4 /* message_type */, 0},
+ []int32{descfield.FileDescriptorProto_MessageType, 0},
}, {
"\t", "AnnotationsTestField", " ",
- []int32{4 /* message_type */, 0, 2 /* field */, 0},
+ []int32{descfield.FileDescriptorProto_MessageType, 0, descfield.DescriptorProto_Field, 0},
}, {
"func (m *AnnotationsTestMessage) ", "GetAnnotationsTestField", "() string {",
- []int32{4 /* message_type */, 0, 2 /* field */, 0},
+ []int32{descfield.FileDescriptorProto_MessageType, 0, descfield.DescriptorProto_Field, 0},
}} {
s := want.prefix + want.text + want.suffix
pos := bytes.Index(sourceFile, []byte(s))
diff --git a/cmd/protoc-gen-go/internal_gengo/main.go b/cmd/protoc-gen-go/internal_gengo/main.go
index 4748f67..c124467 100644
--- a/cmd/protoc-gen-go/internal_gengo/main.go
+++ b/cmd/protoc-gen-go/internal_gengo/main.go
@@ -18,6 +18,7 @@
"unicode/utf8"
"github.com/golang/protobuf/proto"
+ "github.com/golang/protobuf/v2/internal/descfield"
"github.com/golang/protobuf/v2/internal/encoding/tag"
"github.com/golang/protobuf/v2/protogen"
"github.com/golang/protobuf/v2/reflect/protoreflect"
@@ -118,10 +119,9 @@
g.P("// source: ", f.Desc.Path())
}
g.P()
- const filePackageField = 2 // FileDescriptorProto.package
g.PrintLeadingComments(protogen.Location{
SourceFile: f.Proto.GetName(),
- Path: []int32{filePackageField},
+ Path: []int32{descfield.FileDescriptorProto_Package},
})
g.P()
g.P("package ", f.GoPackageName)