unsafe.go 862 B

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