[svn] commit: r571 - in /branches/parkinglot/src/lib/dns/cpp: message.cc message.h message_unittest.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Jan 27 20:55:03 UTC 2010


Author: jinmei
Date: Wed Jan 27 20:55:02 2010
New Revision: 571

Log:
added getRRCount() method to Message class

Modified:
    branches/parkinglot/src/lib/dns/cpp/message.cc
    branches/parkinglot/src/lib/dns/cpp/message.h
    branches/parkinglot/src/lib/dns/cpp/message_unittest.cc

Modified: branches/parkinglot/src/lib/dns/cpp/message.cc
==============================================================================
--- branches/parkinglot/src/lib/dns/cpp/message.cc (original)
+++ branches/parkinglot/src/lib/dns/cpp/message.cc Wed Jan 27 20:55:02 2010
@@ -252,23 +252,31 @@
     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 {

Modified: branches/parkinglot/src/lib/dns/cpp/message.h
==============================================================================
--- branches/parkinglot/src/lib/dns/cpp/message.h (original)
+++ branches/parkinglot/src/lib/dns/cpp/message.h Wed Jan 27 20:55:02 2010
@@ -476,6 +476,8 @@
     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.

Modified: branches/parkinglot/src/lib/dns/cpp/message_unittest.cc
==============================================================================
--- branches/parkinglot/src/lib/dns/cpp/message_unittest.cc (original)
+++ branches/parkinglot/src/lib/dns/cpp/message_unittest.cc Wed Jan 27 20:55:02 2010
@@ -98,6 +98,12 @@
     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);




More information about the bind10-changes mailing list