github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/eface.go (about) 1 package jzon 2 3 import ( 4 "reflect" 5 "unsafe" 6 ) 7 8 type rtype = uintptr 9 10 type eface struct { 11 rtype rtype 12 data unsafe.Pointer 13 } 14 15 func packEFace(rtype rtype, data unsafe.Pointer) interface{} { 16 var i interface{} 17 e := (*eface)(unsafe.Pointer(&i)) 18 e.rtype = rtype 19 e.data = data 20 return i 21 } 22 23 func rtypeOfType(typ reflect.Type) rtype { 24 ef := (*eface)(unsafe.Pointer(&typ)) 25 return rtype(ef.data) 26 } 27 28 type stringHeader = reflect.StringHeader 29 type sliceHeader = reflect.SliceHeader 30 31 /* 32 type stringHeader struct { 33 Data unsafe.Pointer 34 Len int 35 } 36 37 type sliceHeader struct { 38 Data unsafe.Pointer 39 Len int 40 Cap int 41 } 42 */