public void TestPeek() { ByteQueueStream input = new ByteQueueStream(); byte[] buffer = new byte[5]; // peek more than available Assert.AreEqual(0, input.Peek(buffer)); AssertArrayEquals(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00 }, buffer); // peek less than available input.Write(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }); Assert.AreEqual(5, input.Peek(buffer)); AssertArrayEquals(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }, buffer); Assert.AreEqual(6, input.Available); // peek equal to available input.ReadByte(); Assert.AreEqual(5, input.Peek(buffer)); AssertArrayEquals(new byte[] { 0x02, 0x03, 0x04, 0x05, 0x06 }, buffer); Assert.AreEqual(5, input.Available); input.Close(); // so compiler doesn't whine about a resource leak }
public virtual void OfferInput(byte[] input) { if (mBlocking) { throw new InvalidOperationException("Cannot use OfferInput() in blocking mode! Use Stream instead."); } if (mClosed) { throw new IOException("Connection is closed, cannot accept any more input"); } mInputBuffers.Write(input); while (mInputBuffers.Available >= 5) { byte[] buf = new byte[5]; mInputBuffers.Peek(buf); int num = TlsUtilities.ReadUint16(buf, 3) + 5; if (mInputBuffers.Available < num) { break; } SafeReadRecord(); } }
public void TestPeek() { ByteQueueStream input = new ByteQueueStream(); byte[] buffer = new byte[5]; // peek more than available Assert.AreEqual(0, input.Peek(buffer)); AssertArrayEquals(new byte[]{ 0x00, 0x00, 0x00, 0x00, 0x00 }, buffer); // peek less than available input.Write(new byte[]{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }); Assert.AreEqual(5, input.Peek(buffer)); AssertArrayEquals(new byte[]{ 0x01, 0x02, 0x03, 0x04, 0x05 }, buffer); Assert.AreEqual(6, input.Available); // peek equal to available input.ReadByte(); Assert.AreEqual(5, input.Peek(buffer)); AssertArrayEquals(new byte[]{ 0x02, 0x03, 0x04, 0x05, 0x06 }, buffer); Assert.AreEqual(5, input.Available); input.Close(); // so compiler doesn't whine about a resource leak }