mirror of
https://github.com/fumiama/fumitok.git
synced 2026-06-05 00:32:50 +08:00
16 lines
304 B
Go
16 lines
304 B
Go
package fumitok
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
// BytesToString 没有内存开销的转换
|
|
func BytesToString(b []byte) string {
|
|
return *(*string)(unsafe.Pointer(&b))
|
|
}
|
|
|
|
// StringToBytes 没有内存开销的转换
|
|
func StringToBytes(s string) (b []byte) {
|
|
return unsafe.Slice(unsafe.StringData(s), len(s))
|
|
}
|