You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
374 B
23 lines
374 B
3 years ago
|
package local_cache
|
||
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
"unsafe"
|
||
|
)
|
||
|
|
||
|
func String(b []byte) (s string) {
|
||
|
if len(b) == 0 {
|
||
|
return ""
|
||
|
}
|
||
|
return *(*string)(unsafe.Pointer(&b))
|
||
|
}
|
||
|
|
||
|
func StringBytes(s string) []byte {
|
||
|
var b []byte
|
||
|
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||
|
hdr.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
|
||
|
hdr.Cap = len(s)
|
||
|
hdr.Len = len(s)
|
||
|
return b
|
||
|
}
|