代码拉取完成,页面将自动刷新
package labs
import (
"fmt"
"gitee.com/quant1x/engine/factors"
"reflect"
"strings"
"sync"
"unsafe"
)
//go:linkname typelinks2 reflect.typelinks
func typelinks2() (sections []unsafe.Pointer, offset [][]int32)
//go:linkname resolveTypeOff reflect.resolveTypeOff
func resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer
var (
typeOnce sync.Once
types = map[string]reflect.Type{}
packages = map[string]map[string]reflect.Type{}
)
type emptyInterface struct {
typ unsafe.Pointer
word unsafe.Pointer
}
func loadGoTypes() {
fia := reflect.TypeOf((*factors.Feature)(nil)).Elem()
var obj interface{} = reflect.TypeOf(0)
sections, offset := typelinks2()
for i, offs := range offset {
rodata := sections[i]
for _, off := range offs {
(*emptyInterface)(unsafe.Pointer(&obj)).word = resolveTypeOff(unsafe.Pointer(rodata), off)
typ := obj.(reflect.Type)
if typ.Kind() == reflect.Ptr && typ.Elem().Kind() == reflect.Struct {
loadedType := typ.Elem()
pkgTypes := packages[loadedType.PkgPath()]
if pkgTypes == nil {
pkgTypes = map[string]reflect.Type{}
packages[loadedType.PkgPath()] = pkgTypes
}
//types[typeString] = loadedType
pkgPath := loadedType.PkgPath()
typeName := loadedType.Name()
//typeString := loadedType.String()
//fmt.Println(pkgPath, "=>", typeString, "=>", typeName)
structName := fmt.Sprintf("%s.%s", pkgPath, typeName)
types[structName] = loadedType
pkgTypes[loadedType.Name()] = loadedType
if strings.HasPrefix(pkgPath, "gitee.com/quant1x/engine") {
//fmt.Println(structName, "==>", loadedType.PkgPath())
if reflect.PtrTo(loadedType).Implements(fia) {
fmt.Println("found", pkgPath, "==>", loadedType.String(), "==>", structName)
}
}
}
}
}
}
func lazyInit() {
loadGoTypes()
}
func FindImplements(u reflect.Type) (list []reflect.Type) {
typeOnce.Do(lazyInit)
for name, t := range types {
//fmt.Println(name)
if reflect.PtrTo(t).Implements(u) {
list = append(list, t)
}
_ = name
}
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。