当前位置: 首页>>代码示例>>C#>>正文


C# MessageReader.ReadByte方法代码示例

本文整理汇总了C#中MessageReader.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# MessageReader.ReadByte方法的具体用法?C# MessageReader.ReadByte怎么用?C# MessageReader.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MessageReader的用法示例。


在下文中一共展示了MessageReader.ReadByte方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadCommand

        /// <summary>
        /// Reads the <see cref="UpgradeBuildingCommand"/> from the specified <see cref="MessageReader"/>.
        /// </summary>
        /// <param name="reader">
        /// <see cref="MessageReader"/> that will be used to read the <see cref="UpgradeBuildingCommand"/>.
        /// </param>
        public override void ReadCommand(MessageReader reader)
        {
            var gameID = reader.ReadInt32();
            if (!Building.ValidGameID(gameID))
                throw new InvalidCommandException("Unexpected data ID: " + gameID, this);

            BuildingGameIndex = Building.GameIDToIndex(gameID);

            Unknown1 = reader.ReadByte();
            Unknown2 = reader.ReadInt32();
        }
开发者ID:circa94,项目名称:CoCSharp,代码行数:17,代码来源:UpgradeBuildingCommand.cs

示例2: ReadMessageReal2

        IEnumerator<MsgState> ReadMessageReal2()
        {
            byte[] body = null;
            mmneeded = 16;
            while (mmpos < 16)
                yield return MsgState.Wait16;

            EndianFlag endianness = (EndianFlag)mmbuf[0];
            MessageReader reader = new MessageReader (endianness, mmbuf);

            //discard the endian byte as we've already read it
            reader.ReadByte ();

            //discard message type and flags, which we don't care about here
            reader.ReadByte ();
            reader.ReadByte ();

            byte version = reader.ReadByte ();

            if (version < Protocol.MinVersion || version > Protocol.MaxVersion)
                throw new NotSupportedException ("Protocol version '" + version.ToString () + "' is not supported");

            if (Protocol.Verbose)
                if (version != Protocol.Version)
                    Console.Error.WriteLine ("Warning: Protocol version '" + version.ToString () + "' is not explicitly supported but may be compatible");

            uint bodyLength = reader.ReadUInt32 ();
            //discard serial
            reader.ReadUInt32 ();
            uint headerLength = reader.ReadUInt32 ();

            //this check may become relevant if a future version of the protocol allows larger messages
            /*
            if (bodyLength > Int32.MaxValue || headerLength > Int32.MaxValue)
                throw new NotImplementedException ("Long messages are not yet supported");
            */

            int bodyLen = (int)bodyLength;
            int toRead = (int)headerLength;

            //we fixup to include the padding following the header
            toRead = Protocol.Padded (toRead, 8);

            long msgLength = toRead + bodyLen;
            if (msgLength > Protocol.MaxMessageLength)
                throw new Exception ("Message length " + msgLength + " exceeds maximum allowed " + Protocol.MaxMessageLength + " bytes");

            byte[] header = new byte[16 + toRead];
            Array.Copy (mmbuf, header, 16);

            mmneeded = toRead;
            while (mmpos < 16 + toRead)
                yield return MsgState.WaitHeader;

            Array.Copy (mmbuf, 16, header, 16, toRead);

            //if (read != toRead)
            //	throw new Exception ("Message header length mismatch: " + read + " of expected " + toRead);

            mmneeded = bodyLen;
            while (mmpos < 16 + toRead + bodyLen)
                yield return MsgState.WaitBody;

            //read the body
            if (bodyLen != 0) {
                body = new byte[bodyLen];

                Array.Copy (mmbuf, 16 + toRead, body, 0, bodyLen);

                //if (read != bodyLen)
                //	throw new Exception ("Message body length mismatch: " + read + " of expected " + bodyLen);
            }

            Message msg = new Message ();
            msg.Connection = this.Connection;
            msg.Body = body;
            msg.SetHeaderData (header);

            Inbound.Enqueue (msg);

            mmneeded = 16;

            yield return MsgState.Done;
        }
开发者ID:hyperair,项目名称:dbus-sharp,代码行数:84,代码来源:Transport.cs

示例3: ReadMessageReal

        Message ReadMessageReal()
        {
            byte[] header;
            byte[] body = null;

            int read;

            //16 bytes is the size of the fixed part of the header
            byte[] hbuf = new byte[16];

            read = Read (hbuf, 0, 16);

            if (read == 0)
                return null;

            if (read != 16)
                throw new Exception ("Header read length mismatch: " + read + " of expected " + "16");

            EndianFlag endianness = (EndianFlag)hbuf[0];
            MessageReader reader = new MessageReader (endianness, hbuf);

            //discard the endian byte as we've already read it
            reader.ReadByte ();

            //discard message type and flags, which we don't care about here
            reader.ReadByte ();
            reader.ReadByte ();

            byte version = reader.ReadByte ();

            if (version < Protocol.MinVersion || version > Protocol.MaxVersion)
                throw new NotSupportedException ("Protocol version '" + version.ToString () + "' is not supported");

            if (Protocol.Verbose)
                if (version != Protocol.Version)
                    Console.Error.WriteLine ("Warning: Protocol version '" + version.ToString () + "' is not explicitly supported but may be compatible");

            uint bodyLength = reader.ReadUInt32 ();
            //discard serial
            reader.ReadUInt32 ();
            uint headerLength = reader.ReadUInt32 ();

            //this check may become relevant if a future version of the protocol allows larger messages
            /*
            if (bodyLength > Int32.MaxValue || headerLength > Int32.MaxValue)
                throw new NotImplementedException ("Long messages are not yet supported");
            */

            int bodyLen = (int)bodyLength;
            int toRead = (int)headerLength;

            //we fixup to include the padding following the header
            toRead = Protocol.Padded (toRead, 8);

            long msgLength = toRead + bodyLen;
            if (msgLength > Protocol.MaxMessageLength)
                throw new Exception ("Message length " + msgLength + " exceeds maximum allowed " + Protocol.MaxMessageLength + " bytes");

            header = new byte[16 + toRead];
            Array.Copy (hbuf, header, 16);

            read = Read (header, 16, toRead);

            if (read != toRead)
                throw new Exception ("Message header length mismatch: " + read + " of expected " + toRead);

            //read the body
            if (bodyLen != 0) {
                body = new byte[bodyLen];

                read = Read (body, 0, bodyLen);

                if (read != bodyLen)
                    throw new Exception ("Message body length mismatch: " + read + " of expected " + bodyLen);
            }

            Message msg = new Message ();
            msg.Connection = this.Connection;
            msg.Body = body;
            msg.SetHeaderData (header);

            return msg;
        }
开发者ID:hyperair,项目名称:dbus-sharp,代码行数:83,代码来源:Transport.cs

示例4: ReadMessage

        /// <summary>
        /// Reads the <see cref="LoginRequestMessage"/> from the specified <see cref="MessageReader"/>.
        /// </summary>
        /// <param name="reader">
        /// <see cref="MessageReader"/> that will be used to read the <see cref="LoginRequestMessage"/>.
        /// </param>
        public override void ReadMessage(MessageReader reader)
        {
            SessionKey = reader.ReadBytes(CoCKeyPair.NonceLength);
            Nonce = reader.ReadBytes(CoCKeyPair.NonceLength);

            UserID = reader.ReadInt64();
            UserToken = reader.ReadString();
            ClientMajorVersion = reader.ReadInt32();
            ClientContentVersion = reader.ReadInt32();
            ClientMinorVersion = reader.ReadInt32();
            FingerprintHash = reader.ReadString();

            Unknown1 = reader.ReadString();

            OpenUDID = reader.ReadString();
            MacAddress = reader.ReadString();
            DeviceModel = reader.ReadString();
            LocaleKey = reader.ReadInt32();
            Language = reader.ReadString();
            AdvertisingGUID = reader.ReadString();
            OSVersion = reader.ReadString();

            Unknown2 = reader.ReadByte();
            Unknown3 = reader.ReadString();

            AndroidDeviceID = reader.ReadString();
            FacebookDistributionID = reader.ReadString();
            IsAdvertisingTrackingEnabled = reader.ReadBoolean();
            VendorGUID = reader.ReadString();
            Seed = reader.ReadInt32();
        }
开发者ID:circa94,项目名称:CoCSharp,代码行数:37,代码来源:LoginRequestMessage.cs

示例5: ReadMessageReal

        Message ReadMessageReal()
        {
            byte[] header = null;
            byte[] body = null;

            int read;

            //16 bytes is the size of the fixed part of the header
            if (readBuffer == null)
                readBuffer = new byte[16];
            byte[] hbuf = readBuffer;

            read = Read (hbuf, 0, 16);

            if (read == 0)
                return null;

            if (read != 16)
                throw new Exception ("Header read length mismatch: " + read + " of expected " + "16");

            EndianFlag endianness = (EndianFlag)hbuf[0];
            MessageReader reader = new MessageReader (endianness, hbuf);

            //discard endian byte, message type and flags, which we don't care about here
            reader.Seek (3);

            byte version = reader.ReadByte ();

            if (version < ProtocolInformation.MinVersion || version > ProtocolInformation.MaxVersion)
                throw new NotSupportedException ("Protocol version '" + version.ToString () + "' is not supported");

            if (ProtocolInformation.Verbose)
                if (version != ProtocolInformation.Version)
                    Console.Error.WriteLine ("Warning: Protocol version '" + version.ToString () + "' is not explicitly supported but may be compatible");

            uint bodyLength = reader.ReadUInt32 ();
            //discard serial
            reader.ReadUInt32 ();
            uint headerLength = reader.ReadUInt32 ();

            int bodyLen = (int)bodyLength;
            int toRead = (int)headerLength;

            //we fixup to include the padding following the header
            toRead = ProtocolInformation.Padded (toRead, 8);

            long msgLength = toRead + bodyLen;
            if (msgLength > ProtocolInformation.MaxMessageLength)
                throw new Exception ("Message length " + msgLength + " exceeds maximum allowed " + ProtocolInformation.MaxMessageLength + " bytes");

            header = new byte[16 + toRead];
            Array.Copy (hbuf, header, 16);

            read = Read (header, 16, toRead);

            if (read != toRead)
                throw new Exception ("Message header length mismatch: " + read + " of expected " + toRead);

            //read the body
            if (bodyLen != 0) {
                body = new byte[bodyLen];

                read = Read (body, 0, bodyLen);

                if (read != bodyLen)
                    throw new Exception ("Message body length mismatch: " + read + " of expected " + bodyLen);
            }

            Message msg = Message.FromReceivedBytes (Connection, header, body);

            return msg;
        }
开发者ID:acklinr,项目名称:dbus-sharp,代码行数:72,代码来源:Transport.cs


注:本文中的MessageReader.ReadByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。