github.com/racerxdl/gonx@v0.0.0-20210103083128-c5afc43bcbd2/services/ipc/request.go (about) 1 package ipc 2 3 import ( 4 "github.com/racerxdl/gonx/nx/nxtypes" 5 ) 6 7 // Maximum allocated descriptors is always 16 8 const maxIPCDescriptors = 16 9 const debug = false 10 const debugDumpBeforeSend = false 11 12 const ( 13 TypeIPCInvalid Type = 0 14 TypeIPCLegacyRequest Type = 1 15 TypeIPCClose Type = 2 16 TypeIPCLegacyControl Type = 3 17 TypeIPCRequest Type = 4 18 TypeIPCControl Type = 5 19 TypeIPCRequestWithContext Type = 6 20 TypeIPCControlWithContext Type = 7 21 ) 22 23 // Request Represents an unmarshalled outgoing IPC request 24 // see http://switchbrew.org/index.php?title=IPC_Marshalling#IPC_Command_Structure 25 type Request struct { 26 Type Type 27 Buffers []*Buffer 28 RequestID uint32 29 RawData []byte 30 SendPID bool 31 CopyHandles []nxtypes.Handle 32 MoveHandles []nxtypes.Handle 33 Objects []Object 34 CloseObject bool 35 } 36 37 //// SetRawDataFromPointer copies the specified data to internal RawData field 38 //func (i *Request) SetRawDataFromPointer(ptr unsafe.Pointer, dataLen uintptr) { 39 // i.RawData = make([]byte, dataLen) 40 // Memcpy(unsafe.Pointer(&i.RawData[0]), ptr, dataLen) 41 //} 42 43 func (i *Request) SetRawDataFromUint64(data uint64) { 44 i.RawData = make([]byte, 8) 45 i.RawData[0] = byte(data) 46 i.RawData[1] = byte(data >> 8) 47 i.RawData[2] = byte(data >> 16) 48 i.RawData[3] = byte(data >> 24) 49 i.RawData[4] = byte(data >> 32) 50 i.RawData[5] = byte(data >> 40) 51 i.RawData[6] = byte(data >> 48) 52 i.RawData[7] = byte(data >> 56) 53 } 54 55 func (i *Request) SetRawDataFromUint32Slice(data []uint32) { 56 i.RawData = make([]byte, len(data)*4) 57 for n, v := range data { 58 i.RawData[n*4+0] = byte(v) 59 i.RawData[n*4+1] = byte(v >> 8) 60 i.RawData[n*4+2] = byte(v >> 16) 61 i.RawData[n*4+3] = byte(v >> 24) 62 } 63 } 64 65 func MakeDefaultRequest(requestId uint32) Request { 66 return Request{ 67 Type: TypeIPCRequest, 68 RequestID: requestId, 69 } 70 }