Tree builder not crashing, need to check functional correctness.

This commit is contained in:
2022-09-08 12:54:37 +10:00
parent 2d5c85f0e8
commit abc9cf6a61
3 changed files with 70 additions and 16 deletions

View File

@@ -24,6 +24,9 @@
*/
#include <stdint.h>
#undef NDEBUG
#include <assert.h>
#define NDEBUG
#include "msh.h"
// Guards for C++ usage
@@ -320,6 +323,13 @@ extern "C" {
return rth2rt[uint32_t_msh(type, RT_HASH_BITS, RT_HASH_SEED)];
}
// Updates a sized_buf after using `size` bytes
inline void sized_buf_update(struct sized_buf *sb, size_t size) {
assert(sb->size >= size);
sb->data += size;
sb->size -= size;
}
/* `espr_walk` walks through the tree structure of the esp/esm binary
* data starting at `data` of `size` bytes.
*
@@ -329,7 +339,12 @@ extern "C" {
* Data is walked sequentially. Nodes passed to `cb` will be strictly
* increasing in terms of memory location within the buffer.
*/
void espr_walk(char *data, size_t size, struct walker_callbacks cb);
void espr_walk(
char *data,
size_t size,
struct walker_callbacks cb,
void *from_parent
);
/* `espr_print` prints the header of every group and record in the given
* esp/esm binary data.
@@ -355,15 +370,26 @@ extern "C" {
// Calculates the size of a MetaNode tree constructed over the esp/esm
// for which the stats were generated.
inline size_t espr_tree_size(struct esp_stats stats) {
return sizeof(MetaNode) * espr_node_count(stats);
return sizeof(MetaNode) * ((size_t)espr_node_count(stats) + 1);
}
/* Copies the data from `data` to `buf` decompressing compressed fields
* as it does so. buf_size should be the value returned from
* `espr_decompressed_size`, and `buf` should be at least of that size.
*/
void espr_decompress(char *data, size_t size, char *buf, size_t buf_size);
void espr_decompress(
char *data,
size_t size,
char *buf,
size_t buf_size
);
/* Constructs a MetaNode tree in `tree` over the esp/esm data in `in`.
*
* MetaNode trees allows for easier programatic traversal of the esp/esm
* data, and also allow for modifications that add, remove, or change
* the size of groups/records/fields.
*/
MetaNode *espr_create_tree(struct sized_buf in, struct sized_buf tree);
// End C++ guard