Implement JSON printing function

This commit is contained in:
Aaron Cook 2025-09-20 23:15:04 -05:00
commit 08bb217747
4 changed files with 324 additions and 18 deletions

View file

@ -71,8 +71,8 @@ struct empack_map_struct {
empack_map_pair_t *pairs;
/** Number of key-value pairs expected to be in the map */
uint32_t pair_count;
/** Number of key-value pairs actually in the map */
uint32_t pair_count_real;
/** Parsed count utilized in tree traversal */
uint32_t pairs_parsed;
};
struct empack_array_struct {
@ -80,8 +80,8 @@ struct empack_array_struct {
empack_obj_t *objects;
/** Number of objects expected to be in the array */
uint32_t object_count;
/** Number of objects actually in the array */
uint32_t object_count_real;
/** Parsed count utilized in tree traversal */
uint32_t objects_parsed;
};
struct empack_str_struct {
@ -137,6 +137,11 @@ struct empack_obj_struct {
* parsing. NULL if no parent is present.
*/
empack_obj_t *parent;
/**
* Object that comes immediately after this one in the original Msgpack
* buffer, NULL if last object
*/
empack_obj_t *next;
};
struct empack_map_pair_struct {
@ -173,6 +178,16 @@ struct empack_struct {
uint32_t arena_used;
};
/** Macro for whether the given type is a map */
#define EMPACK_IS_MAP(type) ((type == EMPACK_TYPE_FIXMAP) || \
(type == EMPACK_TYPE_MAP16) || \
(type == EMPACK_TYPE_MAP32))
/** Macro for whether the given type is an array */
#define EMPACK_IS_ARRAY(type) ((type == EMPACK_TYPE_FIXARRAY) || \
(type == EMPACK_TYPE_ARRAY16) || \
(type == EMPACK_TYPE_ARRAY16))
/**
* Initialize an empack struct, allowing it to be used for parsing. Calling this
* on a previously initialzed empack struct will effectively reset it.
@ -213,4 +228,12 @@ empack_status_e empack_parse(empack_t *empack, const void *msgpack, uint32_t len
*/
empack_status_e empack_parse_one(empack_obj_t *object, const void *msgpack, uint32_t *len);
/**
* @returns Number of characters printed excluding the NULL terminator
*/
uint32_t empack_print(empack_t *empack,
void (*print_func)(const char *buf, uint32_t buflen, void *arg),
void *arg,
const char *indent);
#endif /* _EMPACK_H_ */