unsafe.go 353 B

123456789101112131415161718192021
  1. //go:build !appengine
  2. // +build !appengine
  3. package internal
  4. import "unsafe"
  5. // String converts byte slice to string.
  6. func String(b []byte) string {
  7. return *(*string)(unsafe.Pointer(&b))
  8. }
  9. // Bytes converts string to byte slice.
  10. func Bytes(s string) []byte {
  11. return *(*[]byte)(unsafe.Pointer(
  12. &struct {
  13. string
  14. Cap int
  15. }{s, len(s)},
  16. ))
  17. }