コード例 #1
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', };
            BWriter bw      = new BWriter(message.Length);

            bw.WriteValueByByteIndex <byte>(0, 0x01);
            bw.WriteValueByByteIndex <int>(1, 0x12345678);
            for (int i = 0; i < 8; ++i)
            {
                bw.WriteValueByBitIndex <bool>(5, i, i % 2 == 1, 1);
            }
            for (byte i = 0; i < 4; ++i)
            {
                bw.WriteValueByBitIndex <byte>(6, 2 * i, i, 2);
            }
            bw.WriteStringByByteIndex(7, "Success", 7);
            bw.GetData().Should().BeEquivalentTo(message);
        }
コード例 #2
0
        public void TestWriteValueByByteIndex()
        {
            BWriter bw = new BWriter(5);

            bw.WriteValueByByteIndex <ulong>(1, 0xAABBCCDD12345678, 4);
            byte[] res = bw.GetData();
            res[1].Should().Be(0x12);
            res[2].Should().Be(0x34);
            res[3].Should().Be(0x56);
            res[4].Should().Be(0x78);
            bw = new BWriter(5);
            bw.WriteValueByByteIndex <ulong>(1, 0xAABBCCDD12345678, 4, Endian.SmallEndian);
            res = bw.GetData();
            res[1].Should().Be(0x78);
            res[2].Should().Be(0x56);
            res[3].Should().Be(0x34);
            res[4].Should().Be(0x12);
            bw.Invoking(_ => _.WriteValueByByteIndex <bool>(0, false, 1)).Should().Throw <NotSupportedException>();
            bw.Invoking(_ => _.WriteValueByByteIndex <BWriter>(0, _, 1)).Should().Throw <NotSupportedException>();
            bw.Invoking(_ => _.WriteValueByByteIndex <int>(0, 0, 5)).Should().Throw <ArgumentOutOfRangeException>();
        }