Commit a7df756b authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2097] use the encoder to allocate the sufficient len of data and do encode.

some parameters are currently hardcoded; we need a revised version
of the reader implementation.
parent e3fa6f45
......@@ -31,22 +31,32 @@ namespace datasrc {
namespace memory {
RdataSet*
RdataSet::create(util::MemorySegment& mem_sgmt, RdataEncoder& /*encoder*/,
dns::ConstRRsetPtr rrset, dns::ConstRRsetPtr sig_rrset)
RdataSet::create(util::MemorySegment& mem_sgmt, RdataEncoder& encoder,
ConstRRsetPtr rrset, ConstRRsetPtr sig_rrset)
{
void* p = mem_sgmt.allocate(sizeof(RdataSet));
encoder.start(rrset->getClass(), rrset->getType());
for (RdataIteratorPtr it = rrset->getRdataIterator();
!it->isLast();
it->next()) {
encoder.addRdata(it->getCurrent());
}
const size_t data_len = encoder.getStorageLength();
assert(data_len == 4);
void* p = mem_sgmt.allocate(sizeof(RdataSet) + data_len);
RdataSet* rdataset = new(p) RdataSet(rrset->getType(),
rrset->getRdataCount(),
sig_rrset ?
sig_rrset->getRdataCount() : 0,
rrset->getTTL());
encoder.encode(rdataset + 1, data_len);
return (rdataset);
}
void
RdataSet::destroy(util::MemorySegment& mem_sgmt, RdataSet* rdataset) {
rdataset->~RdataSet();
mem_sgmt.deallocate(rdataset, sizeof(RdataSet));
mem_sgmt.deallocate(rdataset, sizeof(RdataSet) + 4);
}
namespace {
......
Supports Markdown
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