1
0
mirror of https://github.com/fumiama/go-base16384.git synced 2026-06-12 14:10:32 +08:00

适配所有架构

This commit is contained in:
fumiama
2022-02-10 13:58:39 +08:00
parent 86dc5b5b23
commit d84411a4ef
6 changed files with 37 additions and 78 deletions

20
helper.go Normal file
View File

@@ -0,0 +1,20 @@
package base14
import (
"unsafe"
)
// BytesToString 没有内存开销的转换
func BytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
// StringToBytes 没有内存开销的转换
func StringToBytes(s string) (b []byte) {
bh := (*slice)(unsafe.Pointer(&b))
sh := (*slice)(unsafe.Pointer(&s))
bh.Data = sh.Data
bh.Len = sh.Len
bh.Cap = sh.Len
return b
}