Commit 9653ab59 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

added getRRCount() method to Message class


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@571 e5f2f494-b856-4b98-b285-d166d9295462
parent 13b80a6b
...@@ -252,23 +252,31 @@ Message::setOpcode(const Opcode& opcode) ...@@ -252,23 +252,31 @@ Message::setOpcode(const Opcode& opcode)
impl_->opcode_ = &opcode; impl_->opcode_ = &opcode;
} }
unsigned int
Message::getRRCount(const Section& section) const
{
return (impl_->counts_[section.getCode()]);
}
void void
Message::addRRset(const Section& section, RRsetPtr rrset) Message::addRRset(const Section& section, RRsetPtr rrset)
{ {
// Note: should check duplicate (TBD) // Note: should check duplicate (TBD)
impl_->rrsets_[sectionCodeToId(section)].push_back(rrset); impl_->rrsets_[sectionCodeToId(section)].push_back(rrset);
impl_->counts_[section.getCode()] += rrset->getRdataCount();
} }
void void
Message::addQuestion(const QuestionPtr question) Message::addQuestion(const QuestionPtr question)
{ {
impl_->questions_.push_back(question); impl_->questions_.push_back(question);
impl_->counts_[Section::QUESTION().getCode()]++;
} }
void void
Message::addQuestion(const Question& question) Message::addQuestion(const Question& question)
{ {
impl_->questions_.push_back(QuestionPtr(new Question(question))); addQuestion(QuestionPtr(new Question(question)));
} }
namespace { namespace {
......
...@@ -476,6 +476,8 @@ public: ...@@ -476,6 +476,8 @@ public:
const Opcode& getOpcode() const; const Opcode& getOpcode() const;
void setOpcode(const Opcode& opcode); void setOpcode(const Opcode& opcode);
std::string toText() const; 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 // we don't provide accessors to QD/AN/NS/AR counters as this information
// is included in the corresponding RRsets. // is included in the corresponding RRsets.
......
...@@ -98,6 +98,12 @@ TEST_F(MessageTest, toWire) ...@@ -98,6 +98,12 @@ TEST_F(MessageTest, toWire)
rrset->addRdata(in::A("192.0.2.1")); rrset->addRdata(in::A("192.0.2.1"));
rrset->addRdata(in::A("192.0.2.2")); rrset->addRdata(in::A("192.0.2.2"));
message.addRRset(Section::ANSWER(), rrset); 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); message.toWire(renderer);
vector<unsigned char> data; vector<unsigned char> data;
UnitTestUtil::readWireData("testdata/message_toWire1", data); UnitTestUtil::readWireData("testdata/message_toWire1", data);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment