github.com/wfusion/gofusion@v1.1.14/common/utils/inspect/rtype.go (about) 1 package inspect 2 3 import ( 4 "reflect" 5 "unsafe" 6 ) 7 8 type tflag uint8 9 type nameOff int32 // offset to a name 10 type typeOff int32 // offset to an *rtype 11 type textOff int32 // offset from top of text section 12 13 // iface runtime.iface 14 type iface struct { 15 tab *itab 16 data unsafe.Pointer 17 } 18 19 // eface runtime.eface 20 type eface struct { 21 _type *rtype 22 data unsafe.Pointer 23 } 24 25 func (e eface) pack() (r interface{}) { *(*eface)(unsafe.Pointer(&r)) = e; return } 26 27 // rtype reflect.rtype, declare in internal/api.Type after go1.21 28 type rtype struct { 29 size uintptr 30 ptrdata uintptr // number of bytes in the type that can contain pointers 31 hash uint32 // hash of type; avoids computation in hash tables 32 tflag tflag // extra type information flags, reflect.tflag 33 align uint8 // alignment of variable with this type 34 fieldAlign uint8 // alignment of struct field with this type 35 kind uint8 // enumeration for C 36 // function for comparing objects of this type 37 // (ptr to object A, ptr to object B) -> ==? 38 equal func(unsafe.Pointer, unsafe.Pointer) bool 39 // gcdata stores the GC type data for the garbage collector. 40 // If the KindGCProg bit is set in kind, gcdata is a GC program. 41 // Otherwise it is a ptrmask bitmap. See mbitmap.go for details. 42 gcdata *byte // garbage collection data 43 str nameOff // string form 44 ptrToThis typeOff // type for pointer to this type, may be zero 45 } 46 47 type itab struct { 48 inter *interfaceType 49 _type *rtype 50 hash uint32 // copy of _type.hash. Used for type switches. 51 _ [4]byte 52 fun [1]uintptr // variable sized. fun[0]==0 means _type does not implement inter. 53 } 54 55 type interfaceType struct { 56 typ rtype 57 pkgpath name 58 mhdr []iMethod 59 } 60 61 type name struct { 62 bytes *byte 63 } 64 65 type iMethod struct { 66 name nameOff 67 typ typeOff 68 } 69 70 var ( 71 itabRtype = func(v interface{}) *itab { 72 t := reflect.TypeOf(v).Elem() 73 return (*iface)(unsafe.Pointer(&t)).tab 74 }(new(reflect.Type)) 75 ) 76 77 func unpackType(t reflect.Type) *rtype { 78 return (*rtype)((*eface)(unsafe.Pointer(&t)).data) 79 } 80 81 func packType(t *rtype) (r reflect.Type) { 82 (*iface)(unsafe.Pointer(&r)).tab = itabRtype 83 (*iface)(unsafe.Pointer(&r)).data = unsafe.Pointer(t) 84 return 85 }