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


C# MessageReader.Seek方法代码示例

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


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

示例1: FromBytes

		public static Header FromBytes (byte[] data)
		{
			Header header = new Header ();
			EndianFlag endianness = (EndianFlag)data[0];

			header.Endianness = endianness;
			header.MessageType = (MessageType)data[1];
			header.Flags = (HeaderFlag)data[2];
			header.MajorVersion = data[3];

			var reader = new MessageReader (endianness, data);
			reader.Seek (4);
			header.Length = reader.ReadUInt32 ();
			header.Serial = reader.ReadUInt32 ();

			FieldCodeEntry[] fields = reader.ReadArray<FieldCodeEntry> ();
			foreach (var f in fields) {
				header[(FieldCode)f.Code] = f.Value;
			}

			return header;
		}
开发者ID:brookpatten,项目名称:dbus-sharp,代码行数:22,代码来源:Header.cs

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