A BLOCK_RANGE is an array of two integers that defines a consecutive array of blocks.
        /// <summary>
        /// Convert BLOCK_RANGE parameters to Adapter parameters.
        /// </summary>
        /// <param name="blockRanges">The array of BLOCK_RANGE.</param>
        /// <returns>The array of BLOCKRANGE.</returns>
        public static BLOCKRANGE[] ConvertFromStackBLOCKRANGEArray(BLOCK_RANGE[] blockRanges)
        {
            BLOCKRANGE[] blockRang = new BLOCKRANGE[blockRanges.Length];

            for (int i = 0; i < blockRanges.Length; i++)
            {
                blockRang[i].Index = blockRanges[i].Index;
                blockRang[i].Count = blockRanges[i].Count;
            }

            return(blockRang);
        }
        /// <summary>
        /// Convert BLOCKRANGE parameters to Stack parameters.
        /// </summary>
        /// <param name="blockRanges">The array of BLOCKRANGE.</param>
        /// <returns>The array of BLOCK_RANGE.</returns>
        public static BLOCK_RANGE[] ConvertToStackBLOCKRANGEArray(BLOCKRANGE[] blockRanges)
        {
            BLOCK_RANGE[] blockRang = new BLOCK_RANGE[blockRanges.Length];

            for (int i = 0; i < blockRanges.Length; i++)
            {
                blockRang[i].Index = blockRanges[i].Index;
                blockRang[i].Count = blockRanges[i].Count;
            }

            return blockRang;
        }
        /// <summary>
        /// Send message MSG_GETBLKS
        /// </summary>
        /// <param name="sid">segment id.</param>
        /// <param name="blockRang">Block ranges client wants to get</param>
        /// <param name="isVersionSupported">The version in this message is supported in server.</param>
        public void SendMsgGetBlks(byte[] sid, BLOCKRANGE[] blockRang, bool isVersionSupported)
        {
            PccrrGETBLKSRequestPacket packet;

            BLOCK_RANGE[] blockRanges = Helper.ConvertToStackBLOCKRANGEArray(blockRang);

            if (!isVersionSupported)
            {
                packet = this.pccrrStack.CreateMsgGetBlksRequest(sid, this.cryptoAlgo, MsgType_Values.MSG_GETBLKS, this.protoErrorVer);
            }
            else
            {
                packet = this.pccrrStack.CreateMsgGetBlksRequest(sid, this.cryptoAlgo, MsgType_Values.MSG_GETBLKS, this.protoVer);
            }

            for (int i = 0; i < blockRanges.Length; i++)
            {
                if (blockRanges.Length == 1)
                {
                    packet.MsgGetBLKS.ReqBlockRanges[i].Index = blockRanges[i].Index;
                    packet.MsgGetBLKS.ReqBlockRanges[i].Count = blockRanges[i].Count;
                }
                else
                {
                    MSG_GETBLKS msgGETBLKS = packet.MsgGetBLKS;
                    msgGETBLKS.ReqBlockRanges = new BLOCK_RANGE[blockRanges.Length];
                    msgGETBLKS.ReqBlockRangeCount = (uint)blockRanges.Length;
                    packet.MsgGetBLKS = msgGETBLKS;

                    packet.MsgGetBLKS.ReqBlockRanges[i].Index = blockRanges[i].Index;
                    packet.MsgGetBLKS.ReqBlockRanges[i].Count = blockRanges[i].Count;
                }
            }

            this.pccrrStack.SendPacket(packet, new TimeSpan(0, 0, this.timeout));

            PccrrPacket respMSG = this.pccrrStack.ExpectPacket();

            if (!isVersionSupported)
            {
                PccrrNegoResponsePacket pccrrNegoResponsePacket = respMSG as PccrrNegoResponsePacket;

                if (pccrrNegoResponsePacket != null)
                {
                    this.ReceiveMsgNegoResp();
                }
            }
            else
            {
                PccrrBLKResponsePacket pccrrBLKResponsePacket = respMSG as PccrrBLKResponsePacket;

                MSG_BLK msgBLK = pccrrBLKResponsePacket.MsgBLK;
                MESSAGE_HEADER messageHeader = pccrrBLKResponsePacket.MessageHeader;
                TRANSPORT_RESPONSE_HEADER transportRespH = pccrrBLKResponsePacket.TransportResponseHeader;
                RESPONSE_MESSAGE respMessage = new RESPONSE_MESSAGE();
                respMessage.MESSAGEBODY = msgBLK;
                respMessage.MESSAGEHEADER = messageHeader;
                respMessage.TRANSPORTRESPONSEHEADER = transportRespH;

                this.VerifyMsgBlk(msgBLK);
                PccrrBothRoleCaptureCode.CaptureSegmentIdRequirements(msgBLK.SegmentId);
                this.VerifyResponseMessage(respMessage);

                bool isSizeOfBlockZero = false;

                if (msgBLK.SizeOfBlock == 0)
                {
                    isSizeOfBlockZero = true;
                }
                else
                {
                    isSizeOfBlockZero = false;
                }

                bool isBlockEmpty = false;

                if (msgBLK.Block.Length == 0)
                {
                    isBlockEmpty = true;
                }
                else
                {
                    isBlockEmpty = false;
                }

                CryptoAlgoIdValues crypAlgoId = Helper.ConvertFromStackCryptoAlgoIdValues(pccrrBLKResponsePacket.MessageHeader.CryptoAlgoId);
                this.ReceiveMsgBlk(msgBLK.BlockIndex, msgBLK.NextBlockIndex, isSizeOfBlockZero, isBlockEmpty, crypAlgoId);
            }
        }
        /// <summary>
        /// Send message MSG_GETBLKLIST.
        /// </summary>
        /// <param name="sid">segment id.</param>
        /// <param name="blockRang">Block ranges client wants to get.</param>
        /// <param name="isVersionSupported">The version in message is supported by server or not.</param>
        public void SendMsgGetBlkList(byte[] sid, BLOCKRANGE[] blockRang, bool isVersionSupported)
        {
            PccrrGETBLKLISTRequestPacket packet;

            BLOCK_RANGE[] blockRanges = Helper.ConvertToStackBLOCKRANGEArray(blockRang);

            if (!isVersionSupported)
            {
                packet = this.pccrrStack.CreateMsgGetBlkListRequest(sid, blockRanges, this.cryptoAlgo, MsgType_Values.MSG_GETBLKLIST, this.protoErrorVer);
            }
            else
            {
                packet = this.pccrrStack.CreateMsgGetBlkListRequest(sid, blockRanges, this.cryptoAlgo, MsgType_Values.MSG_GETBLKLIST, this.protoVer);
            }

            this.pccrrStack.SendPacket(packet, new TimeSpan(0, 0, this.timeout));

            PccrrPacket respMSG = this.pccrrStack.ExpectPacket();

            if (!isVersionSupported)
            {
                PccrrNegoResponsePacket pccrrNegoResponsePacket = respMSG as PccrrNegoResponsePacket;

                if (pccrrNegoResponsePacket != null)
                {
                    this.ReceiveMsgNegoResp();
                }
            }
            else
            {
                PccrrBLKLISTResponsePacket pccrrBLKLISTResponsePacket = respMSG as PccrrBLKLISTResponsePacket;

                MSG_BLKLIST msgBLKLIST = pccrrBLKLISTResponsePacket.MsgBLKLIST;
                MESSAGE_HEADER messageHeader = pccrrBLKLISTResponsePacket.MessageHeader;
                TRANSPORT_RESPONSE_HEADER transportRespH = pccrrBLKLISTResponsePacket.TransportResponseHeader;
                RESPONSE_MESSAGE respMessage = new RESPONSE_MESSAGE();
                respMessage.MESSAGEBODY = msgBLKLIST;
                respMessage.MESSAGEHEADER = messageHeader;
                respMessage.TRANSPORTRESPONSEHEADER = transportRespH;

                if (msgBLKLIST.BlockRanges.Length != 0)
                {
                    BLOCK_RANGE blockRange = pccrrBLKLISTResponsePacket.MsgBLKLIST.BlockRanges[0];
                    PccrrBothRoleCaptureCode.CaptureBlockRangeRequirements(blockRange);
                }

                this.VerifyMsgBlkList(msgBLKLIST);
                PccrrBothRoleCaptureCode.CaptureCommonDataTypesRequirements(msgBLKLIST);
                this.VerifyResponseMessage(respMessage);

                BLOCKRANGE[] blkRanges = Helper.ConvertFromStackBLOCKRANGEArray(msgBLKLIST.BlockRanges);
                this.ReceiveMsgBlkList(msgBLKLIST.BlockRangeCount, blkRanges, msgBLKLIST.NextBlockIndex);
            }
        }