Exemplo n.º 1
0
        /// <summary>
        /// Tries to parse a <see cref="NbNsQuestionEntry"/> from a buffer of bytes
        /// </summary>
        /// <param name="buffer">Byte array containing the NbNsQuestionEntry</param>
        /// <param name="offset">Zero based offset in the buffer where the NbNsQuestionEntry starts</param>
        /// <param name="questionEntry">Parsed NbNsQuestionEntry if successful, else null</param>
        /// <returns><c>true</c> if parsing was successful, else <c>false</c></returns>
        public static bool TryParse(byte[] buffer, int offset, out NbNsQuestionEntry questionEntry)
        {
            questionEntry = null;
            NbName questionName;

            if (!NbName.TryParse(buffer, offset, out questionName))
            {
                return(false);
            }
            if (buffer.Length < offset + questionName.Length + 4)
            {
                return(false);
            }

            var questionType = (QuestionTypeSpecifier)BufferToUInt16(buffer, offset + questionName.Length);

            if (!Enum.IsDefined(typeof(QuestionTypeSpecifier), questionType))
            {
                return(false);
            }

            var questionClass = (QuestionClassSpecifier)BufferToUInt16(buffer, offset + questionName.Length + 2);

            if (!Enum.IsDefined(typeof(QuestionClassSpecifier), questionClass))
            {
                return(false);
            }

            questionEntry = new NbNsQuestionEntry(questionName, questionType);
            return(true);
        }
Exemplo n.º 2
0
    /// <summary>
    /// Tries to parse a <see cref="NbNsQuestionEntry"/> from a buffer of bytes
    /// </summary>
    /// <param name="buffer">Byte array containing the NbNsQuestionEntry</param>
    /// <param name="offset">Zero based offset in the buffer where the NbNsQuestionEntry starts</param>
    /// <param name="questionEntry">Parsed NbNsQuestionEntry if successful, else null</param>
    /// <returns><c>true</c> if parsing was successful, else <c>false</c></returns>
    public static bool TryParse(byte[] buffer, int offset, out NbNsQuestionEntry questionEntry)
    {
      questionEntry = null;
      NbName questionName;
      if (!NbName.TryParse(buffer, offset, out questionName))
        return false;
      if (buffer.Length < offset + questionName.Length + 4)
        return false;

      var questionType = (QuestionTypeSpecifier)BufferToUInt16(buffer, offset + questionName.Length);
      if (!Enum.IsDefined(typeof(QuestionTypeSpecifier), questionType))
        return false;

      var questionClass = (QuestionClassSpecifier)BufferToUInt16(buffer, offset + questionName.Length + 2);
      if (!Enum.IsDefined(typeof(QuestionClassSpecifier), questionClass))
        return false;

      questionEntry = new NbNsQuestionEntry(questionName, questionType);
      return true;
    }