本文整理汇总了C#中PacketReader.TryReadUInt16方法的典型用法代码示例。如果您正苦于以下问题:C# PacketReader.TryReadUInt16方法的具体用法?C# PacketReader.TryReadUInt16怎么用?C# PacketReader.TryReadUInt16使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketReader
的用法示例。
在下文中一共展示了PacketReader.TryReadUInt16方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryReadUInt16_Should_Read_In_LittleEndian
public void TryReadUInt16_Should_Read_In_LittleEndian()
{
var buffer = new byte[] { 15, 200, };
var reader = new PacketReader(buffer);
int expected = (buffer[0]) + (buffer[1] << 8);
ushort actual;
reader.TryReadUInt16(out actual).Should().BeTrue();
actual.Should().Be((ushort)expected);
}
示例2: TryPushAsync
/// <summary>
/// Raises the <see cref="PacketProcessing"/> event for the specified packet data, if possible asynchronously.
/// </summary>
/// <param name="packet">The packet data to include for the raised event.</param>
/// <returns>
/// <see langword="false"/> if the data was handled synchronously and another call can be made; if there was a fatal error or the asynchronous call was successfully made, <see langword="false"/>.</returns>
private bool TryPushAsync(byte[] packet)
{
var reader = new PacketReader(packet);
ushort packetCode;
if (!reader.TryReadUInt16(out packetCode))
{
this.Close(@"Could not read packet code.");
// Bad packet. We kill the session and stop pushing.
return true;
}
// If this returns null, it's an unknown code and has no label.
string label;
this.packetCodeTable.TryGetIncomingLabel(packetCode, out label);
// Invoke event asynchronously.
var args = new PacketProcessingEventArgs(packetCode, label, reader);
var handler = this.PacketProcessing;
AsyncCallback callback = this.ContinuePushAsynchronous;
var asyncResult = handler.BeginInvoke(this, args, callback, null);
// If we completed synchronously, we'll take another one right away.
// Otherwise, leave it to the asynchronous continuation.
return asyncResult.CompletedSynchronously;
}