Browse Source

added getRRCount() method to Message class

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@571 e5f2f494-b856-4b98-b285-d166d9295462
JINMEI Tatuya 15 years ago
parent
commit
9653ab59eb
3 changed files with 17 additions and 1 deletions
  1. 9 1
      src/lib/dns/cpp/message.cc
  2. 2 0
      src/lib/dns/cpp/message.h
  3. 6 0
      src/lib/dns/cpp/message_unittest.cc

+ 9 - 1
src/lib/dns/cpp/message.cc

@@ -252,23 +252,31 @@ Message::setOpcode(const Opcode& opcode)
     impl_->opcode_ = &opcode;
 }
 
+unsigned int
+Message::getRRCount(const Section& section) const
+{
+    return (impl_->counts_[section.getCode()]);
+}
+
 void
 Message::addRRset(const Section& section, RRsetPtr rrset)
 {
     // Note: should check duplicate (TBD)
     impl_->rrsets_[sectionCodeToId(section)].push_back(rrset);
+    impl_->counts_[section.getCode()] += rrset->getRdataCount();
 }
 
 void
 Message::addQuestion(const QuestionPtr question)
 {
     impl_->questions_.push_back(question);
+    impl_->counts_[Section::QUESTION().getCode()]++;
 }
 
 void
 Message::addQuestion(const Question& question)
 {
-    impl_->questions_.push_back(QuestionPtr(new Question(question)));
+    addQuestion(QuestionPtr(new Question(question)));
 }
 
 namespace {

+ 2 - 0
src/lib/dns/cpp/message.h

@@ -476,6 +476,8 @@ public:
     const Opcode& getOpcode() const;
     void setOpcode(const Opcode& opcode);
     std::string toText() const;
+    /// \brief Returns the number of RRs contained in the given section.
+    unsigned int getRRCount(const Section& section) const;
 
     // we don't provide accessors to QD/AN/NS/AR counters as this information
     // is included in the corresponding RRsets.

+ 6 - 0
src/lib/dns/cpp/message_unittest.cc

@@ -98,6 +98,12 @@ TEST_F(MessageTest, toWire)
     rrset->addRdata(in::A("192.0.2.1"));
     rrset->addRdata(in::A("192.0.2.2"));
     message.addRRset(Section::ANSWER(), rrset);
+
+    EXPECT_EQ(1, message.getRRCount(Section::QUESTION()));
+    EXPECT_EQ(2, message.getRRCount(Section::ANSWER()));
+    EXPECT_EQ(0, message.getRRCount(Section::AUTHORITY()));
+    EXPECT_EQ(0, message.getRRCount(Section::ADDITIONAL()));
+
     message.toWire(renderer);
     vector<unsigned char> data;
     UnitTestUtil::readWireData("testdata/message_toWire1", data);