Example #1
0
        private static void Set(ref DnStream Stream, ref Dictionary <string, ushort> Pointers, IQuestion Question)
        {
            Set(ref Stream, ref Pointers, Question.Domain);

            Stream.SetUShort((byte)Question.Type);

            Stream.SetUShort((byte)Question.Class);
        }
Example #2
0
        private static void Set(ref DnStream Stream, ref Dictionary <string, ushort> Pointers, IAnswer Answer)
        {
            Set(ref Stream, ref Pointers, Answer.Domain);

            Stream.SetUShort((byte)Answer.Type);

            Stream.SetUShort((byte)Answer.Class);

            Stream.SetTimeSpan(Answer.TimeToLive);

            Stream.SetUShort(Answer.Length);

            Set(ref Stream, ref Pointers, Answer.Record);
        }
Example #3
0
        public static byte[] Serialize(ref IMessage Message)
        {
            var Size = SizeOf(ref Message);

            var Stream = new DnStream(Size);

            var Pointers = new Dictionary <string, ushort>();

            Stream.SetUShort(Message.ID);

            Stream.SetBit((byte)Message.MessageType);
            Stream.SetBits(4, (byte)Message.OperationCode);
            Stream.SetBit((byte)Message.AuthoritativeAnswer);
            Stream.SetBit(Convert.ToByte(Message.Truncated));
            Stream.SetBit(Convert.ToByte(Message.RecursionDesired));

            Stream.SetBit(Convert.ToByte(Message.RecursionAvailable));
            Stream.SetBit(Message.Zero);
            Stream.SetBit(Convert.ToByte(Message.AuthenticatedData));
            Stream.SetBit(Convert.ToByte(Message.CheckingDisabled));
            Stream.SetBits(4, (byte)Message.ResponseCode);

            Stream.SetUShort((ushort)Message.Questions.Count());
            Stream.SetUShort((ushort)Message.Answers.Count());

            Stream.SetUShort((ushort)Message.Authority.Count());
            Stream.SetUShort((ushort)Message.Additional.Count());

            Set(ref Stream, ref Pointers, Message.Questions);

            Set(ref Stream, ref Pointers, Message.Answers);

            Set(ref Stream, ref Pointers, Message.Authority);

            Set(ref Stream, ref Pointers, Message.Additional);

            return(Stream.ToArray());
        }