本站源代码
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.

23 lines
362B

  1. // +build !appengine
  2. package util
  3. import (
  4. "unsafe"
  5. )
  6. // BytesToString converts byte slice to string.
  7. func BytesToString(b []byte) string {
  8. return *(*string)(unsafe.Pointer(&b))
  9. }
  10. // StringToBytes converts string to byte slice.
  11. func StringToBytes(s string) []byte {
  12. return *(*[]byte)(unsafe.Pointer(
  13. &struct {
  14. string
  15. Cap int
  16. }{s, len(s)},
  17. ))
  18. }
上海开阖软件有限公司 沪ICP备12045867号-1