Implemented FormID counter.

This commit is contained in:
2022-09-05 20:14:34 +10:00
parent 148a999953
commit 10f9c50674
3 changed files with 26 additions and 2 deletions

View File

@@ -272,6 +272,11 @@ extern "C" {
*/
size_t espr_decompressed_size(char *data, size_t size);
/* Counts the number of formids present in the esp/esm data. This should be
* equal to the number of records.
*/
size_t espr_formid_count(char *data, size_t size);
// End C++ guard
#ifdef __cplusplus
}

View File

@@ -44,6 +44,7 @@ void print_type4(Type4 val);
Timestamp convert_ts(uint16_t ts);
void print_callback(Node n, void *_);
void dc_size_cb(Node n, void *dc_size_ptr);
void formid_count_cb(Node n, void *count_ptr);
//
// === FUNCTIONS ===
@@ -95,6 +96,7 @@ size_t espr_decompressed_size(char *data, size_t size) {
return dc_size;
}
// Adds the size of every node up, reading decompressed size from compressed records.
void dc_size_cb(Node n, void *dc_size_ptr) {
size_t *dcsp = dc_size_ptr;
switch (n.type) {
@@ -116,6 +118,23 @@ void dc_size_cb(Node n, void *dc_size_ptr) {
}
}
size_t espr_formid_count(char *data, size_t size) {
size_t count = 0;
espr_walk(data, size, formid_count_cb, &count);
return count;
}
/* FormID <-> Record relationship should be bijective. I do not believe
* groups have formids, and every record should have a unique formid,
* otherwise there would be clashes in the id space.
*/
void formid_count_cb(Node n, void *count_ptr) {
size_t *c = count_ptr;
if (n.type == NT_RECORD) {
(*c)++;
}
}
/* Unknown data will be some concatenation of groups and records.
*
* `walk_concat` will call the appropriate walking function