mirror of
https://github.com/fumiama/unibase2n.git
synced 2026-06-30 00:40:32 +08:00
add base & pack
This commit is contained in:
20
helper.go
Normal file
20
helper.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package unibase2n
|
||||
|
||||
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