Split out sized buffer type and added tests. Modified reader to better utilise sized buffer. Debugged and working at least as well as previous.
This commit is contained in:
@@ -24,10 +24,13 @@
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
#define NDEBUG
|
||||
|
||||
#include "msh.h"
|
||||
#include "SizedBuffer.h"
|
||||
|
||||
// Guards for C++ usage
|
||||
#ifdef __cplusplus
|
||||
@@ -76,6 +79,7 @@ extern "C" {
|
||||
typedef struct field Field;
|
||||
typedef struct meta_node MetaNode;
|
||||
typedef struct meta_tree MetaTree;
|
||||
typedef struct esp_stats ESPStats;
|
||||
|
||||
|
||||
//
|
||||
@@ -113,11 +117,6 @@ extern "C" {
|
||||
char _pad[4];
|
||||
};
|
||||
|
||||
struct sized_buf {
|
||||
char *data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
//
|
||||
// === ENUMS ===
|
||||
//
|
||||
@@ -334,13 +333,6 @@ 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.
|
||||
*
|
||||
@@ -351,7 +343,7 @@ extern "C" {
|
||||
* increasing in terms of memory location within the buffer.
|
||||
*/
|
||||
void espr_walk(
|
||||
struct sized_buf esp,
|
||||
SizedBuf esp,
|
||||
struct walker_callbacks cb,
|
||||
void *from_parent
|
||||
);
|
||||
@@ -359,13 +351,13 @@ extern "C" {
|
||||
/* `espr_print` prints the header of every group and record in the given
|
||||
* esp/esm binary data.
|
||||
*/
|
||||
void espr_print(struct sized_buf esp);
|
||||
void espr_print(SizedBuf esp);
|
||||
|
||||
/* Calculates the number of groups and records in the esp/esm file and
|
||||
* the size of the esp/esm if all of the compressed records were
|
||||
* decompressed.
|
||||
*/
|
||||
struct esp_stats espr_stats(struct sized_buf esp);
|
||||
struct esp_stats espr_stats(SizedBuf esp);
|
||||
|
||||
// Calculates the number of formid's in an esm/esp from the stats
|
||||
inline uint32_t espr_formid_count(struct esp_stats stats) {
|
||||
@@ -387,10 +379,7 @@ extern "C" {
|
||||
* 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(
|
||||
struct sized_buf esp,
|
||||
struct sized_buf decom
|
||||
);
|
||||
void espr_decompress(SizedBuf esp, SizedBuf decom);
|
||||
|
||||
/* Constructs a MetaNode tree in `tree` over the esp/esm data in `in`.
|
||||
*
|
||||
@@ -398,13 +387,13 @@ extern "C" {
|
||||
* data, and also allow for modifications that add, remove, or change
|
||||
* the size of groups/records/fields.
|
||||
*/
|
||||
MetaTree espr_create_tree(struct sized_buf in, struct sized_buf tree);
|
||||
MetaTree espr_create_tree(SizedBuf in, SizedBuf tree);
|
||||
|
||||
void espr_meta_walk(MetaTree tree, struct meta_callbacks cb);
|
||||
|
||||
void espr_meta_node_walk(MetaNode *m, struct meta_callbacks cb);
|
||||
|
||||
void espr_serialize(MetaTree tree, struct sized_buf out);
|
||||
void espr_serialize(MetaTree tree, SizedBuf out);
|
||||
|
||||
// End C++ guard
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user