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; }
public void TestIndexOf() { for (int i = 0; i < 2; i++) { IoBuffer buf = IoBuffer.Allocate(16); buf.Put((byte)0x1); buf.Put((byte)0x2); buf.Put((byte)0x3); buf.Put((byte)0x4); buf.Put((byte)0x1); buf.Put((byte)0x2); buf.Put((byte)0x3); buf.Put((byte)0x4); buf.Position = 2; buf.Limit = 5; Assert.AreEqual(4, buf.IndexOf((byte)0x1)); Assert.AreEqual(-1, buf.IndexOf((byte)0x2)); Assert.AreEqual(2, buf.IndexOf((byte)0x3)); Assert.AreEqual(3, buf.IndexOf((byte)0x4)); } }
/// <inheritdoc/> public override Int32 IndexOf(Byte b) { return(_buf.IndexOf(b)); }