Ejemplo n.º 1
0
        public void TestReadValueByByteIndex()
        {
            BReader br = new BReader(new byte[] { 0x12, 0x34, 0x56, 0x78 });

            br.ReadValueByByteIndex <long>(0, 4).Should().Be(0x12345678);
            br.ReadValueByByteIndex <long>(1, 3).Should().Be(0x345678);
            br.Invoking(_ => _.ReadValueByByteIndex <short>(0, 4)).Should().Throw <ArgumentOutOfRangeException>();
            br.Invoking(_ => _.ReadValueByByteIndex <string>(0, 4)).Should().Throw <NotSupportedException>();
            br.Invoking(_ => _.ReadValueByByteIndex <bool>(0, 4)).Should().Throw <NotSupportedException>();
            br.Invoking(_ => _.ReadValueByByteIndex <Foo>(0, 4)).Should().Throw <NotSupportedException>();
            new BReader(new byte[] { 0x12, 0x34, 0x56, 0x78 }).ReadValueByByteIndex <long>(0, 4, Endian.SmallEndian).Should().Be(0x78563412);
        }
Ejemplo n.º 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");
        }