Parcourir la source

cleanup: unified duplicate code

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac351@3036 e5f2f494-b856-4b98-b285-d166d9295462
JINMEI Tatuya il y a 14 ans
Parent
commit
2a907b2c2d
1 fichiers modifiés avec 9 ajouts et 5 suppressions
  1. 9 5
      src/lib/dns/message.cc

+ 9 - 5
src/lib/dns/message.cc

@@ -183,6 +183,7 @@ public:
 #endif
 
     void init();
+    void setOpcode(const Opcode& opcode);
     int parseQuestion(InputBuffer& buffer);
     int parseSection(const Section& section, InputBuffer& buffer);
 };
@@ -218,6 +219,12 @@ MessageImpl::init() {
     rrsets_[sectionCodeToId(Section::ADDITIONAL())].clear();
 }
 
+void
+MessageImpl::setOpcode(const Opcode& opcode) {
+    opcode_placeholder_ = opcode;
+    opcode_ = &opcode_placeholder_;
+}
+
 Message::Message(Mode mode) :
     impl_(new MessageImpl(mode))
 {}
@@ -320,8 +327,7 @@ Message::setOpcode(const Opcode& opcode) {
         isc_throw(InvalidMessageOperation,
                   "setOpcode performed in non-render mode");
     }
-    impl_->opcode_placeholder_ = opcode;
-    impl_->opcode_ = &impl_->opcode_placeholder_;
+    impl_->setOpcode(opcode);
 }
 
 unsigned int
@@ -547,9 +553,7 @@ Message::parseHeader(InputBuffer& buffer) {
 
     impl_->qid_ = buffer.readUint16();
     const uint16_t codes_and_flags = buffer.readUint16();
-    impl_->opcode_placeholder_ =
-        Opcode((codes_and_flags & OPCODE_MASK) >> OPCODE_SHIFT);
-    impl_->opcode_ = &impl_->opcode_placeholder_;
+    impl_->setOpcode(Opcode((codes_and_flags & OPCODE_MASK) >> OPCODE_SHIFT));
     impl_->rcode_ = rcodes[(codes_and_flags & RCODE_MASK)];
     impl_->flags_ = (codes_and_flags & FLAG_MASK);
     impl_->counts_[Section::QUESTION().getCode()] = buffer.readUint16();