Created
April 29, 2017 21:54
-
-
Save awnumar/370dbf60455986f4a4137793d465ac12 to your computer and use it in GitHub Desktop.
Go function to convert a pointer to a slice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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