github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/convert.go (about)

     1  package jzon
     2  
     3  import (
     4  	"unsafe"
     5  )
     6  
     7  func localStringToBytes(s string) []byte {
     8  	sh := (*stringHeader)(unsafe.Pointer(&s))
     9  	return *(*[]byte)(unsafe.Pointer(&sliceHeader{
    10  		Data: sh.Data,
    11  		Len:  sh.Len,
    12  		Cap:  sh.Len,
    13  	}))
    14  }
    15  
    16  func localByteToString(buf []byte) string {
    17  	return *(*string)(unsafe.Pointer(&buf))
    18  }