github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/utils/convert/convert.go (about) 1 package convert 2 3 import ( 4 "reflect" 5 "unsafe" 6 ) 7 8 func StringToBytes(str string) (p []byte) { 9 return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ 10 Data: *(*uintptr)(unsafe.Pointer(&str)), 11 Len: len(str), 12 Cap: len(str), 13 })) 14 } 15 16 func BytesToString(p []byte) string { 17 return *(*string)(unsafe.Pointer(&p)) 18 }