Пример #1
0
        public void TestReadStringByByteIndex()
        {
            BReader br = new BReader(Encoding.Default.GetBytes("Hello world!"));

            br.ReadStringByByteIndex(0, 5).Should().Be("Hello");
            br.ReadStringByByteIndex(6, 5).Should().Be("world");

            br.Invoking(_ => _.ReadStringByByteIndex(8, 100)).Should().Throw <ArgumentOutOfRangeException>();
            new BReader(Encoding.Default.GetBytes("Hello world!")).ReadStringByByteIndex(6, 5, Endian.SmallEndian).Should().Be("dlrow");
        }
Пример #2
0
        public void TestFunction()
        {
            byte[]  message = new byte[] { 0x01, 0x12, 0x34, 0x56, 0x78, 0b10101010, 0b11100100, (byte)'S', (byte)'u', (byte)'c', (byte)'c', (byte)'e', (byte)'s', (byte)'s', };
            BReader br      = new BReader(message);

            br.ReadValueByByteIndex <byte>(0, 1).Should().Be(0x01);
            br.ReadValueByByteIndex <int>(1, 4).Should().Be(0x12345678);
            for (int i = 0; i < 8; ++i)
            {
                br.ReadValueByBitIndex <bool>(5, i, 1).Should().Be(i % 2 == 1);
            }
            for (byte i = 0; i < 4; ++i)
            {
                br.ReadValueByBitIndex <byte>(6, 2 * i, 2).Should().Be(i);
            }
            br.ReadStringByByteIndex(7, 7).Should().Be("Success");
        }