/// <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()); }
/// <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()); }
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)); }