Beispiel #1
0
        public byte[] GetBytes(long CmdPtr)
        {
            //todo
            using (MemoryStream MS = new MemoryStream())
            {
                BinaryWriter Writer = new BinaryWriter(MS);

                int Word0;
                int Word1;

                Word0  = (int)Type;
                Word0 |= (PtrBuff.Count & 0xf) << 16;
                Word0 |= (SendBuff.Count & 0xf) << 20;
                Word0 |= (ReceiveBuff.Count & 0xf) << 24;
                Word0 |= (ExchangeBuff.Count & 0xf) << 28;

                byte[] HandleData = new byte[0];

                if (HandleDesc != null)
                {
                    HandleData = HandleDesc.GetBytes();
                }

                int DataLength = RawData?.Length ?? 0;

                int Pad0 = (int)GetPadSize16(CmdPtr + 8 + HandleData.Length);

                //Apparently, padding after Raw Data is 16 bytes, however when there is
                //padding before Raw Data too, we need to subtract the size of this padding.
                //This is the weirdest padding I've seen so far...
                int Pad1 = 0x10 - Pad0;

                DataLength = (DataLength + Pad0 + Pad1) / 4;

                Word1 = DataLength & 0x3ff;

                if (HandleDesc != null)
                {
                    Word1 |= 1 << 31;
                }

                Writer.Write(Word0);
                Writer.Write(Word1);
                Writer.Write(HandleData);

                MS.Seek(Pad0, SeekOrigin.Current);

                if (RawData != null)
                {
                    Writer.Write(RawData);
                }

                Writer.Write(new byte[Pad1]);

                return(MS.ToArray());
            }
        }
Beispiel #2
0
        public byte[] GetBytes(long cmdPtr)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                BinaryWriter writer = new BinaryWriter(ms);

                int word0;
                int word1;

                word0  = (int)Type;
                word0 |= (PtrBuff.Count & 0xf) << 16;
                word0 |= (SendBuff.Count & 0xf) << 20;
                word0 |= (ReceiveBuff.Count & 0xf) << 24;
                word0 |= (ExchangeBuff.Count & 0xf) << 28;

                byte[] handleData = new byte[0];

                if (HandleDesc != null)
                {
                    handleData = HandleDesc.GetBytes();
                }

                int dataLength = RawData?.Length ?? 0;

                int pad0 = (int)GetPadSize16(cmdPtr + 8 + handleData.Length);

                // Apparently, padding after Raw Data is 16 bytes, however when there is
                // padding before Raw Data too, we need to subtract the size of this padding.
                // This is the weirdest padding I've seen so far...
                int pad1 = 0x10 - pad0;

                dataLength = (dataLength + pad0 + pad1) / 4;

                word1 = dataLength & 0x3ff;

                if (HandleDesc != null)
                {
                    word1 |= 1 << 31;
                }

                writer.Write(word0);
                writer.Write(word1);
                writer.Write(handleData);

                ms.Seek(pad0, SeekOrigin.Current);

                if (RawData != null)
                {
                    writer.Write(RawData);
                }

                writer.Write(new byte[pad1]);

                return(ms.ToArray());
            }
        }
Beispiel #3
0
        public byte[] GetBytesTipc()
        {
            Debug.Assert(PtrBuff.Count == 0);

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryWriter writer = new BinaryWriter(ms);

                int word0;
                int word1;

                word0  = (int)Type;
                word0 |= (SendBuff.Count & 0xf) << 20;
                word0 |= (ReceiveBuff.Count & 0xf) << 24;
                word0 |= (ExchangeBuff.Count & 0xf) << 28;

                byte[] handleData = new byte[0];

                if (HandleDesc != null)
                {
                    handleData = HandleDesc.GetBytes();
                }

                int dataLength = RawData?.Length ?? 0;

                dataLength = ((dataLength + 3) & ~3) / 4;

                word1 = (dataLength & 0x3ff);

                if (HandleDesc != null)
                {
                    word1 |= 1 << 31;
                }

                writer.Write(word0);
                writer.Write(word1);
                writer.Write(handleData);

                if (RawData != null)
                {
                    writer.Write(RawData);
                }

                return(ms.ToArray());
            }
        }