FromArray() public static method

public static FromArray ( byte header ) : Header
header byte
return Header
示例#1
0
        public static Response FromArray(byte[] message)
        {
            Header header = Header.FromArray(message);
            int    offset = header.Size;

            if (!header.Response || header.QuestionCount == 0)
            {
                throw new ArgumentException("Invalid response message");
            }

            if (header.Truncated)
            {
                return(new Response(header,
                                    Question.GetAllFromArray(message, offset, header.QuestionCount),
                                    new List <IResourceRecord>(),
                                    new List <IResourceRecord>(),
                                    new List <IResourceRecord>()));
            }

            return(new Response(header,
                                Question.GetAllFromArray(message, offset, header.QuestionCount, out offset),
                                ResourceRecordFactory.GetAllFromArray(message, offset, header.AnswerRecordCount, out offset),
                                ResourceRecordFactory.GetAllFromArray(message, offset, header.AuthorityRecordCount, out offset),
                                ResourceRecordFactory.GetAllFromArray(message, offset, header.AdditionalRecordCount, out offset)));
        }
示例#2
0
        public static Request FromArray(byte[] message)
        {
            Header header = Header.FromArray(message);

            if (header.Response || header.QuestionCount == 0 ||
                header.AdditionalRecordCount + header.AnswerRecordCount + header.AuthorityRecordCount > 0 ||
                header.ResponseCode != ResponseCode.NoError)
            {
                throw new ArgumentException("Invalid request message");
            }

            return(new Request(header, Question.GetAllFromArray(message, header.Size, header.QuestionCount)));
        }