示例#1
0
        public void BoundaryBitsTest()
        {
            ByteWriter writer = new ByteWriter();

            writer.AddBits(5, 0b10100);
            writer.AddBits(4, 0b1100);
        }
示例#2
0
        public void UnfinishedValueTest()
        {
            ByteWriter writer = new ByteWriter();

            writer.AddBits(5, 0b10100);
            writer.GetValue();
        }
示例#3
0
        public void BoundaryTest()
        {
            ByteWriter writer = new ByteWriter();

            writer.AddBits(5, 0b10100);
            writer.AddUint(123);
        }
示例#4
0
        public void NormalOperationTest()
        {
            ByteWriter writer = new ByteWriter();

            writer.AddUshort(35000);
            writer.AddByte(230);
            writer.AddString("spam");
            writer.AddUint(4211001100);

            writer.AddBits(1, 1);
            writer.AddBits(4, 2);
            writer.AddBits(3, 1);

            writer.AddByte(10);

            byte[] expected = File.ReadAllBytes(Path.Combine("Files", "structdata.dat"));
            byte[] actual   = writer.GetValue();

            Assert.AreEqual(BitConverter.ToString(expected), BitConverter.ToString(actual));
        }
示例#5
0
        /// <summary>
        /// Get byte representation of the header.
        /// </summary>
        public byte[] ToBytes()
        {
            var byteWriter = new ByteWriter();

            byteWriter.AddUshort(ID);

            byteWriter.AddBits(1, QR);
            byteWriter.AddBits(4, OPCODE);
            byteWriter.AddBits(1, AA);
            byteWriter.AddBits(1, TC);
            byteWriter.AddBits(1, RD);

            byteWriter.AddBits(1, RA);
            byteWriter.AddBits(3, Z);
            byteWriter.AddBits(4, RCODE);

            byteWriter.AddUshort(QDCOUNT);
            byteWriter.AddUshort(ANCOUNT);
            byteWriter.AddUshort(NSCOUNT);
            byteWriter.AddUshort(ARCOUNT);

            return(byteWriter.GetValue());
        }