...
1 package base64x
2
3 import (
4 `reflect`
5 `unsafe`
6 )
7
8 func mem2str(v []byte) (s string) {
9 (*reflect.StringHeader)(unsafe.Pointer(&s)).Len = (*reflect.SliceHeader)(unsafe.Pointer(&v)).Len
10 (*reflect.StringHeader)(unsafe.Pointer(&s)).Data = (*reflect.SliceHeader)(unsafe.Pointer(&v)).Data
11 return
12 }
13
14 func str2mem(s string) (v []byte) {
15 (*reflect.SliceHeader)(unsafe.Pointer(&v)).Cap = (*reflect.StringHeader)(unsafe.Pointer(&s)).Len
16 (*reflect.SliceHeader)(unsafe.Pointer(&v)).Len = (*reflect.StringHeader)(unsafe.Pointer(&s)).Len
17 (*reflect.SliceHeader)(unsafe.Pointer(&v)).Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
18 return
19 }
20
21 func mem2addr(v []byte) unsafe.Pointer {
22 return *(*unsafe.Pointer)(unsafe.Pointer(&v))
23 }
24
25
26
27
28
29
30
31
32 func noEscape(p unsafe.Pointer) unsafe.Pointer {
33 x := uintptr(p)
34 return unsafe.Pointer(x ^ 0)
35 }
36
View as plain text