github.com/racerxdl/gonx@v0.0.0-20210103083128-c5afc43bcbd2/services/ipc/buffer.go (about)

     1  package ipc
     2  
     3  import (
     4  	"encoding/binary"
     5  	"github.com/racerxdl/gonx/nx/nxtypes"
     6  )
     7  
     8  var (
     9  	sfci = binary.LittleEndian.Uint32([]byte("SFCI"))
    10  	sfco = binary.LittleEndian.Uint32([]byte("SFCO"))
    11  )
    12  
    13  type Direction uint8
    14  type Family uint8
    15  
    16  type Type uint32
    17  type BufferFamily int
    18  
    19  const (
    20  	BufferFamilyA BufferFamily = 0
    21  	BufferFamilyB BufferFamily = 1
    22  	BufferFamilyC BufferFamily = 2
    23  	BufferFamilyX BufferFamily = 3
    24  
    25  	DirectionInput  Direction = 1 // 0b01
    26  	DirectionOutput Direction = 2 // 0b10
    27  
    28  	FamilyA Family = 1 // 0b01
    29  	FamilyB Family = 1 // 0b01
    30  	FamilyX Family = 2 // 0b10
    31  	FamilyC Family = 2 // 0b10
    32  )
    33  
    34  type Domain struct {
    35  	Session nxtypes.SessionHandle
    36  }
    37  
    38  type Buffer struct {
    39  	Addr uintptr
    40  	Size uint64
    41  	Type uint32
    42  }
    43  
    44  func (i Buffer) Direction() Direction {
    45  	return Direction(i.Type & 3)
    46  }
    47  
    48  func (i Buffer) Family() Family {
    49  	return Family((i.Type & 12) >> 2)
    50  }
    51  
    52  // nullBuffer is a empty buffer
    53  // used in some "workarounds"
    54  var nullBuffer = Buffer{
    55  	Addr: 0,
    56  	Type: 0,
    57  	Size: 0,
    58  }
    59  
    60  func ipcPadSize(size uint64) uint64 {
    61  	return (size + 3) & ^uint64(3)
    62  }