Microsoft.Protocols.TestTools.StackSdk.BranchCache.Pccrr.PccrrBLKLISTResponsePacket.Encode C# (CSharp) Method

Encode() public method

Encode pack.
public Encode ( ) : byte[]
return byte[]
        public override byte[] Encode()
        {
            RESPONSE_MESSAGE responseMessage = new RESPONSE_MESSAGE();
            responseMessage.MESSAGEBODY = this.msgBLKLIST;
            responseMessage.MESSAGEHEADER = this.MessageHeader;
            byte[] ret;

            List<byte> temp = new List<byte>();
            byte[] tempPayload;

            List<byte> listRet = new List<byte>();
            listRet.AddRange(MarshalHelper.GetBytes(((MSG_BLKLIST)responseMessage.MESSAGEBODY).SizeOfSegmentId, false));
            listRet.AddRange(((MSG_BLKLIST)responseMessage.MESSAGEBODY).SegmentId);
            while (listRet.Count % 4 != 0)
            {
                listRet.Add(byte.MinValue);
            }

            listRet.AddRange(MarshalHelper.GetBytes(((MSG_BLKLIST)responseMessage.MESSAGEBODY).BlockRangeCount, false));
            for (int i = 0; i < ((MSG_BLKLIST)responseMessage.MESSAGEBODY).BlockRangeCount; i++)
            {
                listRet.AddRange(MarshalHelper.GetBytes(((MSG_BLKLIST)responseMessage.MESSAGEBODY).BlockRanges[i].Index, false));
                listRet.AddRange(MarshalHelper.GetBytes(((MSG_BLKLIST)responseMessage.MESSAGEBODY).BlockRanges[i].Count, false));
            }

            listRet.AddRange(MarshalHelper.GetBytes(((MSG_BLKLIST)responseMessage.MESSAGEBODY).NextBlockIndex, false));
            tempPayload = listRet.ToArray();

            responseMessage.MESSAGEHEADER.MsgSize = (uint)tempPayload.Length + 16;

            List<byte> listRet1 = new List<byte>();
            listRet1.AddRange(MarshalHelper.GetBytes((ushort)responseMessage.MESSAGEHEADER.ProtVer.MinorVersion, false));
            listRet1.AddRange(MarshalHelper.GetBytes((ushort)responseMessage.MESSAGEHEADER.ProtVer.MajorVersion, false));
            listRet1.AddRange(MarshalHelper.GetBytes((uint)responseMessage.MESSAGEHEADER.MsgType, false));
            listRet1.AddRange(MarshalHelper.GetBytes(responseMessage.MESSAGEHEADER.MsgSize, false));
            listRet1.AddRange(MarshalHelper.GetBytes((uint)responseMessage.MESSAGEHEADER.CryptoAlgoId, false));

            temp.AddRange(listRet1.ToArray());
            temp.AddRange(tempPayload);
            temp.InsertRange(0, MarshalHelper.GetBytes((uint)temp.Count, false));
            ret = (byte[])temp.ToArray();

            return ret;
        }