16 lines
553 B
Go
16 lines
553 B
Go
package binding
|
|
|
|
import "unsafe"
|
|
|
|
// stringToBytes converts string to byte slice without a memory allocation.
|
|
// For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077.
|
|
func stringToBytes(s string) []byte {
|
|
return unsafe.Slice(unsafe.StringData(s), len(s))
|
|
}
|
|
|
|
// bytesToString converts byte slice to string without a memory allocation.
|
|
// For more details, see https://github.com/golang/go/issues/53003#issuecomment-1140276077.
|
|
func bytesToString(b []byte) string {
|
|
return unsafe.String(unsafe.SliceData(b), len(b))
|
|
}
|