github.com/ovechkin-dm/go-dyno@v0.0.23/proxy/model.go (about) 1 package proxy 2 3 import ( 4 "fmt" 5 "reflect" 6 "unsafe" 7 ) 8 9 type StructValue struct { 10 typ uintptr 11 } 12 13 type IFaceValue struct { 14 Typ uintptr 15 Ptr *NonEmptyInterface 16 Flag uintptr 17 } 18 19 type NonEmptyInterface struct { 20 Itab *itab 21 Word unsafe.Pointer 22 } 23 24 type itab struct { 25 ityp uintptr 26 typ uintptr 27 hash uint32 28 _ [4]byte 29 fun [260]unsafe.Pointer 30 } 31 32 type DynamicStruct struct { 33 methods []*methodContext 34 arr []int64 35 IFaceValue reflect.Value 36 IFaceValueSource *IFaceValue 37 } 38 39 func (d *DynamicStruct) String() string { 40 return fmt.Sprintf("DynamicProxy[%v]", d.IFaceValue.Type()) 41 } 42 43 func UnsafeCast[T any](v *DynamicStruct) T { 44 ifaceInstance := new(T) 45 ii := reflect.ValueOf(ifaceInstance).Elem() 46 ifaceValue := (*IFaceValue)(unsafe.Pointer(&ii)) 47 ifaceValue.Ptr.Word = v.IFaceValueSource.Ptr.Word 48 ifaceValue.Ptr.Itab = v.IFaceValueSource.Ptr.Itab 49 ifaceValue.Flag = v.IFaceValueSource.Flag 50 ifaceValue.Typ = v.IFaceValueSource.Typ 51 return *ifaceInstance 52 } 53 54 type methodContext struct { 55 fn *makeFuncImpl 56 tp reflect.Type 57 rv reflect.Value 58 } 59 60 type MethodInfo struct { 61 Num int 62 Name string 63 ReflectValue reflect.Value 64 Type reflect.Method 65 } 66 67 type refValue struct { 68 typ *rtype 69 ptr unsafe.Pointer 70 uintptr 71 } 72 73 type makeFuncImpl struct { 74 makeFuncCtxt 75 ftyp *funcType 76 fn func([]reflect.Value) []reflect.Value 77 } 78 79 type makeFuncCtxt struct { 80 fn uintptr 81 stack uintptr 82 argLen uintptr 83 regPtrs [2]uint8 84 } 85 86 type funcType struct { 87 rtype 88 inCount uint16 89 outCount uint16 90 } 91 92 type rtype struct { 93 size uintptr 94 ptrdata uintptr 95 hash uint32 96 tflag uint8 97 align uint8 98 fieldAlign uint8 99 kind uint8 100 equal func(unsafe.Pointer, unsafe.Pointer) bool 101 gcdata *byte 102 str int32 103 ptrToThis int32 104 }