gitee.com/quant1x/gox@v1.21.2/api/string_bytes_above_120.go (about)

     1  //go:build go1.20
     2  
     3  package api
     4  
     5  import (
     6  	"unsafe"
     7  )
     8  
     9  // Bytes2String 字节数组转字符串
    10  func Bytes2String(b []byte) string {
    11  	return unsafe.String(&b[0], len(b))
    12  }
    13  
    14  // String2Bytes 字符串转字节数组
    15  func String2Bytes(s string) []byte {
    16  	return unsafe.Slice(unsafe.StringData(s), len(s))
    17  }