本文整理汇总了C#中MessageReader.ReadUInt32方法的典型用法代码示例。如果您正苦于以下问题:C# MessageReader.ReadUInt32方法的具体用法?C# MessageReader.ReadUInt32怎么用?C# MessageReader.ReadUInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageReader
的用法示例。
在下文中一共展示了MessageReader.ReadUInt32方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例4: 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;
}