1
0
mirror of https://github.com/fumiama/go-nd-portal.git synced 2026-06-29 23:51:06 +08:00
This commit is contained in:
源文雨
2022-11-26 15:47:31 +08:00
parent 51de023bdb
commit 91808d70b9
13 changed files with 293 additions and 72 deletions

21
helper/helper.go Normal file
View File

@@ -0,0 +1,21 @@
package helper
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
}