forked from mirror/redis
28 lines
521 B
Go
28 lines
521 B
Go
// +build !appengine
|
|
|
|
package internal
|
|
|
|
import (
|
|
"reflect"
|
|
"unsafe"
|
|
)
|
|
|
|
func BytesToString(b []byte) string {
|
|
bytesHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
|
strHeader := reflect.StringHeader{
|
|
Data: bytesHeader.Data,
|
|
Len: bytesHeader.Len,
|
|
}
|
|
return *(*string)(unsafe.Pointer(&strHeader))
|
|
}
|
|
|
|
func StringToBytes(s string) []byte {
|
|
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
|
bh := reflect.SliceHeader{
|
|
Data: sh.Data,
|
|
Len: sh.Len,
|
|
Cap: sh.Len,
|
|
}
|
|
return *(*[]byte)(unsafe.Pointer(&bh))
|
|
}
|