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/conformance/conformance.pb.go b/internal/testprotos/conformance/conformance.pb.go
index 6a718fc..90a1076 100644
--- a/internal/testprotos/conformance/conformance.pb.go
+++ b/internal/testprotos/conformance/conformance.pb.go
@@ -42,9 +42,14 @@
}
func (x WireFormat) String() string {
- return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
+func (WireFormat) Descriptor() protoreflect.EnumDescriptor {
+ return file_conformance_conformance_proto_enumTypes[0].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (WireFormat) Type() protoreflect.EnumType {
return file_conformance_conformance_proto_enumTypes[0]
}
@@ -98,9 +103,14 @@
}
func (x TestCategory) String() string {
- return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
+func (TestCategory) Descriptor() protoreflect.EnumDescriptor {
+ return file_conformance_conformance_proto_enumTypes[1].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (TestCategory) Type() protoreflect.EnumType {
return file_conformance_conformance_proto_enumTypes[1]
}
diff --git a/internal/testprotos/conformance/test_messages_proto2.pb.go b/internal/testprotos/conformance/test_messages_proto2.pb.go
index 04e0621..cde3e92 100644
--- a/internal/testprotos/conformance/test_messages_proto2.pb.go
+++ b/internal/testprotos/conformance/test_messages_proto2.pb.go
@@ -42,9 +42,14 @@
}
func (x ForeignEnumProto2) String() string {
- return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
+func (ForeignEnumProto2) Descriptor() protoreflect.EnumDescriptor {
+ return file_google_protobuf_test_messages_proto2_proto_enumTypes[0].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (ForeignEnumProto2) Type() protoreflect.EnumType {
return file_google_protobuf_test_messages_proto2_proto_enumTypes[0]
}
@@ -55,7 +60,7 @@
// Deprecated: Do not use.
func (x *ForeignEnumProto2) UnmarshalJSON(b []byte) error {
- num, err := protoimpl.X.UnmarshalJSONEnum(x.Type(), b)
+ num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b)
if err != nil {
return err
}
@@ -100,9 +105,14 @@
}
func (x TestAllTypesProto2_NestedEnum) String() string {
- return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
+func (TestAllTypesProto2_NestedEnum) Descriptor() protoreflect.EnumDescriptor {
+ return file_google_protobuf_test_messages_proto2_proto_enumTypes[1].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (TestAllTypesProto2_NestedEnum) Type() protoreflect.EnumType {
return file_google_protobuf_test_messages_proto2_proto_enumTypes[1]
}
@@ -113,7 +123,7 @@
// Deprecated: Do not use.
func (x *TestAllTypesProto2_NestedEnum) UnmarshalJSON(b []byte) error {
- num, err := protoimpl.X.UnmarshalJSONEnum(x.Type(), b)
+ num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b)
if err != nil {
return err
}
diff --git a/internal/testprotos/conformance/test_messages_proto3.pb.go b/internal/testprotos/conformance/test_messages_proto3.pb.go
index 28233e5..c49c66d 100644
--- a/internal/testprotos/conformance/test_messages_proto3.pb.go
+++ b/internal/testprotos/conformance/test_messages_proto3.pb.go
@@ -37,9 +37,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_google_protobuf_test_messages_proto3_proto_enumTypes[0].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (ForeignEnum) Type() protoreflect.EnumType {
return file_google_protobuf_test_messages_proto3_proto_enumTypes[0]
}
@@ -79,9 +84,14 @@
}
func (x TestAllTypesProto3_NestedEnum) String() string {
- return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
+func (TestAllTypesProto3_NestedEnum) Descriptor() protoreflect.EnumDescriptor {
+ return file_google_protobuf_test_messages_proto3_proto_enumTypes[1].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (TestAllTypesProto3_NestedEnum) Type() protoreflect.EnumType {
return file_google_protobuf_test_messages_proto3_proto_enumTypes[1]
}
@@ -127,9 +137,14 @@
}
func (x TestAllTypesProto3_AliasedEnum) String() string {
- return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
+func (TestAllTypesProto3_AliasedEnum) Descriptor() protoreflect.EnumDescriptor {
+ return file_google_protobuf_test_messages_proto3_proto_enumTypes[2].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (TestAllTypesProto3_AliasedEnum) Type() protoreflect.EnumType {
return file_google_protobuf_test_messages_proto3_proto_enumTypes[2]
}
diff --git a/internal/testprotos/test/test.pb.go b/internal/testprotos/test/test.pb.go
index 8217a9a..7d512da 100644
--- a/internal/testprotos/test/test.pb.go
+++ b/internal/testprotos/test/test.pb.go
@@ -43,9 +43,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_test_test_proto_enumTypes[0].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (ForeignEnum) Type() protoreflect.EnumType {
return file_test_test_proto_enumTypes[0]
}
@@ -56,7 +61,7 @@
// Deprecated: Do not use.
func (x *ForeignEnum) UnmarshalJSON(b []byte) error {
- num, err := protoimpl.X.UnmarshalJSONEnum(x.Type(), b)
+ num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b)
if err != nil {
return err
}
@@ -92,9 +97,14 @@
}
func (x TestReservedEnumFields) String() string {
- return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
+func (TestReservedEnumFields) Descriptor() protoreflect.EnumDescriptor {
+ return file_test_test_proto_enumTypes[1].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (TestReservedEnumFields) Type() protoreflect.EnumType {
return file_test_test_proto_enumTypes[1]
}
@@ -105,7 +115,7 @@
// Deprecated: Do not use.
func (x *TestReservedEnumFields) UnmarshalJSON(b []byte) error {
- num, err := protoimpl.X.UnmarshalJSONEnum(x.Type(), b)
+ num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b)
if err != nil {
return err
}
@@ -150,9 +160,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_test_test_proto_enumTypes[2].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (TestAllTypes_NestedEnum) Type() protoreflect.EnumType {
return file_test_test_proto_enumTypes[2]
}
@@ -163,7 +178,7 @@
// Deprecated: Do not use.
func (x *TestAllTypes_NestedEnum) UnmarshalJSON(b []byte) error {
- num, err := protoimpl.X.UnmarshalJSONEnum(x.Type(), b)
+ num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b)
if err != nil {
return err
}
@@ -198,9 +213,14 @@
}
func (x TestDeprecatedMessage_DeprecatedEnum) String() string {
- return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
+func (TestDeprecatedMessage_DeprecatedEnum) Descriptor() protoreflect.EnumDescriptor {
+ return file_test_test_proto_enumTypes[3].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (TestDeprecatedMessage_DeprecatedEnum) Type() protoreflect.EnumType {
return file_test_test_proto_enumTypes[3]
}
@@ -211,7 +231,7 @@
// Deprecated: Do not use.
func (x *TestDeprecatedMessage_DeprecatedEnum) UnmarshalJSON(b []byte) error {
- num, err := protoimpl.X.UnmarshalJSONEnum(x.Type(), b)
+ num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b)
if err != nil {
return err
}
diff --git a/internal/testprotos/test/test_import.pb.go b/internal/testprotos/test/test_import.pb.go
index 3b9766f..1682ef5 100644
--- a/internal/testprotos/test/test_import.pb.go
+++ b/internal/testprotos/test/test_import.pb.go
@@ -36,9 +36,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_test_test_import_proto_enumTypes[0].Descriptor()
+}
+
+// Deprecated: Use Descriptor instead.
func (ImportEnum) Type() protoreflect.EnumType {
return file_test_test_import_proto_enumTypes[0]
}
@@ -49,7 +54,7 @@
// Deprecated: Do not use.
func (x *ImportEnum) UnmarshalJSON(b []byte) error {
- num, err := protoimpl.X.UnmarshalJSONEnum(x.Type(), b)
+ num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b)
if err != nil {
return err
}
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]
}