writer_unsafe.go 371 B

1234567891011121314151617181920
  1. //go:build !appengine && !tinygo
  2. // +build !appengine,!tinygo
  3. package fwd
  4. import (
  5. "reflect"
  6. "unsafe"
  7. )
  8. // unsafe cast string as []byte
  9. func unsafestr(s string) []byte {
  10. var b []byte
  11. sHdr := (*reflect.StringHeader)(unsafe.Pointer(&s))
  12. bHdr := (*reflect.SliceHeader)(unsafe.Pointer(&b))
  13. bHdr.Data = sHdr.Data
  14. bHdr.Len = sHdr.Len
  15. bHdr.Cap = sHdr.Len
  16. return b
  17. }