MCPcopy Create free account
hub / github.com/ElementsProject/elements / WriteBlock

Method WriteBlock

src/leveldb/table/table_builder.cc:141–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141void TableBuilder::WriteBlock(BlockBuilder* block, BlockHandle* handle) {
142 // File format contains a sequence of blocks where each block has:
143 // block_data: uint8[n]
144 // type: uint8
145 // crc: uint32
146 assert(ok());
147 Rep* r = rep_;
148 Slice raw = block->Finish();
149
150 Slice block_contents;
151 CompressionType type = r->options.compression;
152 // TODO(postrelease): Support more compression options: zlib?
153 switch (type) {
154 case kNoCompression:
155 block_contents = raw;
156 break;
157
158 case kSnappyCompression: {
159 std::string* compressed = &r->compressed_output;
160 if (port::Snappy_Compress(raw.data(), raw.size(), compressed) &&
161 compressed->size() < raw.size() - (raw.size() / 8u)) {
162 block_contents = *compressed;
163 } else {
164 // Snappy not supported, or compressed less than 12.5%, so just
165 // store uncompressed form
166 block_contents = raw;
167 type = kNoCompression;
168 }
169 break;
170 }
171 }
172 WriteRawBlock(block_contents, type, handle);
173 r->compressed_output.clear();
174 block->Reset();
175}
176
177void TableBuilder::WriteRawBlock(const Slice& block_contents,
178 CompressionType type, BlockHandle* handle) {

Callers

nothing calls this directly

Calls 7

okFunction · 0.85
Snappy_CompressFunction · 0.85
FinishMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected