diff options
| author | Joe Richey joerichey@google.com <joerichey@google.com> | 2017-07-17 15:40:02 -0700 |
|---|---|---|
| committer | Joe Richey joerichey@google.com <joerichey@google.com> | 2017-07-17 15:40:02 -0700 |
| commit | 0b643ea0976f7bbd3cebef08c449090869701226 (patch) | |
| tree | 35c98f585201d48aecb5175763cd9330f7475997 /util/util.go | |
| parent | 6f32bbc8bf51d615ef23ed37aa40910ec23cd587 (diff) | |
util: Add conversions for byte/pointer arrays
Diffstat (limited to 'util/util.go')
| -rw-r--r-- | util/util.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/util/util.go b/util/util.go index 32e5c06..792b66c 100644 --- a/util/util.go +++ b/util/util.go @@ -37,6 +37,18 @@ func Ptr(slice []byte) unsafe.Pointer { return unsafe.Pointer(&slice[0]) } +// ByteSlice takes a pointer to some data and views it as a slice of bytes. +// Note, indexing into this slice is unsafe. +func ByteSlice(ptr unsafe.Pointer) []byte { + return (*[1 << 30]byte)(ptr)[:] +} + +// PointerSlice takes a pointer to an array of pointers and views it as a slice +// of pointers. Note, indexing into this slice is unsafe. +func PointerSlice(ptr unsafe.Pointer) []unsafe.Pointer { + return (*[1 << 30]unsafe.Pointer)(ptr)[:] +} + // Index returns the first index i such that inVal == inArray[i]. // ok is true if we find a match, false otherwise. func Index(inVal int64, inArray []int64) (index int, ok bool) { |