Skip to content

Instantly share code, notes, and snippets.

View giliao's full-sized avatar
🎯
Focusing

giliao

🎯
Focusing
View GitHub Profile
// no copy to change slice to string
// use your own risk
func String(b []byte) (s string) {
pbytes := (*reflect.SliceHeader)(unsafe.Pointer(&b))
pstring := (*reflect.StringHeader)(unsafe.Pointer(&s))
pstring.Data = pbytes.Data
pstring.Len = pbytes.Len
return
}