internal void Write(DnsNameWriter dnsNameWriter, DnsWriter dnsWriter)
        {
            dnsNameWriter.Write(this.Name);
            dnsWriter.Write(((ushort)this.Type).ToNetworkByteOrder());
            dnsWriter.Write(((ushort)this.Class).ToNetworkByteOrder());
            dnsWriter.Write(this.TimeToLive.ToNetworkByteOrder());

            var data = this.GetData(dnsNameWriter);
            dnsWriter.Write(((ushort)data.Length).ToNetworkByteOrder());
            dnsWriter.Write(data);
        }
        public byte[] GetBytes()
        {
            using (var memoryStream = new MemoryStream())
            using (var writer = new DnsWriter(0, memoryStream))
            {
                var dnsNameWriter = new DnsNameWriter(memoryStream);

                writer.Write(this.MessageId.ToNetworkByteOrder());
                writer.Write(((ushort)this.Flags).ToNetworkByteOrder());

                writer.Write(this.QueryCount.ToNetworkByteOrder());
                writer.Write(((ushort)this.AnswerRecords.Count).ToNetworkByteOrder());
                writer.Write(((ushort)this.NameServerRecords.Count).ToNetworkByteOrder());
                writer.Write(((ushort)this.AdditionalRecords.Count).ToNetworkByteOrder());

                foreach (var resourceRecord in this.AnswerRecords)
                {
                    resourceRecord.Write(dnsNameWriter, writer);
                }

                foreach (var resourceRecord in this.NameServerRecords)
                {
                    resourceRecord.Write(dnsNameWriter, writer);
                }

                foreach (var resourceRecord in this.AdditionalRecords)
                {
                    resourceRecord.Write(dnsNameWriter, writer);
                }

                return memoryStream.ToArray();
            }
        }
 private void WritePointer(DnsWriter dnsWriter)
 {
     var pointer = (ushort)(this.position.Value | 0xc000);
     dnsWriter.Write(pointer.ToNetworkByteOrder());
 }
 private void WriteLabel(DnsWriter dnsWriter)
 {
     this.position = (ushort)dnsWriter.Position;
     var bytes = Encoding.ASCII.GetBytes(this.label);
     dnsWriter.Write((byte)bytes.Length);
     dnsWriter.Write(bytes);
 }