GetUInt32() публичный статический Метод

parse UInt32 from bytes
public static GetUInt32 ( byte buffer, int &index, bool isBigEndian ) : uint
buffer byte the buffer stores the value.
index int the index of start to parse
isBigEndian bool order of bytes. If it's big endian, set it to true, else set it to false.
Результат uint
Пример #1
0
        /// <summary>
        /// Decode MSG_GETBLKS message.
        /// </summary>
        /// <param name="data">Data to be decoded.</param>
        /// <param name="index">Started index.</param>
        /// <returns>The MSG_GETBLKS struct.</returns>
        private MSG_GETBLKS DecodeMSG_GETBLKS(byte[] data, ref int index)
        {
            MSG_GETBLKS ret = new MSG_GETBLKS();

            ret.SizeOfSegmentID = MarshalHelper.GetUInt32(data, ref index, false);
            ret.SegmentID       = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfSegmentID);
            ret.ZeroPad         = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfSegmentID % 4);

            if (ret.ZeroPad == null)
            {
                ret.ZeroPad = new byte[0];
            }

            ret.ReqBlockRangeCount = MarshalHelper.GetUInt32(data, ref index, false);
            ret.ReqBlockRanges     = new BLOCK_RANGE[ret.ReqBlockRangeCount];

            for (int i = 0; i < ret.ReqBlockRangeCount; i++)
            {
                ret.ReqBlockRanges[i].Index = MarshalHelper.GetUInt32(data, ref index, false);
                ret.ReqBlockRanges[i].Count = MarshalHelper.GetUInt32(data, ref index, false);
            }

            ret.SizeOfDataForVrfBlock = MarshalHelper.GetUInt32(data, ref index, false);
            ret.DataForVrfBlock       = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfDataForVrfBlock);

            if (ret.DataForVrfBlock == null)
            {
                ret.DataForVrfBlock = new byte[0];
            }

            return(ret);
        }
Пример #2
0
        /// <summary>
        /// Decode message header.
        /// </summary>
        /// <param name="data">Data to be decoded.</param>
        /// <param name="index">Started index.</param>
        /// <returns>The MESSAGE_HEADER struct.</returns>
        private MESSAGE_HEADER DecodeMessageHeader(byte[] data, ref int index)
        {
            MESSAGE_HEADER ret = new MESSAGE_HEADER();

            ret.ProtVer.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
            ret.ProtVer.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
            ret.MsgType      = (MsgType_Values)MarshalHelper.GetUInt32(data, ref index, false);
            ret.MsgSize      = MarshalHelper.GetUInt32(data, ref index, false);
            ret.CryptoAlgoId = (CryptoAlgoId_Values)MarshalHelper.GetUInt32(data, ref index, false);
            return(ret);
        }
Пример #3
0
        /// <summary>
        /// Decode MSG_BLK message.
        /// </summary>
        /// <param name="data">Data to be decoded.</param>
        /// <param name="index">Started index.</param>
        /// <returns>The MSG_BLK struct.</returns>
        private MSG_BLK DecodeMSG_BLK(byte[] data, ref int index)
        {
            MSG_BLK ret = new MSG_BLK();

            ret.SizeOfSegmentId = MarshalHelper.GetUInt32(data, ref index, false);
            ret.SegmentId       = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfSegmentId);
            ret.ZeroPad         = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfSegmentId % 4);
            if (ret.ZeroPad == null)
            {
                ret.ZeroPad = new byte[0];
            }

            ret.BlockIndex     = MarshalHelper.GetUInt32(data, ref index, false);
            ret.NextBlockIndex = MarshalHelper.GetUInt32(data, ref index, false);
            ret.SizeOfBlock    = MarshalHelper.GetUInt32(data, ref index, false);
            ret.Block          = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfBlock);
            if (ret.Block == null)
            {
                ret.Block = new byte[0];
            }

            ret.ZeroPad2 = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfBlock % 4);
            if (ret.ZeroPad2 == null)
            {
                ret.ZeroPad2 = new byte[0];
            }

            ret.SizeOfVrfBlock = MarshalHelper.GetUInt32(data, ref index, false);
            ret.VrfBlock       = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfVrfBlock);
            if (ret.VrfBlock == null)
            {
                ret.VrfBlock = new byte[0];
            }

            ret.ZeroPad3 = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfVrfBlock % 4);
            if (ret.ZeroPad3 == null)
            {
                ret.ZeroPad3 = new byte[0];
            }

            ret.SizeOfIVBlock = MarshalHelper.GetUInt32(data, ref index, false);
            ret.IVBlock       = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfIVBlock);

            if (ret.IVBlock == null)
            {
                ret.IVBlock = new byte[0];
            }

            return(ret);
        }
        /// <summary>
        /// Decode pack.
        /// </summary>
        /// <param name="rawdata">The rawdata.</param>
        /// <returns>The PccrrPacket.</returns>
        public override PccrrPacket Decode(byte[] rawdata)
        {
            if (rawdata == null)
            {
                throw new ArgumentNullException("rawdata");
            }

            if (rawdata.Length == 0)
            {
                throw new ArgumentException("The raw data should not be empty.");
            }

            PccrrNegoResponsePacket packet = new PccrrNegoResponsePacket();

            int messageLength = 0;

            messageLength = rawdata.Length;

            if (messageLength > 0)
            {
                int index = 0;

                byte[] data = rawdata;

                RESPONSE_MESSAGE ret = new RESPONSE_MESSAGE();
                ret.TRANSPORTRESPONSEHEADER.Size = MarshalHelper.GetUInt32(data, ref index, false);

                MESSAGE_HEADER ret1 = new MESSAGE_HEADER();
                ret1.ProtVer.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret1.ProtVer.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret1.MsgType      = (MsgType_Values)MarshalHelper.GetUInt32(data, ref index, false);
                ret1.MsgSize      = MarshalHelper.GetUInt32(data, ref index, false);
                ret1.CryptoAlgoId = (CryptoAlgoId_Values)MarshalHelper.GetUInt32(data, ref index, false);

                MSG_NEGO_RESP ret2 = new MSG_NEGO_RESP();
                ret2.MinSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret2.MinSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret2.MaxSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
                ret2.MaxSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);

                packet.TransportResponseHeader = ret.TRANSPORTRESPONSEHEADER;
                packet.MsgNegoResp             = ret2;
                packet.MessageHeader           = ret1;
            }

            return(packet);
        }
Пример #5
0
        /// <summary>
        /// Decode MSG_BLKLIST message.
        /// </summary>
        /// <param name="data">The data to be decoded.</param>
        /// <param name="index">Started index.</param>
        /// <returns>The MSG_BLKLIST struct.</returns>
        private MSG_BLKLIST DecodeMSG_BLKLIST(byte[] data, ref int index)
        {
            MSG_BLKLIST ret = new MSG_BLKLIST();

            ret.SizeOfSegmentId = MarshalHelper.GetUInt32(data, ref index, false);
            ret.SegmentId       = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfSegmentId);
            ret.ZeroPad         = MarshalHelper.GetBytes(data, ref index, (int)ret.SizeOfSegmentId % 4);
            if (ret.ZeroPad == null)
            {
                ret.ZeroPad = new byte[0];
            }

            ret.BlockRangeCount = MarshalHelper.GetUInt32(data, ref index, false);
            ret.BlockRanges     = new BLOCK_RANGE[ret.BlockRangeCount];
            for (int i = 0; i < ret.BlockRangeCount; i++)
            {
                ret.BlockRanges[i].Index = MarshalHelper.GetUInt32(data, ref index, false);
                ret.BlockRanges[i].Count = MarshalHelper.GetUInt32(data, ref index, false);
            }

            ret.NextBlockIndex = MarshalHelper.GetUInt32(data, ref index, false);
            return(ret);
        }
Пример #6
0
        /// <summary>
        /// Decode response message.
        /// </summary>
        /// <param name="rawdata">The raw data.</param>
        /// <returns>The PccrrPacket.</returns>
        public PccrrPacket DecodeResponseMessage(byte[] rawdata)
        {
            if (rawdata == null)
            {
                throw new ArgumentNullException("rawdata");
            }

            if (rawdata.Length == 0)
            {
                throw new ArgumentException("The raw data should not be empty.");
            }

            int messageLength = 0;

            messageLength = rawdata.Length;

            PccrrPacket packet = null;

            if (messageLength > 0)
            {
                int index = 0;

                RESPONSE_MESSAGE ret = new RESPONSE_MESSAGE();
                ret.TRANSPORTRESPONSEHEADER.Size = MarshalHelper.GetUInt32(rawdata, ref index, false);
                ret.MESSAGEHEADER = this.DecodeMessageHeader(rawdata, ref index);

                switch (ret.MESSAGEHEADER.MsgType)
                {
                case MsgType_Values.MSG_BLKLIST:
                    PccrrBLKLISTResponsePacket pccrrBLKLISTResponsePacket = new PccrrBLKLISTResponsePacket();

                    MSG_BLKLIST msgBLKLIST = this.DecodeMSG_BLKLIST(rawdata, ref index);
                    pccrrBLKLISTResponsePacket.TransportResponseHeader = ret.TRANSPORTRESPONSEHEADER;
                    pccrrBLKLISTResponsePacket.MsgBLKLIST    = msgBLKLIST;
                    pccrrBLKLISTResponsePacket.MessageHeader = ret.MESSAGEHEADER;
                    packet = pccrrBLKLISTResponsePacket;
                    break;

                case MsgType_Values.MSG_BLK:
                    PccrrBLKResponsePacket pccrrBLKResponsePacket = new PccrrBLKResponsePacket();

                    MSG_BLK msgBLK = this.DecodeMSG_BLK(rawdata, ref index);
                    pccrrBLKResponsePacket.TransportResponseHeader = ret.TRANSPORTRESPONSEHEADER;
                    pccrrBLKResponsePacket.MsgBLK        = msgBLK;
                    pccrrBLKResponsePacket.MessageHeader = ret.MESSAGEHEADER;
                    packet = pccrrBLKResponsePacket;
                    break;

                case MsgType_Values.MSG_NEGO_RESP:
                    PccrrNegoResponsePacket pccrrNegoResponsePacket = new PccrrNegoResponsePacket();

                    MSG_NEGO_RESP msgNEGORESP = this.DecodeMSG_NEGO_RESP(rawdata, ref index);
                    pccrrNegoResponsePacket.TransportResponseHeader = ret.TRANSPORTRESPONSEHEADER;
                    pccrrNegoResponsePacket.MsgNegoResp             = msgNEGORESP;
                    pccrrNegoResponsePacket.MessageHeader           = ret.MESSAGEHEADER;
                    packet = pccrrNegoResponsePacket;
                    break;

                case MsgType_Values.MSG_SEGLIST:
                    PccrrSegListResponsePacket pccrrSegListResponsePacket = new PccrrSegListResponsePacket();
                    pccrrSegListResponsePacket.MsgSegList = TypeMarshal.ToStruct <MSG_SEGLIST>(rawdata, ref index);
                    pccrrSegListResponsePacket.TransportResponseHeader = ret.TRANSPORTRESPONSEHEADER;
                    pccrrSegListResponsePacket.MessageHeader           = ret.MESSAGEHEADER;
                    packet = pccrrSegListResponsePacket;
                    break;
                }
            }

            return(packet);
        }