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


C# IoBuffer.Rewind方法代码示例

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


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

示例1: ComputeChecksum

 private byte ComputeChecksum(IoBuffer buffer)
 {
     buffer.Rewind();
     byte checksum = 0;
     for (int i = 0; i < Length - 1; i++) checksum += buffer.Get();
     return checksum;
 }
开发者ID:zesus19,项目名称:c5.v1,代码行数:7,代码来源:AbstractPacket.cs

示例2: Decodable

 public MessageDecoderResult Decodable(IoSession session, IoBuffer input)
 {
     if (input.Remaining < MIN_PACKET_LENGTH)
         return MessageDecoderResult.NeedData;
     var symbol = input.GetArray(2);
     if (DataPacket.True(symbol))
     {
         input.Skip(1);
         var len = input.Get();
         input.Rewind();
         if (len > input.Remaining) return MessageDecoderResult.NeedData;
     }
     else if (!CtlPacket.True(symbol)) return MessageDecoderResult.NotOK;
     return MessageDecoderResult.OK;
 }
开发者ID:zesus19,项目名称:c5.v1,代码行数:15,代码来源:PacketDecoder.cs

示例3: ManipulateIoBuffer

        private void ManipulateIoBuffer(IoSession session, IoBuffer buffer)
        {
            if ((buffer.Remaining > 0) && (_removeByteProbability > _rng.Next(1000)))
            {
                if (log.IsInfoEnabled)
                    log.Info(buffer.GetHexDump());

                // where to remove bytes ?
                int pos = _rng.Next(buffer.Remaining);
                // how many byte to remove ?
                int count = _rng.Next(buffer.Remaining - pos) + 1;
                if (count == buffer.Remaining)
                    count = buffer.Remaining - 1;

                IoBuffer newBuff = IoBuffer.Allocate(buffer.Remaining - count);
                for (int i = 0; i < pos; i++)
                    newBuff.Put(buffer.Get());

                buffer.Skip(count); // hole
                while (newBuff.Remaining > 0)
                    newBuff.Put(buffer.Get());
                newBuff.Flip();
                // copy the new buffer in the old one
                buffer.Rewind();
                buffer.Put(newBuff);
                buffer.Flip();

                if (log.IsInfoEnabled)
                {
                    log.Info("Removed " + count + " bytes at position " + pos + ".");
                    log.Info(buffer.GetHexDump());
                }
            }
            if ((buffer.Remaining > 0) && (_changeByteProbability > _rng.Next(1000)))
            {
                if (log.IsInfoEnabled)
                    log.Info(buffer.GetHexDump());

                // how many byte to change ?
                int count = _rng.Next(buffer.Remaining - 1) + 1;

                byte[] values = new byte[count];
                _rng.NextBytes(values);
                for (int i = 0; i < values.Length; i++)
                {
                    int pos = _rng.Next(buffer.Remaining);
                    buffer.Put(pos, values[i]);
                }

                if (log.IsInfoEnabled)
                {
                    log.Info("Modified " + count + " bytes.");
                    log.Info(buffer.GetHexDump());
                }
            }
        }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:56,代码来源:ErrorGeneratingFilter.cs


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