reflect/protoreflect: add Enum.Type and Message.Type
CL/174938 removed these methods in favor of a method that returned
only the descriptors. This CL adds back in the Type methods alongside
the Descriptor methods.
In a vast majority of protobuf usages, only the descriptor information
is needed. However, there is a small percentage that legitimately needs
the Go type information. We should provide both, but document that the
descriptor-only information is preferred.
Change-Id: Ia0a098997fb1bd009994940ae8ea5257ccd87cae
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/184578
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/encoding/testprotos/pb3/test.pb.go b/encoding/testprotos/pb3/test.pb.go
index aaa20e0..56e5e4a 100644
--- a/encoding/testprotos/pb3/test.pb.go
+++ b/encoding/testprotos/pb3/test.pb.go
@@ -54,6 +54,10 @@
return file_pb3_test_proto_enumTypes[0].EnumDescriptor
}
+func (Enum) Type() protoreflect.EnumType {
+ return &file_pb3_test_proto_enumTypes[0]
+}
+
func (x Enum) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
@@ -100,6 +104,10 @@
return file_pb3_test_proto_enumTypes[1].EnumDescriptor
}
+func (Enums_NestedEnum) Type() protoreflect.EnumType {
+ return &file_pb3_test_proto_enumTypes[1]
+}
+
func (x Enums_NestedEnum) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}