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


C# PacketReader.TryReadUInt16方法代码示例

本文整理汇总了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);
        }
开发者ID:shoftee,项目名称:OpenStory,代码行数:11,代码来源:SafePacketReadingFixture.cs

示例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;
        }
开发者ID:shoftee,项目名称:OpenStory,代码行数:33,代码来源:ServerSession.cs


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