github.com/jxskiss/gopkg@v0.17.3/internal/unsafeheader/convert.go (about)

     1  package unsafeheader
     2  
     3  import "unsafe"
     4  
     5  func StringToBytes(s string) []byte {
     6  	sh := (*String)(unsafe.Pointer(&s))
     7  	bh := &Slice{
     8  		Data: sh.Data,
     9  		Len:  sh.Len,
    10  		Cap:  sh.Len,
    11  	}
    12  	return *(*[]byte)(unsafe.Pointer(bh))
    13  }
    14  
    15  func BytesToString(b []byte) string {
    16  	return *(*string)(unsafe.Pointer(&b))
    17  }