reflect/protoreflect: add Descriptor specific methods
Added methods:
Enum.Descriptor
Message.Descriptor
EnumType.Descriptor
MessageType.Descriptor
ExtensionType.Descriptor
Message.New
All functionality is switched over to use those methods instead of
implicitly relying on the fact that {Enum,Message}Type implicitly
implement the associated descriptor interface.
This CL does not yet remove {Enum,Message}.Type or prevent
{Enum,Message,Extension}Type from implementating a descriptor.
That is a subsequent CL.
The Message.New method is also added to replace functionality
that will be lost when the Type methods are removed.
Change-Id: I7fefde1673bbd40bfdac489aca05cec9a6c98eb1
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/174918
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/internal/testprotos/test3/test.pb.go b/internal/testprotos/test3/test.pb.go
index d871a2e..262f7c9 100644
--- a/internal/testprotos/test3/test.pb.go
+++ b/internal/testprotos/test3/test.pb.go
@@ -39,9 +39,14 @@
}
func (x ForeignEnum) String() string {
- return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
+func (ForeignEnum) Descriptor() protoreflect.EnumDescriptor {
+ return file_test3_test_proto_enumTypes[0].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (ForeignEnum) Type() protoreflect.EnumType {
return file_test3_test_proto_enumTypes[0]
}
@@ -81,9 +86,14 @@
}
func (x TestAllTypes_NestedEnum) String() string {
- return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
+func (TestAllTypes_NestedEnum) Descriptor() protoreflect.EnumDescriptor {
+ return file_test3_test_proto_enumTypes[1].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (TestAllTypes_NestedEnum) Type() protoreflect.EnumType {
return file_test3_test_proto_enumTypes[1]
}
diff --git a/internal/testprotos/test3/test_import.pb.go b/internal/testprotos/test3/test_import.pb.go
index 385827b..3ea92b6 100644
--- a/internal/testprotos/test3/test_import.pb.go
+++ b/internal/testprotos/test3/test_import.pb.go
@@ -30,9 +30,14 @@
}
func (x ImportEnum) String() string {
- return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
+func (ImportEnum) Descriptor() protoreflect.EnumDescriptor {
+ return file_test3_test_import_proto_enumTypes[0].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (ImportEnum) Type() protoreflect.EnumType {
return file_test3_test_import_proto_enumTypes[0]
}