Exemple #1
0
        public void SkipOneByteTest()
        {
            var stream = new FastStreamReader(new byte[5]);

            Assert.Equal(0, stream.GetCurrentIndex());

            stream.SkipOneByte();
            Assert.Equal(1, stream.GetCurrentIndex());

            stream.SkipOneByte();
            Assert.Equal(2, stream.GetCurrentIndex());
        }
Exemple #2
0
        public void GetCurrentIndexTest()
        {
            var stream = new FastStreamReader(new byte[10]);

            Assert.Equal(0, stream.GetCurrentIndex());
            _ = stream.TryReadByteArray(3, out _);
            Assert.Equal(3, stream.GetCurrentIndex());
            _ = stream.TryReadByteArray(5, out _);
            Assert.Equal(8, stream.GetCurrentIndex());
            _ = stream.TryReadByteArray(2, out _);
            Assert.Equal(10, stream.GetCurrentIndex());
        }
Exemple #3
0
        public void ReadByteArray32CheckedTest()
        {
            var stream = new FastStreamReader(Helper.GetBytes(35));

            byte[] actual   = stream.ReadByteArray32Checked();
            byte[] expected = Helper.GetBytes(32);

            Assert.Equal(expected, actual);
            Assert.Equal(32, stream.GetCurrentIndex());
        }
Exemple #4
0
        public void TryReadByteArrayTest()
        {
            var  stream = new FastStreamReader(Helper.GetBytes(12));
            bool b      = stream.TryReadByteArray(10, out byte[] actual);

            byte[] expected = Helper.GetBytes(10);

            Assert.True(b);
            Assert.Equal(expected, actual);
            Assert.Equal(10, stream.GetCurrentIndex());
        }
Exemple #5
0
        public void SkipTest()
        {
            var stream = new FastStreamReader(new byte[10]);

            Assert.Equal(0, stream.GetCurrentIndex());

            stream.Skip(0);
            Assert.Equal(0, stream.GetCurrentIndex());

            stream.Skip(1);
            Assert.Equal(1, stream.GetCurrentIndex());

            stream.Skip(4);
            Assert.Equal(5, stream.GetCurrentIndex());

            stream.Skip(7);
            Assert.Equal(12, stream.GetCurrentIndex());

            Assert.False(stream.CheckRemaining(1));
        }
Exemple #6
0
        public override bool TryDeserialize(FastStreamReader stream, out string error)
        {
            int actualIndex = stream.GetCurrentIndex();

            Assert.Equal(expectedIndex, actualIndex);

            if (!stream.TryReadByteArray(bytesToRead, out _))
            {
                Assert.True(false, "Stream doesn't have enough bytes.");
            }

            error = retError;
            return(string.IsNullOrEmpty(retError));
        }