any.go 342 B

12345678910111213
  1. package conv
  2. import "unsafe"
  3. // The change of bytes will cause the change of string synchronously
  4. func BytesToString(b []byte) string {
  5. return unsafe.String(unsafe.SliceData(b), len(b))
  6. }
  7. // If string is readonly, modifying bytes will cause panic
  8. func StringToBytes(s string) []byte {
  9. return unsafe.Slice(unsafe.StringData(s), len(s))
  10. }