1
0
mirror of https://github.com/fumiama/go-nd-portal.git synced 2026-06-05 08:20:26 +08:00
Files
go-nd-portal/helper.go
源文雨 8743bf9b5d init
2022-11-26 00:39:38 +08:00

22 lines
431 B
Go

package gondportal
import (
"reflect"
"unsafe"
)
// BytesToString 没有内存开销的转换
func BytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
// StringToBytes 没有内存开销的转换
func StringToBytes(s string) (b []byte) {
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
bh.Data = sh.Data
bh.Len = sh.Len
bh.Cap = sh.Len
return b
}