mirror of
https://github.com/redis/go-redis.git
synced 2025-12-18 23:34:11 +03:00
As of Go 1.20, this is the idiomatic way to convert from Bytes to String and vice-versa. This updates `go.mod` to 1.20, builds have already been running on 1.23.x and 1.24.x since #3274. Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
18 lines
338 B
Go
18 lines
338 B
Go
//go:build !appengine
|
|
|
|
package util
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
// BytesToString converts byte slice to string.
|
|
func BytesToString(b []byte) string {
|
|
return unsafe.String(unsafe.SliceData(b), len(b))
|
|
}
|
|
|
|
// StringToBytes converts string to byte slice.
|
|
func StringToBytes(s string) []byte {
|
|
return unsafe.Slice(unsafe.StringData(s), len(s))
|
|
}
|