1
0
mirror of https://github.com/redis/go-redis.git synced 2025-12-18 23:34:11 +03:00
Files
go-redis/internal/util/unsafe.go
Justin Hwang 3aec3ddf9a chore(proto): use go 1.20 idiomatic string<->byte conversion (#3435)
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>
2025-12-05 13:10:00 +02:00

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))
}