github.com/ii64/gouring@v0.4.1/util_ptr_arith.go (about)

     1  package gouring
     2  
     3  import (
     4  	"unsafe"
     5  )
     6  
     7  type uint32Array = unsafe.Pointer // *uint32
     8  
     9  func uint32Array_Index(u uint32Array, i uintptr) *uint32 {
    10  	return (*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(u)) + SizeofUint32*i))
    11  }
    12  
    13  type ioUringSqeArray = unsafe.Pointer // *IoUringSqe
    14  
    15  func ioUringSqeArray_Index(u ioUringSqeArray, i uintptr) *IoUringSqe {
    16  	return (*IoUringSqe)(unsafe.Pointer(uintptr(unsafe.Pointer(u)) + SizeofIoUringSqe*i))
    17  }
    18  
    19  //
    20  
    21  type ioUringCqeArray = unsafe.Pointer // *IoUringCqe
    22  
    23  func ioUringCqeArray_Index(u ioUringCqeArray, i uintptr) *IoUringCqe {
    24  	return (*IoUringCqe)(unsafe.Pointer(uintptr(unsafe.Pointer(u)) + SizeofIoUringCqe*i))
    25  }
    26  
    27  //
    28  
    29  type UserData [8]byte // uint64
    30  
    31  func (u *UserData) SetUint64(v uint64) {
    32  	putUintptr(unsafe.Pointer(u), uintptr(v))
    33  
    34  }
    35  func (u *UserData) SetUintptr(v uintptr) {
    36  	putUintptr(unsafe.Pointer(u), v)
    37  }
    38  func (u *UserData) SetUnsafe(ptr unsafe.Pointer) {
    39  	putUnsafe(unsafe.Pointer(u), ptr)
    40  }
    41  
    42  func (u UserData) GetUnsafe() unsafe.Pointer {
    43  	return *(*unsafe.Pointer)(unsafe.Pointer(&u))
    44  }
    45  func (u UserData) GetUintptr() uintptr {
    46  	return uintptr(u.GetUnsafe())
    47  }
    48  func (u UserData) GetUint64() uint64 {
    49  	return uint64(u.GetUintptr())
    50  }
    51  func (u UserData) IsZero() bool {
    52  	return u.GetUintptr() == 0
    53  }
    54  
    55  // ---
    56  
    57  func putUnsafe(ptr unsafe.Pointer, v unsafe.Pointer) {
    58  	*(*unsafe.Pointer)(ptr) = v
    59  }
    60  
    61  func putUintptr(ptr unsafe.Pointer, v uintptr) {
    62  	*(*uintptr)(ptr) = v
    63  }
    64  func putUint64(ptr unsafe.Pointer, v uint64) {
    65  	*(*uint64)(ptr) = v
    66  }
    67  func putUint32(ptr unsafe.Pointer, v uint32) {
    68  	*(*uint32)(ptr) = v
    69  }
    70  func putUint16(ptr unsafe.Pointer, v uint16) {
    71  	*(*uint16)(ptr) = v
    72  }
    73  func putUint8(ptr unsafe.Pointer, v uint8) {
    74  	*(*uint8)(ptr) = v
    75  }
    76  
    77  func putInt64(ptr unsafe.Pointer, v int64) {
    78  	*(*int64)(ptr) = v
    79  }
    80  func putInt32(ptr unsafe.Pointer, v int32) {
    81  	*(*int32)(ptr) = v
    82  }
    83  func putInt16(ptr unsafe.Pointer, v int16) {
    84  	*(*int16)(ptr) = v
    85  }
    86  func putInt8(ptr unsafe.Pointer, v int8) {
    87  	*(*int8)(ptr) = v
    88  }