mirror of
https://github.com/fumiama/go-base16384.git
synced 2026-06-12 14:10:32 +08:00
适配所有架构
This commit is contained in:
20
helper.go
Normal file
20
helper.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user