From 962f5efdf1af9f07395c28df7a2181733e3e5125 Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Sat, 3 Feb 2024 16:58:23 -0600 Subject: add lists --- src/nbt.internal.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/nbt.internal.h (limited to 'src/nbt.internal.h') diff --git a/src/nbt.internal.h b/src/nbt.internal.h new file mode 100644 index 0000000..88f636b --- /dev/null +++ b/src/nbt.internal.h @@ -0,0 +1,78 @@ +#ifndef LIBWORLD_NBT_INTERNAL_H_INCLUDED +#define LIBWORLD_NBT_INTERNAL_H_INCLUDED + +#include "nbt.h" +#include "nbt/nbtht.internal.h" + +typedef struct { + size_t len; + nbt_byte_t *data; +} nbt__byte_array_t; + +typedef struct { + size_t len; + nbt_int_t *data; +} nbt__int_array_t; + +typedef struct { + size_t len; + nbt_long_t *data; +} nbt__long_array_t; + +typedef struct { + size_t len; + char *data; +} nbt__string_t; + +typedef struct nbt__compound_tag { + nbt__ht_t *hash; +} nbt__compound_t; + +typedef struct nbt__list_tag { + size_t cap, len; + nbt_tag_t **ptags; +} nbt__list_t; + +typedef union { + nbt_byte_t nbt_byte; + nbt_short_t nbt_short; + nbt_int_t nbt_int; + nbt_long_t nbt_long; + + nbt_float_t nbt_float; + nbt_double_t nbt_double; + + nbt__byte_array_t nbt_byte_array; + + nbt__string_t nbt_string; + + nbt__list_t nbt_list; + nbt__compound_t nbt_compound; + + nbt__int_array_t nbt_int_array; + nbt__long_array_t nbt_long_array; +} nbt__any_t; + +struct nbt__tag_tag { + size_t ref; + nbt_type_t type; + nbt__any_t value; +}; + +/* a named tag */ +typedef struct { + nbt_tag_t tag; + + size_t name_length; + char *name; /* nullable if there is no name (will be written as if the name is empty) */ +} nbt__ntag_t; + +#define NBT__CHECK_TYPE(_tag, _t, _r, ...) do { \ + if (!(_tag) || (_tag)->type != _t) { _r(__VA_ARGS__); } \ +} while (0) + +/* functions */ + +void nbt__tag_free(nbt_tag_t *tag); + +#endif /* include guard */ -- cgit v1.2.3-70-g09d2