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)
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 {
......
......@@ -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.
......
......@@ -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);
......
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