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

parse UInt16 from bytes
public static GetUInt16 ( byte buffer, int &index, bool isBigEndian ) : ushort
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.
Результат ushort
Пример #1
0
        /// <summary>
        /// Decode MSG_NEGO_RESP message.
        /// </summary>
        /// <param name="data">Data to be decoded.</param>
        /// <param name="index">Started index.</param>
        /// <returns>The MSG_NEGO_RESP struct.</returns>
        private MSG_NEGO_RESP DecodeMSG_NEGO_RESP(byte[] data, ref int index)
        {
            MSG_NEGO_RESP ret = new MSG_NEGO_RESP();

            ret.MinSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
            ret.MinSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
            ret.MaxSupporteProtocolVersion.MinorVersion = MarshalHelper.GetUInt16(data, ref index, false);
            ret.MaxSupporteProtocolVersion.MajorVersion = MarshalHelper.GetUInt16(data, ref index, false);
            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);
        }
        /// <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);
        }