bytes<->string without allocation. However, bytes can't be changed.
// StringToBytes converts string to byte slice without a memory allocation.
// The bytes must not be modified; doing so can cause
// the program to crash or behave unpredictably.
func StringToBytes(s string) []byte {
return unsafe.Slice(unsafe.StringData(s), len(s))
}
// BytesToString converts byte slice to string without a memory allocation.
// The bytes passed must not be modified later;
// doing so can cause the program to crash or behave unpredictably.
func BytesToString(b []byte) string {
return unsafe.String(&b[0], len(b))
}