unsafe.go 853 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //go:build !purego && !appengine
  2. // +build !purego,!appengine
  3. package msgp
  4. import (
  5. "unsafe"
  6. )
  7. // NOTE:
  8. // all of the definition in this file
  9. // should be repeated in appengine.go,
  10. // but without using unsafe
  11. const (
  12. // spec says int and uint are always
  13. // the same size, but that int/uint
  14. // size may not be machine word size
  15. smallint = unsafe.Sizeof(int(0)) == 4
  16. )
  17. // UnsafeString returns the byte slice as a volatile string
  18. // THIS SHOULD ONLY BE USED BY THE CODE GENERATOR.
  19. // THIS IS EVIL CODE.
  20. // YOU HAVE BEEN WARNED.
  21. func UnsafeString(b []byte) string {
  22. return *(*string)(unsafe.Pointer(&b))
  23. }
  24. // UnsafeBytes returns the string as a byte slice
  25. //
  26. // Deprecated:
  27. // Since this code is no longer used by the code generator,
  28. // UnsafeBytes(s) is precisely equivalent to []byte(s)
  29. func UnsafeBytes(s string) []byte {
  30. return []byte(s)
  31. }