public void TestReadValueByBitIndex() { BReader br = new BReader(new byte[] { 0x12, 0x34 }); br.ReadValueByBitIndex <int>(0, 16).Should().Be(0x3412); br.ReadValueByBitIndex <long>(4, 8).Should().Be(0x41); br.ReadValueByBitIndex <bool>(13, 1).Should().Be(true); br.ReadValueByBitIndex <byte>(9, 5).Should().Be(0x1A); br.ReadValueByBitIndex <byte>(1, 1, 5).Should().Be(0x1A); br.Invoking(_ => _.ReadValueByBitIndex <byte>(0, 9)).Should().Throw <ArgumentOutOfRangeException>(); br.Invoking(_ => _.ReadValueByBitIndex <string>(0, 4)).Should().Throw <NotSupportedException>(); br.Invoking(_ => _.ReadValueByBitIndex <Foo>(0, 4)).Should().Throw <NotSupportedException>(); br = new BReader(new byte[] { 0x12, 0x34 }); br.ReadValueByBitIndex <int>(0, 16, Endian.BigEndian).Should().Be(0x482C); br.ReadValueByBitIndex <byte>(9, 6, Endian.BigEndian).Should().Be(0x16); }
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"); }