wasi-module-sdk-go/internal/mem/unmanaged.go

18 lines
425 B
Go
Raw Normal View History

2023-05-08 13:21:31 +00:00
package mem
import "unsafe"
func DataToManagedPtr(data []byte) (uint32, uint32) {
ptr := unsafe.Pointer(unsafe.SliceData(data))
return uint32(uintptr(ptr)), uint32(len(data))
}
func DataFromPtr(ptr, size uint32) []byte {
p := unsafe.Pointer(uintptr(ptr))
return unsafe.Slice((*byte)(p), int(size))
}
func PtrToData(ptr uint32, size uint32) []byte {
return unsafe.Slice((*byte)(unsafe.Pointer(uintptr(ptr))), size)
}