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 LIBCLOD_NBT_H
19#define LIBCLOD_NBT_H
20
21#include <clod/lib.h>
22#include <clod/string.h>
23#include <stdint.h>
24#include <stddef.h>
25
26#define CLOD_NBT_ZERO (uint8_t)(0)
27#define CLOD_NBT_INT8 (uint8_t)(1)
28#define CLOD_NBT_INT16 (uint8_t)(2)
29#define CLOD_NBT_INT32 (uint8_t)(3)
30#define CLOD_NBT_INT64 (uint8_t)(4)
31#define CLOD_NBT_FLOAT32 (uint8_t)(5)
32#define CLOD_NBT_FLOAT64 (uint8_t)(6)
33#define CLOD_NBT_INT8_ARRAY (uint8_t)(7)
34#define CLOD_NBT_INT32_ARRAY (uint8_t)(11)
35#define CLOD_NBT_INT64_ARRAY (uint8_t)(12)
36#define CLOD_NBT_STRING (uint8_t)(8)
37#define CLOD_NBT_LIST (uint8_t)(9)
38#define CLOD_NBT_COMPOUND (uint8_t)(10)
39
40#define CLOD_NBT_ROOT_COMPOUND_INIT ((uint8_t[]){CLOD_NBT_COMPOUND, 0, 0, 0})
41#define CLOD_NBT_ROOT_LIST_INIT(type) ((uint8_t[]){CLOD_NBT_LIST, type, 0, 0, 0, 0})
42
52CLOD_API CLOD_PURE CLOD_NONNULL(1, 2)
54 const uint8_t *restrict payload,
55 const void *end,
56 uint8_t payload_type
57);
58
66CLOD_API CLOD_PURE CLOD_NONNULL(1)
67size_t clod_nbt_tag_size(const uint8_t *restrict tag, const void *end);
68
76CLOD_API CLOD_PURE CLOD_NONNULL(1, 2)
77uint8_t *clod_nbt_tag_payload(const uint8_t *restrict tag, const void *end);
78
86CLOD_API CLOD_PURE CLOD_NONNULL(1, 2)
87struct clod_string clod_nbt_tag_name(const uint8_t *tag, const void *end);
88
97 uint8_t *tag;
99 uint8_t *payload;
101 size_t size;
103 uint8_t type;
105 uint32_t index;
106};
107#define CLOD_NBT_ITER_ZERO { .type = CLOD_NBT_ZERO }
108
122CLOD_API CLOD_USE_RETURN CLOD_NONNULL(1, 2, 4)
124 const uint8_t *restrict payload,
125 const void *end,
126 uint8_t payload_type,
127 struct clod_nbt_iter *iter
128);
129
138CLOD_API CLOD_NONNULL(1, 2)
139uint8_t *clod_nbt_compound_get(
140 const uint8_t *restrict compound,
141 const void *end,
142 struct clod_string name
143);
144
160CLOD_API CLOD_NONNULL(2, 3)
161uint8_t *clod_nbt_compound_add(
162 uint8_t *restrict compound,
163 const void **end,
164 ptrdiff_t *free,
165 struct clod_string name,
166 uint8_t type
167);
168
178CLOD_API CLOD_NONNULL(1, 2, 3)
180 uint8_t *restrict compound,
181 const void **end,
182 ptrdiff_t *free,
183 struct clod_string name
184);
185
197CLOD_API CLOD_NONNULL(2)
199 uint8_t *restrict list,
200 const uint8_t **end,
201 ptrdiff_t *free,
202 uint8_t type,
203 uint32_t length
204);
205
207#endif
bool clod_nbt_iter_next(const uint8_t *restrict payload, const void *end, uint8_t payload_type, struct clod_nbt_iter *iter)
Definition nbt.c:118
size_t clod_nbt_payload_size(const uint8_t *restrict payload, const void *end, uint8_t payload_type)
Definition nbt.c:26
size_t clod_nbt_tag_size(const uint8_t *restrict tag, const void *end)
Definition nbt.c:94
uint8_t * clod_nbt_compound_add(uint8_t *restrict compound, const void **end, ptrdiff_t *free, struct clod_string name, uint8_t type)
Definition nbt.c:281
bool clod_nbt_list_resize(uint8_t *restrict list, const uint8_t **end, ptrdiff_t *free, uint8_t type, uint32_t length)
Definition nbt.c:336
struct clod_string clod_nbt_tag_name(const uint8_t *tag, const void *end)
bool clod_nbt_compound_del(uint8_t *restrict compound, const void **end, ptrdiff_t *free, struct clod_string name)
Definition nbt.c:318
uint8_t * clod_nbt_tag_payload(const uint8_t *restrict tag, const void *end)
Definition nbt.c:102
uint8_t * clod_nbt_compound_get(const uint8_t *restrict compound, const void *end, struct clod_string name)
Definition nbt.c:269
Sized string helpers.
uint32_t index
Definition nbt.h:105
uint8_t * tag
Definition nbt.h:97
size_t size
Definition nbt.h:101
uint8_t type
Definition nbt.h:103
uint8_t * payload
Definition nbt.h:99