MessageType returns the message type for a named message. It returns nil if not found. Deprecated: Use protoregistry.GlobalTypes.FindMessageByName instead.
(s messageName)
| 204 | // |
| 205 | // Deprecated: Use protoregistry.GlobalTypes.FindMessageByName instead. |
| 206 | func MessageType(s messageName) reflect.Type { |
| 207 | if v, ok := messageTypeCache.Load(s); ok { |
| 208 | return v.(reflect.Type) |
| 209 | } |
| 210 | |
| 211 | // Derive the message type from the v2 registry. |
| 212 | var t reflect.Type |
| 213 | if mt, _ := protoregistry.GlobalTypes.FindMessageByName(protoreflect.FullName(s)); mt != nil { |
| 214 | t = messageGoType(mt) |
| 215 | } |
| 216 | |
| 217 | // If we could not get a concrete type, it is possible that it is a |
| 218 | // pseudo-message for a map entry. |
| 219 | if t == nil { |
| 220 | d, _ := protoregistry.GlobalFiles.FindDescriptorByName(protoreflect.FullName(s)) |
| 221 | if md, _ := d.(protoreflect.MessageDescriptor); md != nil && md.IsMapEntry() { |
| 222 | kt := goTypeForField(md.Fields().ByNumber(1)) |
| 223 | vt := goTypeForField(md.Fields().ByNumber(2)) |
| 224 | t = reflect.MapOf(kt, vt) |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | // Locally cache the message type for the given name. |
| 229 | if t != nil { |
| 230 | v, _ := messageTypeCache.LoadOrStore(s, t) |
| 231 | return v.(reflect.Type) |
| 232 | } |
| 233 | return nil |
| 234 | } |
| 235 | |
| 236 | func goTypeForField(fd protoreflect.FieldDescriptor) reflect.Type { |
| 237 | switch k := fd.Kind(); k { |