本文整理匯總了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;
}