public void GetNextMessage_OneBatch()
        {
            // add one batch
            byte[] batch = { 0x01, 0x02 };
            unbatcher.AddBatch(new ArraySegment <byte>(batch));

            // get next message, read first byte
            bool result = unbatcher.GetNextMessage(out NetworkReader reader);

            Assert.That(result, Is.True);
            Assert.That(reader.ReadByte(), Is.EqualTo(0x01));

            // get next message, read last byte
            result = unbatcher.GetNextMessage(out reader);
            Assert.That(result, Is.True);
            Assert.That(reader.ReadByte(), Is.EqualTo(0x02));

            // there should be no more messages
            result = unbatcher.GetNextMessage(out _);
            Assert.That(result, Is.False);
        }
        public void GetNextMessage_OneBatch()
        {
            // add one batch
            byte[] batch = BatcherTests.ConcatTimestamp(TimeStamp, new byte[] { 0x01, 0x02 });
            unbatcher.AddBatch(new ArraySegment <byte>(batch));

            // get next message, read first byte
            bool result = unbatcher.GetNextMessage(out NetworkReader reader, out double remoteTimeStamp);

            Assert.That(result, Is.True);
            Assert.That(reader.ReadByte(), Is.EqualTo(0x01));
            Assert.That(remoteTimeStamp, Is.EqualTo(TimeStamp));

            // get next message, read last byte
            result = unbatcher.GetNextMessage(out reader, out remoteTimeStamp);
            Assert.That(result, Is.True);
            Assert.That(reader.ReadByte(), Is.EqualTo(0x02));
            Assert.That(remoteTimeStamp, Is.EqualTo(TimeStamp));

            // there should be no more messages
            result = unbatcher.GetNextMessage(out _, out _);
            Assert.That(result, Is.False);
        }
Exemple #3
0
        public void GetNextMessage_True_False_False_InvalidOperationException()
        {
            // add batch
            byte[] batch = BatcherTests.ConcatTimestamp(TimeStamp, new byte[2]);
            unbatcher.AddBatch(new ArraySegment <byte>(batch));

            // get next message, pretend we read the whole thing
            bool result = unbatcher.GetNextMessage(out NetworkReader reader, out _);

            Assert.That(result, Is.True);
            reader.Position = reader.Length;

            // shouldn't get another one
            result = unbatcher.GetNextMessage(out reader, out _);
            Assert.That(result, Is.False);

            // calling it again was causing "InvalidOperationException: Queue empty"
            result = unbatcher.GetNextMessage(out reader, out _);
            Assert.That(result, Is.False);
        }