Commit 04eb5ceb authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2751] Consolidate common code

parent 8e647762
......@@ -114,6 +114,25 @@ sanityChecks(const ConstRRsetPtr& rrset, const ConstRRsetPtr &sig_rrset,
} // Anonymous namespace
RdataSet*
RdataSet::packSet(util::MemorySegment& mem_sgmt, RdataEncoder& encoder,
size_t rdata_count, size_t rrsig_count, const RRType& rrtype,
const RRTTL& rrttl)
{
const size_t ext_rrsig_count_len =
rrsig_count >= MANY_RRSIG_COUNT ? sizeof(uint16_t) : 0;
const size_t data_len = encoder.getStorageLength();
void* p = mem_sgmt.allocate(sizeof(RdataSet) + ext_rrsig_count_len +
data_len);
RdataSet* rdataset = new(p) RdataSet(rrtype, rdata_count, rrsig_count,
rrttl);
if (rrsig_count >= RdataSet::MANY_RRSIG_COUNT) {
*rdataset->getExtSIGCountBuf() = rrsig_count;
}
encoder.encode(rdataset->getDataBuf(), data_len);
return (rdataset);
}
RdataSet*
RdataSet::create(util::MemorySegment& mem_sgmt, RdataEncoder& encoder,
ConstRRsetPtr rrset, ConstRRsetPtr sig_rrset,
......@@ -171,18 +190,8 @@ RdataSet::create(util::MemorySegment& mem_sgmt, RdataEncoder& encoder,
<< MAX_RRSIG_COUNT);
}
const size_t ext_rrsig_count_len =
rrsig_count >= MANY_RRSIG_COUNT ? sizeof(uint16_t) : 0;
const size_t data_len = encoder.getStorageLength();
void* p = mem_sgmt.allocate(sizeof(RdataSet) + ext_rrsig_count_len +
data_len);
RdataSet* rdataset = new(p) RdataSet(rrtype, rdata_count, rrsig_count,
rrttl);
if (rrsig_count >= MANY_RRSIG_COUNT) {
*rdataset->getExtSIGCountBuf() = rrsig_count;
}
encoder.encode(rdataset->getDataBuf(), data_len);
return (rdataset);
return (packSet(mem_sgmt, encoder, rdata_count, rrsig_count, rrtype,
rrttl));
}
namespace {
......@@ -272,20 +281,8 @@ RdataSet::subtract(util::MemorySegment& mem_sgmt, RdataEncoder& encoder,
if (rdata_count == 0 && rrsig_count == 0) {
return (NULL); // It is left empty
}
// Construct the result
const size_t ext_rrsig_count_len =
rrsig_count >= MANY_RRSIG_COUNT ? sizeof(uint16_t) : 0;
const size_t data_len = encoder.getStorageLength();
void* p = mem_sgmt.allocate(sizeof(RdataSet) + ext_rrsig_count_len +
data_len);
RdataSet* rdataset =
new(p) RdataSet(rrtype, rdata_count, rrsig_count,
restoreTTL(old_rdataset.getTTLData()));
if (rrsig_count >= MANY_RRSIG_COUNT) {
*rdataset->getExtSIGCountBuf() = rrsig_count;
}
encoder.encode(rdataset->getDataBuf(), data_len);
return (rdataset);
return (packSet(mem_sgmt, encoder, rdata_count, rrsig_count, rrtype,
restoreTTL(old_rdataset.getTTLData())));
}
void
......
......@@ -358,6 +358,12 @@ private:
// field for the real number of RRSIGs. It's 2^3 - 1 = 7.
static const size_t MANY_RRSIG_COUNT = (1 << 3) - 1;
// Common code for packing the result in create and subtract.
static RdataSet* packSet(util::MemorySegment& mem_sgmt,
RdataEncoder& encoder, size_t rdata_count,
size_t rrsig_count, const dns::RRType& rrtype,
const dns::RRTTL& rrttl);
public:
/// \brief Return the bare pointer to the next node.
///
......
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