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/internal/impl/message.go b/internal/impl/message.go
index 09e91ed..2e8d185 100644
--- a/internal/impl/message.go
+++ b/internal/impl/message.go
@@ -224,8 +224,8 @@
// any discrepancies.
func (mi *MessageInfo) makeKnownFieldsFunc(si structInfo) {
mi.fields = map[pref.FieldNumber]*fieldInfo{}
- for i := 0; i < mi.PBType.Descriptor().Fields().Len(); i++ {
- fd := mi.PBType.Descriptor().Fields().Get(i)
+ for i := 0; i < mi.PBType.Fields().Len(); i++ {
+ fd := mi.PBType.Fields().Get(i)
fs := si.fieldsByNumber[fd.Number()]
var fi fieldInfo
switch {
@@ -244,8 +244,8 @@
}
mi.oneofs = map[pref.Name]*oneofInfo{}
- for i := 0; i < mi.PBType.Descriptor().Oneofs().Len(); i++ {
- od := mi.PBType.Descriptor().Oneofs().Get(i)
+ for i := 0; i < mi.PBType.Oneofs().Len(); i++ {
+ od := mi.PBType.Oneofs().Get(i)
mi.oneofs[od.Name()] = makeOneofInfo(od, si.oneofsByName[od.Name()], mi.Exporter, si.oneofWrappersByType)
}
}