summaryrefslogtreecommitdiff
path: root/utils/convert.go
blob: 8728ad1f2b792436224f87a3b7e66d9a5861641e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package utils

import (
	"reflect"
	"unsafe"
)

// AsString returns a string that refers to the data backing the slice s.
func AsString(b []byte) string {
	p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&b)).Data)

	var s string
	hdr := (*reflect.StringHeader)(unsafe.Pointer(&s))
	hdr.Data = uintptr(p)
	hdr.Len = len(b)

	return s
}

// Uint64 returns a pointer value for the uint64 value passed in.
func Uint64(v uint64) *uint64 {
	return &v
}