Implemented walker overlay that calculates decompressed size.

This commit is contained in:
2022-09-05 20:04:54 +10:00
parent ab921e5059
commit 148a999953
3 changed files with 35 additions and 1 deletions

View File

@@ -43,6 +43,7 @@ void print_type4(Type4 val);
// Utilities
Timestamp convert_ts(uint16_t ts);
void print_callback(Node n, void *_);
void dc_size_cb(Node n, void *dc_size_ptr);
//
// === FUNCTIONS ===
@@ -88,6 +89,33 @@ void print_callback(Node n, void *pt) {
}
}
size_t espr_decompressed_size(char *data, size_t size) {
size_t dc_size = 0;
espr_walk(data, size, dc_size_cb, &dc_size);
return dc_size;
}
void dc_size_cb(Node n, void *dc_size_ptr) {
size_t *dcsp = dc_size_ptr;
switch (n.type) {
case NT_GROUP:
// Only add header size for groups, internals will be walked
*dcsp += sizeof(Group);
break;
case NT_RECORD:
// Add the whole record and header, records are leaf-ish
*dcsp += sizeof(Record);
if (n.header.record->flags & COMPRESSED_FLAG) {
// Read decompressed size
*dcsp += *((uint32_t *)n.data);
} else
*dcsp += n.header.record->size;
break;
default:
assert(false); // invalid node type
}
}
/* Unknown data will be some concatenation of groups and records.
*
* `walk_concat` will call the appropriate walking function