Ejemplo n.º 1
0
        /// <summary>
        /// Get byte representation of the question.
        /// </summary>
        public byte[] ToBytes()
        {
            var byteWriter = new ByteWriter();

            var labels = Name.Split('.');

            foreach (var label in labels)
            {
                byteWriter.AddByte((byte)label.Length);
                byteWriter.AddString(label);
            }
            byteWriter.AddByte(0);

            byteWriter.AddUshort(QType);
            byteWriter.AddUshort(QClass);

            return(byteWriter.GetValue());
        }
Ejemplo n.º 2
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));
        }