public void ResetSet()
        {
            var writer = new BitBufferWriter <SevenBitEncoding <u32ArrayMemory> >(8);

            writer.i32(666);
            var bitsWritten   = writer.BitsWritten;
            var bitsAvailable = writer.BitsAvailable;

            writer.Reset();
            Assert.AreEqual(0, writer.BitsWritten);

            writer.i32(666);
            Assert.AreEqual(bitsWritten, writer.BitsWritten);
            Assert.AreEqual(bitsAvailable, writer.BitsAvailable);
            writer.i32(-273);
            writer.b(true);
            writer.i64(1234567890);
            var reader = new BitBufferReader <SevenBitDecoding <u32ArrayMemory> >();

            reader.CopyFrom(writer.ToArray());
            Assert.AreEqual(666, reader.i32());
            var bitsRead = reader.BitsRead;

            reader.i32();
            reader.SetPosition(bitsRead);
            Assert.AreEqual(-273, reader.i32());
            var bitPosition = reader.BitsRead;

            reader.b();
            reader.SetPosition(bitPosition);
            Assert.True(reader.b());
        }
Exemplo n.º 2
0
        public void i32ReadOutOfRange()
        {
            var reader = new BitBufferReader <SevenBitDecoding <u32ArrayMemory> >();

            reader.CopyFrom(new u8[666]);
            Assert.Throws <ArgumentException>(() => reader.i32(666, 123));
            Assert.Throws <ArgumentOutOfRangeException>(() => reader.i32(255));
            Assert.Throws <ArgumentOutOfRangeException>(() => reader.i32(33));
        }
Exemplo n.º 3
0
        public void int32VerySmallReader()
        {
            var smallReader = new BitBufferReader <SevenBitDecoding <u32ArrayMemory> >(1);

            smallReader.CopyFrom(new u8[4]);
            smallReader.i32(i32.MinValue, i32.MaxValue);
            Assert.True(smallReader.BitsRead > 0);
            smallReader.i32(i32.MinValue, i32.MaxValue);
            Assert.Throws <ArgumentOutOfRangeException>(() => smallReader.i32(i32.MinValue, i32.MaxValue));
        }
        public void BitsRead()
        {
            var writer = new BitBufferWriter <SevenBitEncoding <u32ArrayMemory> >();

            Assert.AreEqual(0, writer.BitsWritten);
            writer.b(true);
            Assert.AreEqual(1, writer.BitsWritten);
            writer.u8(123);
            Assert.AreEqual(9, writer.BitsWritten);
            writer.i16(12345);
            Assert.AreEqual(33, writer.BitsWritten);
            writer.i32(1234567890);
            Assert.AreEqual(73, writer.BitsWritten);
            var data   = writer.ToArray();
            var reader = new BitBufferReader <SevenBitDecoding <u32ArrayMemory> >();

            reader.CopyFrom(data);

            Assert.AreEqual(0, reader.BitsRead);
            reader.b();
            Assert.AreEqual(1, reader.BitsRead);
            reader.u8();
            Assert.AreEqual(9, reader.BitsRead);
            reader.i16();
            Assert.AreEqual(33, reader.BitsRead);
            reader.i32();
            Assert.AreEqual(73, reader.BitsRead);
        }
Exemplo n.º 5
0
        public void IntReadWrite()
        {
            var writer = new BitBufferWriter <SevenBitEncoding <u32ArrayMemory> >();

            writer.i32(int.MinValue);
            writer.i32(0);
            writer.i32(int.MaxValue);
            writer.Align();
            var allocated = new byte[ushort.MaxValue];

            writer.ToSpan(allocated);
            var reader = new BitBufferReader <SevenBitDecoding <u32ArrayMemory> >(allocated.Length);

            reader.CopyFrom(allocated);
            Assert.AreEqual(int.MinValue, reader.i32());
            Assert.AreEqual(0, reader.i32());
            Assert.AreEqual(int.MaxValue, reader.i32());
        }
        public void ToArrayFromFrom()
        {
            var writer = new BitBufferWriter <SevenBitEncoding <u32ArrayMemory> >(100);

            writer.i64(i64.MaxValue);
            writer.i32(i32.MaxValue);
            writer.i16(i16.MaxValue);
            var result = writer.ToArray();
            var reader = new BitBufferReader <SevenBitDecoding <u32ArrayMemory> >();

            reader.CopyFrom(result);
            Assert.AreEqual(i64.MaxValue, reader.i64());
            Assert.AreEqual(i32.MaxValue, reader.i32());
            Assert.AreEqual(i16.MaxValue, reader.i16());
            reader.CopyFrom(result);
            Assert.AreEqual(i64.MaxValue, reader.i64());
            Assert.AreEqual(i32.MaxValue, reader.i32());
            Assert.AreEqual(i16.MaxValue, reader.i16());
        }
        public void RawToEncodedReadWrite()
        {
            var rawWriter = new BitBufferWriter <RawEncoding <u32ArrayMemory> >();

            rawWriter.i32(i32.MaxValue - 13);
            rawWriter.u32(u32.MaxValue - 666);
            var rawReader = new BitBufferReader <RawDecoding <u32ArrayMemory> >();
            var data      = rawWriter.ToArray();

            rawReader.CopyFrom(data);
            Assert.AreEqual(i32.MaxValue - 13, rawReader.i32());
            Assert.AreEqual(u32.MaxValue - 666, rawReader.u32());
        }
        public void ToSpanFromFrom()
        {
            var writer = new BitBufferWriter <SevenBitEncoding <u32ArrayMemory> >(100);

            writer.i64(i64.MaxValue);
            writer.i32(i32.MaxValue);
            writer.i16(i16.MaxValue);
            Span <byte>         span = new byte[writer.LengthWritten];
            ReadOnlySpan <byte> read = span;

            writer.ToSpan(span);
            var reader = new BitBufferReader <SevenBitDecoding <u32ArrayMemory> >();

            reader.CopyFrom(read);
            Assert.AreEqual(i64.MaxValue, reader.i64());
            Assert.AreEqual(i32.MaxValue, reader.i32());
            Assert.AreEqual(i16.MaxValue, reader.i16());
            reader.CopyFrom(read);
            Assert.AreEqual(i64.MaxValue, reader.i64());
            Assert.AreEqual(i32.MaxValue, reader.i32());
            Assert.AreEqual(i16.MaxValue, reader.i16());
        }
Exemplo n.º 9
0
        public void IntMinMaxRequired()
        {
            var writer = new BitBufferWriter <SevenBitEncoding <u32ArrayMemory> >();

            writer.i32(12345, 0, 123456);
            writer.i32(1);
            writer.i32(42, -1, 43);
            writer.i32(1, 0, 10);
            writer.i32(2, 3);
            writer.i32(0);
            var bitsWritten = writer.BitsWritten;
            var data        = writer.ToArray();
            var reader      = new BitBufferReader <SevenBitDecoding <u32ArrayMemory> >();

            reader.CopyFrom(data);
            Assert.AreEqual(12345, reader.i32(0, 123456));
            Assert.AreEqual(1, reader.i32());
            Assert.AreEqual(42, reader.i32Peek(-1, 43));
            Assert.AreEqual(42, reader.i32(-1, 43));
            Assert.AreEqual(1, reader.i32(0, 10));
            Assert.AreEqual(2, reader.i32(3));
            Assert.AreEqual(0, reader.i32());
            Assert.AreEqual(bitsWritten, reader.BitsRead);
        }