writer_tinygo.go 313 B

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