MCPcopy Index your code
hub / github.com/google/gvisor / findType

Method findType

pkg/state/encode.go:555–592  ·  view source on GitHub ↗

findType recursively finds type information.

(typ reflect.Type)

Source from the content-addressed store, hash-verified

553
554// findType recursively finds type information.
555func (es *encodeState) findType(typ reflect.Type) wire.TypeSpec {
556 // First: check if this is a proper type. It's possible for pointers,
557 // slices, arrays, maps, etc to all have some different type.
558 te, ok := es.types.Lookup(typ)
559 if te != nil {
560 if !ok {
561 // See encodeStruct.
562 es.pendingTypes = append(es.pendingTypes, te.Type)
563 }
564 return wire.TypeID(te.ID)
565 }
566
567 switch typ.Kind() {
568 case reflect.Ptr:
569 return &wire.TypeSpecPointer{
570 Type: es.findType(typ.Elem()),
571 }
572 case reflect.Slice:
573 return &wire.TypeSpecSlice{
574 Type: es.findType(typ.Elem()),
575 }
576 case reflect.Array:
577 return &wire.TypeSpecArray{
578 Count: wire.Uint(typ.Len()),
579 Type: es.findType(typ.Elem()),
580 }
581 case reflect.Map:
582 return &wire.TypeSpecMap{
583 Key: es.findType(typ.Key()),
584 Value: es.findType(typ.Elem()),
585 }
586 default:
587 // After potentially chasing many pointers, the
588 // ultimate type of the object is not known.
589 Failf("type %q is not known", typ)
590 }
591 panic("unreachable")
592}
593
594// encodeInterface encodes an interface.
595func (es *encodeState) encodeInterface(obj reflect.Value, dest *wire.Object) {

Callers 2

resolveMethod · 0.95
encodeInterfaceMethod · 0.95

Calls 7

TypeIDTypeAlias · 0.92
UintTypeAlias · 0.92
FailfFunction · 0.85
ElemMethod · 0.80
LookupMethod · 0.65
KindMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected