Skip to content

Instantly share code, notes, and snippets.

@awnumar
Created April 29, 2017 21:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awnumar/370dbf60455986f4a4137793d465ac12 to your computer and use it in GitHub Desktop.
Save awnumar/370dbf60455986f4a4137793d465ac12 to your computer and use it in GitHub Desktop.
Go function to convert a pointer to a slice.
package ptr2bytes
func GetBytesFromPtr(ptr uintptr, len int, cap int) []byte {
var sl = struct {
addr uintptr
len int
cap int
}{ptr, len, cap}
return *(*[]byte)(unsafe.Pointer(&sl))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment