You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
384 B

  1. //go:build !appengine
  2. // +build !appengine
  3. package util
  4. import (
  5. "unsafe"
  6. )
  7. // BytesToString converts byte slice to string.
  8. func BytesToString(b []byte) string {
  9. return *(*string)(unsafe.Pointer(&b))
  10. }
  11. // StringToBytes converts string to byte slice.
  12. func StringToBytes(s string) []byte {
  13. return *(*[]byte)(unsafe.Pointer(
  14. &struct {
  15. string
  16. Cap int
  17. }{s, len(s)},
  18. ))
  19. }