From 8d37b05bc168f5268039b73e10c06a199a96ed71 Mon Sep 17 00:00:00 2001 From: Nugraha <richiisei@gmail.com> Date: Thu, 13 Oct 2022 22:03:46 +0700 Subject: [PATCH] fix: change base type of UserData to uint64 --- util_ptr_arith.go | 5 ++++- util_ptr_arith_test.go | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/util_ptr_arith.go b/util_ptr_arith.go index 7192fa8..7767488 100644 --- a/util_ptr_arith.go +++ b/util_ptr_arith.go @@ -34,7 +34,7 @@ func ioUringCqe32Array_Index(u ioUringCqeArray, i uintptr) *IoUringCqe { // -type UserData [8]byte // uint64 +type UserData uint64 func (u *UserData) SetUint64(v uint64) { putUintptr(unsafe.Pointer(u), uintptr(v)) @@ -50,6 +50,9 @@ func (u *UserData) SetUnsafe(ptr unsafe.Pointer) { func (u UserData) GetUnsafe() unsafe.Pointer { return *(*unsafe.Pointer)(unsafe.Pointer(&u)) } +func (u UserData) GetBytes() [8]byte { + return *(*[8]byte)(u.GetUnsafe()) +} func (u UserData) GetUintptr() uintptr { return uintptr(u.GetUnsafe()) } diff --git a/util_ptr_arith_test.go b/util_ptr_arith_test.go index 27f50fb..b8c33c8 100644 --- a/util_ptr_arith_test.go +++ b/util_ptr_arith_test.go @@ -39,6 +39,7 @@ func TestUserdata(t *testing.T) { var exp [8]byte bo.PutUint64(exp[:], tc.exp) - assert.Equal(t, exp[:], u[:]) + // assert.Equal(t, exp[:], u[:]) + assert.Equal(t, tc.exp, u.GetUint64()) } }