libclod
C library for interacting with NBTs, region files, LOD data and other things.
Loading...
Searching...
No Matches
nbt.h
Go to the documentation of this file.
1
18#ifndef CLOD_NBT_H
19#define CLOD_NBT_H
20
21#include <clod/lib.h>
22#include <clod/big_endian.h>
23#include <clod/sstr.h>
24#include <stddef.h>
25
26static_assert(CHAR_BIT == 8);
27
28#define CLOD_NBT_ZERO (char)(0)
29#define CLOD_NBT_INT8 (char)(1)
30#define CLOD_NBT_INT16 (char)(2)
31#define CLOD_NBT_INT32 (char)(3)
32#define CLOD_NBT_INT64 (char)(4)
33#define CLOD_NBT_FLOAT32 (char)(5)
34#define CLOD_NBT_FLOAT64 (char)(6)
35#define CLOD_NBT_INT8_ARRAY (char)(7)
36#define CLOD_NBT_INT32_ARRAY (char)(11)
37#define CLOD_NBT_INT64_ARRAY (char)(12)
38#define CLOD_NBT_STRING (char)(8)
39#define CLOD_NBT_LIST (char)(9)
40#define CLOD_NBT_COMPOUND (char)(10)
41
42#define CLOD_NBT_ROOT_COMPOUND_INIT ((char[]){CLOD_NBT_COMPOUND, 0, 0, 0})
43#define CLOD_NBT_ROOT_LIST_INIT(type) ((char[]){CLOD_NBT_LIST, type, 0, 0, 0, 0})
44
54CLOD_API CLOD_PURE CLOD_NONNULL(1, 2)
56 const char *restrict payload,
57 const void *end,
58 char payload_type
59);
60
68CLOD_API CLOD_PURE CLOD_NONNULL(1)
69size_t clod_nbt_tag_size(const char *restrict tag, const void *end);
70
78CLOD_API CLOD_PURE CLOD_NONNULL(1, 2)
79char *clod_nbt_tag_payload(const char *restrict tag, const void *end);
80
88CLOD_API CLOD_PURE CLOD_NONNULL(1, 2)
89clod_sstr clod_nbt_tag_name(const char *tag, const void *end);
90
99 char *tag;
101 char *payload;
103 size_t size;
105 char type;
107 uint32_t index;
108};
109#define CLOD_NBT_ITER_ZERO { .type = CLOD_NBT_ZERO }
110
124CLOD_API CLOD_USE_RETURN CLOD_NONNULL(1, 2, 4)
126 const char *restrict payload,
127 const void *end,
128 char payload_type,
129 struct clod_nbt_iter *iter
130);
131
140CLOD_API CLOD_NONNULL(1, 2)
142 const char *restrict compound,
143 const void *end,
144 clod_sstr name
145);
146
162CLOD_API CLOD_NONNULL(2, 3)
164 char *restrict compound,
165 const void **end,
166 ptrdiff_t *free,
167 clod_sstr name,
168 char type
169);
170
180CLOD_API CLOD_NONNULL(1, 2, 3)
182 char *restrict compound,
183 const void **end,
184 ptrdiff_t *free,
185 clod_sstr name
186);
187
199CLOD_API CLOD_NONNULL(2)
201 char *restrict list,
202 const char **end,
203 ptrdiff_t *free,
204 char type,
205 uint32_t length
206);
207
209#endif
Methods for big-endian encoding numbers.
char * clod_nbt_compound_get(const char *restrict compound, const void *end, clod_sstr name)
Definition nbt.c:269
bool clod_nbt_iter_next(const char *restrict payload, const void *end, char payload_type, struct clod_nbt_iter *iter)
Definition nbt.c:118
bool clod_nbt_list_resize(char *restrict list, const char **end, ptrdiff_t *free, char type, uint32_t length)
Definition nbt.c:336
bool clod_nbt_compound_del(char *restrict compound, const void **end, ptrdiff_t *free, clod_sstr name)
Definition nbt.c:318
char * clod_nbt_compound_add(char *restrict compound, const void **end, ptrdiff_t *free, clod_sstr name, char type)
Definition nbt.c:281
clod_sstr clod_nbt_tag_name(const char *tag, const void *end)
size_t clod_nbt_payload_size(const char *restrict payload, const void *end, char payload_type)
Definition nbt.c:26
char * clod_nbt_tag_payload(const char *restrict tag, const void *end)
Definition nbt.c:102
size_t clod_nbt_tag_size(const char *restrict tag, const void *end)
Definition nbt.c:94
Sized string helpers.
char * tag
Definition nbt.h:99
uint32_t index
Definition nbt.h:107
size_t size
Definition nbt.h:103
char type
Definition nbt.h:105
char * payload
Definition nbt.h:101