MCPcopy
hub / github.com/golang/protobuf / goTypeForField

Function goTypeForField

proto/registry.go:236–251  ·  view source on GitHub ↗
(fd protoreflect.FieldDescriptor)

Source from the content-addressed store, hash-verified

234}
235
236func goTypeForField(fd protoreflect.FieldDescriptor) reflect.Type {
237 switch k := fd.Kind(); k {
238 case protoreflect.EnumKind:
239 if et, _ := protoregistry.GlobalTypes.FindEnumByName(fd.Enum().FullName()); et != nil {
240 return enumGoType(et)
241 }
242 return reflect.TypeOf(protoreflect.EnumNumber(0))
243 case protoreflect.MessageKind, protoreflect.GroupKind:
244 if mt, _ := protoregistry.GlobalTypes.FindMessageByName(fd.Message().FullName()); mt != nil {
245 return messageGoType(mt)
246 }
247 return reflect.TypeOf((*protoreflect.Message)(nil)).Elem()
248 default:
249 return reflect.TypeOf(fd.Default().Interface())
250 }
251}
252
253func enumGoType(et protoreflect.EnumType) reflect.Type {
254 return reflect.TypeOf(et.New(0))

Callers 1

MessageTypeFunction · 0.85

Calls 5

enumGoTypeFunction · 0.85
messageGoTypeFunction · 0.85
FindMessageByNameMethod · 0.80
InterfaceMethod · 0.80
EnumMethod · 0.45

Tested by

no test coverage detected