Implemented walker overlay that calculates decompressed size.
This commit is contained in:
@@ -23,7 +23,8 @@ int main(void) {
|
|||||||
size_t read = fread(buffer, sizeof(char), size, fp);
|
size_t read = fread(buffer, sizeof(char), size, fp);
|
||||||
assert(read == size);
|
assert(read == size);
|
||||||
|
|
||||||
espr_print(buffer, size);
|
size_t decompressed = espr_decompressed_size(buffer, size);
|
||||||
|
printf("%llu -> %llu\n", size, decompressed);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,6 +267,11 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
void espr_print(char *data, size_t size);
|
void espr_print(char *data, size_t size);
|
||||||
|
|
||||||
|
/* Calculates the size of the esp data if all of the compressed records are
|
||||||
|
* decompressed.
|
||||||
|
*/
|
||||||
|
size_t espr_decompressed_size(char *data, size_t size);
|
||||||
|
|
||||||
// End C++ guard
|
// End C++ guard
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ void print_type4(Type4 val);
|
|||||||
// Utilities
|
// Utilities
|
||||||
Timestamp convert_ts(uint16_t ts);
|
Timestamp convert_ts(uint16_t ts);
|
||||||
void print_callback(Node n, void *_);
|
void print_callback(Node n, void *_);
|
||||||
|
void dc_size_cb(Node n, void *dc_size_ptr);
|
||||||
|
|
||||||
//
|
//
|
||||||
// === FUNCTIONS ===
|
// === 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.
|
/* Unknown data will be some concatenation of groups and records.
|
||||||
*
|
*
|
||||||
* `walk_concat` will call the appropriate walking function
|
* `walk_concat` will call the appropriate walking function
|
||||||
|
|||||||
Reference in New Issue
Block a user