redis/internal/util/unsafe.go

23 lines
363 B
Go
Raw Normal View History

2021-09-08 16:00:52 +03:00
//go:build !appengine
2017-01-13 14:39:59 +03:00
2018-02-22 15:14:30 +03:00
package util
2017-01-13 14:39:59 +03:00
import (
"unsafe"
)
2018-01-11 11:07:24 +03:00
// BytesToString converts byte slice to string.
2017-01-13 14:39:59 +03:00
func BytesToString(b []byte) string {
2018-01-11 11:07:24 +03:00
return *(*string)(unsafe.Pointer(&b))
2017-01-13 14:39:59 +03:00
}
2018-08-17 13:56:37 +03:00
// StringToBytes converts string to byte slice.
func StringToBytes(s string) []byte {
return *(*[]byte)(unsafe.Pointer(
&struct {
string
Cap int
}{s, len(s)},
))
}