bool InnerNode::write_msgbuf(BlockWriter& writer, MsgBuf *mb, Slice buffer) { if (tree_->compressor_) { // 1. write to buffer Block block(buffer, 0, 0); BlockWriter wr(&block); if (!mb->write_to(wr)) return false; // 2. compress assert(tree_->compressor_->max_compressed_length(block.size()) <= writer.remain()); size_t compressed_length; if (!tree_->compressor_->compress(buffer.data(), block.size(), writer.addr(), &compressed_length)) { LOG_ERROR("compress msgbuf error, nid " << nid_); return false; } // 3. skip writer.skip(compressed_length); return true; } else { return mb->write_to(writer); } }
bool LeafNode::write_bucket(BlockWriter& writer, RecordBucket *bucket, Slice buffer) { if (tree_->compressor_) { // 1. write to buffer Block block(buffer, 0, 0); BlockWriter wr(&block); if (!write_bucket(wr, bucket)) return false; // 2. compress assert(tree_->compressor_->max_compressed_length(block.size()) <= writer.remain()); size_t compressed_length; if (!tree_->compressor_->compress(buffer.data(), block.size(), writer.addr(), &compressed_length)) { LOG_ERROR("compress msgbuf error, nid " << nid_); return false; } // 3. skip writer.skip(compressed_length); return true; } else { return write_bucket(writer, bucket); } }