internal/unsafebytes/unsafebytes.go
raw| 1 | package unsafebytes |
| 2 | |
| 3 | import "unsafe" |
| 4 | |
| 5 | func Pointer(b []byte) *byte { |
| 6 | return *(**byte)(unsafe.Pointer(&b)) |
| 7 | } |
| 8 | |
| 9 | func String(b []byte) string { |
| 10 | return *(*string)(unsafe.Pointer(&b)) |
| 11 | } |
| 12 | |
| 13 | func BytesOf(s string) []byte { |
| 14 | return *(*[]byte)(unsafe.Pointer(&sliceHeader{str: s, cap: len(s)})) |
| 15 | } |
| 16 | |
| 17 | type sliceHeader struct { |
| 18 | str string |
| 19 | cap int |
| 20 | } |