本文整理汇总了C#中Mina.Core.Buffer.IoBuffer.Slice方法的典型用法代码示例。如果您正苦于以下问题:C# IoBuffer.Slice方法的具体用法?C# IoBuffer.Slice怎么用?C# IoBuffer.Slice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mina.Core.Buffer.IoBuffer
的用法示例。
在下文中一共展示了IoBuffer.Slice方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decode
public IDecodingState Decode(IoBuffer input, IProtocolDecoderOutput output)
{
if (_buffer == null)
{
if (input.Remaining >= _length)
{
Int32 limit = input.Limit;
input.Limit = input.Position + _length;
IoBuffer product = input.Slice();
input.Position = input.Position + _length;
input.Limit = limit;
return FinishDecode(product, output);
}
_buffer = IoBuffer.Allocate(_length);
_buffer.Put(input);
return this;
}
if (input.Remaining >= _length - _buffer.Position)
{
Int32 limit = input.Limit;
input.Limit = input.Position + _length - _buffer.Position;
_buffer.Put(input);
input.Limit = limit;
IoBuffer product = _buffer;
_buffer = null;
return FinishDecode(product.Flip(), output);
}
_buffer.Put(input);
return this;
}
示例2: Decode
public IDecodingState Decode(IoBuffer input, IProtocolDecoderOutput output)
{
Int32 terminatorPos = input.IndexOf(_terminator);
if (terminatorPos >= 0)
{
Int32 limit = input.Limit;
IoBuffer product;
if (input.Position < terminatorPos)
{
input.Limit = terminatorPos;
if (_buffer == null)
{
product = input.Slice();
}
else
{
_buffer.Put(input);
product = _buffer.Flip();
_buffer = null;
}
input.Limit = limit;
}
else
{
// When input contained only terminator rather than actual data...
if (_buffer == null)
{
product = IoBuffer.Allocate(0);
}
else
{
product = _buffer.Flip();
_buffer = null;
}
}
input.Position = terminatorPos + 1;
return FinishDecode(product, output);
}
if (_buffer == null)
{
_buffer = IoBuffer.Allocate(input.Remaining);
_buffer.AutoExpand = true;
}
_buffer.Put(input);
return this;
}
示例3: Decode
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
{
int limit = input.Limit;
int position = input.Position;
var len = input.GetInt32();
var version = input.Get();
input.Position = position;
input.Limit = input.Position + len;
var buffer = input.Slice();
input.Position = input.Limit;
input.Limit = limit;
var message = DoDecode(version.ToEnum<MessageVersion>(), buffer);
if (message != null)
output.Write(message);
return MessageDecoderResult.OK;
}
示例4: Decode
public IDecodingState Decode(IoBuffer input, IProtocolDecoderOutput output)
{
Int32 beginPos = input.Position;
Int32 limit = input.Limit;
Int32 terminatorPos = -1;
for (Int32 i = beginPos; i < limit; i++)
{
Byte b = input.Get(i);
if (b == CR)
{
_lastIsCR = true;
}
else
{
if (b == LF && _lastIsCR)
{
terminatorPos = i;
break;
}
_lastIsCR = false;
}
}
if (terminatorPos >= 0)
{
IoBuffer product;
Int32 endPos = terminatorPos - 1;
if (beginPos < endPos)
{
input.Limit = endPos;
if (_buffer == null)
{
product = input.Slice();
}
else
{
_buffer.Put(input);
product = _buffer.Flip();
_buffer = null;
}
input.Limit = limit;
}
else
{
// When input contained only CR or LF rather than actual data...
if (_buffer == null)
{
product = IoBuffer.Allocate(0);
}
else
{
product = _buffer.Flip();
_buffer = null;
}
}
input.Position = terminatorPos + 1;
return FinishDecode(product, output);
}
input.Position = beginPos;
if (_buffer == null)
{
_buffer = IoBuffer.Allocate(input.Remaining);
_buffer.AutoExpand = true;
}
_buffer.Put(input);
if (_lastIsCR)
{
_buffer.Position = _buffer.Position - 1;
}
return this;
}