internal/impl: move filetype.EnumInfo to impl
Change-Id: I5558d9d4618df80dd08969fb8af1bc16191176b5
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/195620
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/filetype/build.go b/internal/filetype/build.go
index 738a1ca..f421a62 100644
--- a/internal/filetype/build.go
+++ b/internal/filetype/build.go
@@ -90,15 +90,15 @@
// is appended to the end in reverse order.
DependencyIndexes []int32
+ // EnumInfos is a list of enum infos in "flattened ordering".
+ EnumInfos []pimpl.EnumInfo
+
// MessageInfos is a list of message infos in "flattened ordering".
// If provided, the GoType and PBType for each element is populated.
//
// Requirement: len(MessageInfos) == len(Build.Messages)
MessageInfos []pimpl.MessageInfo
- // EnumInfos is a list of enum infos in "flattened ordering".
- EnumInfos []EnumInfo
-
// ExtensionInfos is a list of extension infos in "flattened ordering".
// Each element is initialized and registered with the protoregistry package.
//
@@ -144,9 +144,9 @@
}
if len(fbOut.Enums) > 0 {
for i := range fbOut.Enums {
- tb.EnumInfos[i] = EnumInfo{
- desc: &fbOut.Enums[i],
- goType: reflect.TypeOf(enumGoTypes[i]),
+ tb.EnumInfos[i] = pimpl.EnumInfo{
+ GoReflectType: reflect.TypeOf(enumGoTypes[i]),
+ Desc: &fbOut.Enums[i],
}
// Register enum types.
if err := tb.TypeRegistry.Register(&tb.EnumInfos[i]); err != nil {
@@ -293,20 +293,3 @@
return pimpl.Export{}.MessageDescriptorOf(r.goTypes[depIdx])
}
}
-
-type EnumInfo struct {
- desc pref.EnumDescriptor
- goType reflect.Type
-}
-
-func (t *EnumInfo) New(n pref.EnumNumber) pref.Enum {
- return reflect.ValueOf(n).Convert(t.goType).Interface().(pref.Enum)
-}
-func (t *EnumInfo) GoType() reflect.Type { return t.goType }
-func (t *EnumInfo) Descriptor() pref.EnumDescriptor { return t.desc }
-
-func messageMaker(t reflect.Type) func() pref.Message {
- return func() pref.Message {
- return reflect.New(t.Elem()).Interface().(pref.ProtoMessage).ProtoReflect()
- }
-}
diff --git a/internal/impl/enum.go b/internal/impl/enum.go
new file mode 100644
index 0000000..eceff8a
--- /dev/null
+++ b/internal/impl/enum.go
@@ -0,0 +1,22 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package impl
+
+import (
+ "reflect"
+
+ pref "google.golang.org/protobuf/reflect/protoreflect"
+)
+
+type EnumInfo struct {
+ GoReflectType reflect.Type // int32 kind
+ Desc pref.EnumDescriptor
+}
+
+func (t *EnumInfo) New(n pref.EnumNumber) pref.Enum {
+ return reflect.ValueOf(n).Convert(t.GoReflectType).Interface().(pref.Enum)
+}
+func (t *EnumInfo) GoType() reflect.Type { return t.GoReflectType }
+func (t *EnumInfo) Descriptor() pref.EnumDescriptor { return t.Desc }
diff --git a/internal/filetype/enum_test.go b/internal/impl/enum_test.go
similarity index 97%
rename from internal/filetype/enum_test.go
rename to internal/impl/enum_test.go
index 59badb2..d122a6c 100644
--- a/internal/filetype/enum_test.go
+++ b/internal/impl/enum_test.go
@@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package filetype_test
+package impl_test
import (
"reflect"
"testing"
- testpb "google.golang.org/protobuf/internal/testprotos/test"
pref "google.golang.org/protobuf/reflect/protoreflect"
+
+ testpb "google.golang.org/protobuf/internal/testprotos/test"
)
func TestEnum(t *testing.T) {
diff --git a/runtime/protoimpl/impl.go b/runtime/protoimpl/impl.go
index aff6570..4a1ab7f 100644
--- a/runtime/protoimpl/impl.go
+++ b/runtime/protoimpl/impl.go
@@ -26,7 +26,7 @@
TypeBuilder = filetype.Builder
// Types used by generated code to implement EnumType, MessageType, and ExtensionType.
- EnumInfo = filetype.EnumInfo
+ EnumInfo = impl.EnumInfo
MessageInfo = impl.MessageInfo
ExtensionInfo = impl.ExtensionInfo