本文整理汇总了C#中Mina.Core.Buffer.IoBuffer类的典型用法代码示例。如果您正苦于以下问题:C# IoBuffer类的具体用法?C# IoBuffer怎么用?C# IoBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IoBuffer类属于Mina.Core.Buffer命名空间,在下文中一共展示了IoBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decode
public void Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
{
if (_session == null)
_session = session;
else if (_session != session)
throw new InvalidOperationException(GetType().Name + " is a stateful decoder. "
+ "You have to create one per session.");
_undecodedBuffers.Enqueue(input);
while (true)
{
IoBuffer b;
if (!_undecodedBuffers.TryPeek(out b))
break;
Int32 oldRemaining = b.Remaining;
_state.Decode(b, output);
Int32 newRemaining = b.Remaining;
if (newRemaining != 0)
{
if (oldRemaining == newRemaining)
throw new InvalidOperationException(_state.GetType().Name
+ " must consume at least one byte per decode().");
}
else
{
_undecodedBuffers.TryDequeue(out b);
}
}
}
示例2: GetHexdump
public static String GetHexdump(IoBuffer buf, Int32 lengthLimit)
{
if (lengthLimit <= 0)
throw new ArgumentException("lengthLimit: " + lengthLimit + " (expected: 1+)");
Boolean truncate = buf.Remaining > lengthLimit;
Int32 size = truncate ? lengthLimit : buf.Remaining;
if (size == 0)
return "empty";
StringBuilder sb = new StringBuilder(size * 3 + 3);
Int32 oldPos = buf.Position;
// fill the first
Int32 byteValue = buf.Get() & 0xFF;
sb.Append((char)highDigits[byteValue]);
sb.Append((char)lowDigits[byteValue]);
size--;
// and the others, too
for (; size > 0; size--)
{
sb.Append(' ');
byteValue = buf.Get() & 0xFF;
sb.Append((char)highDigits[byteValue]);
sb.Append((char)lowDigits[byteValue]);
}
buf.Position = oldPos;
if (truncate)
sb.Append("...");
return sb.ToString();
}
示例3: WriteVarint32
static void WriteVarint32(IoBuffer buffer, uint value)
{
for (; value >= 0x80u; value >>= 7)
buffer.Put((byte)(value | 0x80u));
buffer.Put((byte)value);
}
示例4: Decode
public void Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
{
lock (_decoder)
{
_decoder.Decode(session, input, output);
}
}
示例5: Decode
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
{
// Try to skip header if not read.
if (!_readHeader)
{
input.GetInt16(); // Skip 'type'.
_sequence = input.GetInt32(); // Get 'sequence'.
_readHeader = true;
}
// Try to decode body
AbstractMessage m = DecodeBody(session, input);
// Return NEED_DATA if the body is not fully read.
if (m == null)
{
return MessageDecoderResult.NeedData;
}
else
{
_readHeader = false; // reset readHeader for the next decode
}
m.Sequence = _sequence;
output.Write(m);
return MessageDecoderResult.OK;
}
示例6: IoBufferWrapper
/// <summary>
/// </summary>
protected IoBufferWrapper(IoBuffer buf)
: base(-1, 0, 0, 0)
{
if (buf == null)
throw new ArgumentNullException("buf");
_buf = buf;
}
示例7: DecodeBody
protected override AbstractMessage DecodeBody(IoSession session, IoBuffer input)
{
if (!_readCode)
{
if (input.Remaining < Constants.RESULT_CODE_LEN)
{
return null; // Need more data.
}
_code = input.GetInt16();
_readCode = true;
}
if (_code == Constants.RESULT_OK)
{
if (input.Remaining < Constants.RESULT_VALUE_LEN)
{
return null;
}
ResultMessage m = new ResultMessage();
m.OK = true;
m.Value = input.GetInt32();
_readCode = false;
return m;
}
else
{
ResultMessage m = new ResultMessage();
m.OK = false;
_readCode = false;
return m;
}
}
示例8: BeginSend
/// <inheritdoc/>
protected override void BeginSend(IWriteRequest request, IoBuffer buf)
{
EndPoint destination = request.Destination;
if (destination == null)
destination = this.RemoteEndPoint;
BeginSend(buf, destination);
}
示例9: ComputeChecksum
private byte ComputeChecksum(IoBuffer buffer)
{
buffer.Rewind();
byte checksum = 0;
for (int i = 0; i < Length - 1; i++) checksum += buffer.Get();
return checksum;
}
示例10: Decode
public IDecodingState Decode(IoBuffer input, IProtocolDecoderOutput output)
{
if (input.HasRemaining)
return FinishDecode(input.Get(), output);
return this;
}
示例11: DoDecode
protected override object DoDecode(MessageVersion version, IoBuffer input)
{
using (var scope = ObjectHost.Host.BeginLifetimeScope())
{
return scope.ResolveKeyed<IMessageReader<DuplexMessage>>(version).Read(input);
}
}
示例12: Decodable
public MessageDecoderResult Decodable(IoSession session, IoBuffer input)
{
if ((MessageType)input.Get() != MessageType.Update_ZipFiles)
{
return MessageDecoderResult.NotOK;
}
var zipFileInfo = JsonConvert.DeserializeObject<TransferingZipFileInfo>(input.GetString(Encoding.UTF8));
var fileSize = zipFileInfo.FileSize;
var hashBytes = zipFileInfo.HashBytes;
if (input.Remaining < fileSize)
{
return MessageDecoderResult.NeedData;
}
var filesBytes = new byte[fileSize];
input.Get(filesBytes, 0, (int)fileSize);
if (FileHashHelper.CompareHashValue(FileHashHelper.ComputeFileHash(filesBytes), hashBytes))
{
_zipFileInfoMessage = new TransferingZipFile(filesBytes);
return MessageDecoderResult.OK;
}
return MessageDecoderResult.NotOK;
}
示例13: IoSessionStream
/// <summary>
/// </summary>
public IoSessionStream()
{
_syncRoot = new Byte[0];
_buf = IoBuffer.Allocate(16);
_buf.AutoExpand = true;
_buf.Limit = 0;
}
示例14: 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;
}
示例15: ParameterListEncapsulation
internal ParameterListEncapsulation(IoBuffer bb)
{
#if TODO
this.options = bb.GetInt16();
this.parameters = bb.GetParameterList();
#endif
throw new NotImplementedException();
}