forked from Celisium/libnbt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbt.h
208 lines (177 loc) · 4.88 KB
/
nbt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
libnbt
Written in 2019 by IDidMakeThat
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along
with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#ifndef NBT_H
#define NBT_H
#ifdef __cplusplus
extern "C" {
#endif
#define DllImport __declspec(dllimport)
#define LIBNBT_VERSION 10
#define LIBNBT_NBT_VERSION 19133
#include <stddef.h>
#ifndef NBT_NO_STDLIB
#include <stdlib.h>
#include <string.h>
#define NBT_MALLOC malloc
#define NBT_REALLOC realloc
#define NBT_FREE free
#define NBT_MEMCPY memcpy
#define NBT_MEMCMP memcmp
#endif
#ifndef NBT_NO_STDINT
#include <stdint.h>
#endif
#ifdef NBT_OWN_ZLIB
#include NBT_OWN_ZLIB
#else
#include "miniz.h"
#endif
#ifndef Z_DEFAULT_WINDOW_BITS
#define Z_DEFAULT_WINDOW_BITS 15
#endif
#ifndef NBT_BUFFER_SIZE
#define NBT_BUFFER_SIZE 32768
#endif
#define NBT_COMPRESSION_LEVEL 9
typedef enum {
NBT_TYPE_END,
NBT_TYPE_BYTE,
NBT_TYPE_SHORT,
NBT_TYPE_INT,
NBT_TYPE_LONG,
NBT_TYPE_FLOAT,
NBT_TYPE_DOUBLE,
NBT_TYPE_BYTE_ARRAY,
NBT_TYPE_STRING,
NBT_TYPE_LIST,
NBT_TYPE_COMPOUND,
NBT_TYPE_INT_ARRAY,
NBT_TYPE_LONG_ARRAY,
NBT_TYPE_SHORT_ARRAY,
NBT_TYPE_FLOAT_ARRAY,
NBT_TYPE_DOUBLE_ARRAY,
NBT_TYPE_STRING_ARRAY,
NBT_NO_OVERRIDE // Only used internally.
} nbt_tag_type_t;
typedef struct nbt_tag_t nbt_tag_t;
struct nbt_tag_t {
nbt_tag_type_t type;
char* name;
size_t name_size;
union {
struct {
int8_t value;
} tag_byte;
struct {
int16_t value;
} tag_short;
struct {
int32_t value;
} tag_int;
struct {
int64_t value;
} tag_long;
struct {
float value;
} tag_float;
struct {
double value;
} tag_double;
struct {
int8_t* value;
size_t size;
} tag_byte_array;
struct {
char* value;
size_t size;
} tag_string;
struct {
nbt_tag_t** value;
nbt_tag_type_t type;
size_t size;
} tag_list;
struct {
nbt_tag_t** value;
size_t size;
} tag_compound;
struct {
int32_t* value;
size_t size;
} tag_int_array;
struct {
int64_t* value;
size_t size;
} tag_long_array;
struct {
int16_t* value;
size_t size;
} tag_short_array;
struct {
float* value;
size_t size;
} tag_float_array;
struct {
double* value;
size_t size;
} tag_double_array;
struct {
nbt_tag_t** value;
size_t size;
} tag_string_array;
};
};
typedef struct {
size_t (*read)(void* userdata, uint8_t* data, size_t size);
void* userdata;
} nbt_reader_t;
typedef struct {
size_t (*write)(void* userdata, uint8_t* data, size_t size);
void* userdata;
} nbt_writer_t;
typedef enum {
NBT_PARSE_FLAG_USE_GZIP = 1,
NBT_PARSE_FLAG_USE_ZLIB = 2,
NBT_PARSE_FLAG_USE_RAW = 3,
} nbt_parse_flags_t;
typedef enum {
NBT_WRITE_FLAG_USE_GZIP = 1,
NBT_WRITE_FLAG_USE_ZLIB = 2,
NBT_WRITE_FLAG_USE_RAW = 3
} nbt_write_flags_t;
DllImport nbt_tag_t* nbt_parse(nbt_reader_t reader, int parse_flags);
DllImport void nbt_write(nbt_writer_t writer, nbt_tag_t* tag, int write_flags);
DllImport nbt_tag_t* nbt_new_tag_byte(int8_t value);
DllImport nbt_tag_t* nbt_new_tag_short(int16_t value);
DllImport nbt_tag_t* nbt_new_tag_int(int32_t value);
DllImport nbt_tag_t* nbt_new_tag_long(int64_t value);
DllImport nbt_tag_t* nbt_new_tag_float(float value);
DllImport nbt_tag_t* nbt_new_tag_double(double value);
DllImport nbt_tag_t* nbt_new_tag_byte_array(int8_t* value, size_t size);
DllImport nbt_tag_t* nbt_new_tag_string(const char* value);
DllImport nbt_tag_t* nbt_new_tag_string0(const char* value, size_t size);
DllImport nbt_tag_t* nbt_new_tag_list(nbt_tag_type_t type);
DllImport nbt_tag_t* nbt_new_tag_compound(void);
DllImport nbt_tag_t* nbt_new_tag_int_array(int32_t* value, size_t size);
DllImport nbt_tag_t* nbt_new_tag_long_array(int64_t* value, size_t size);
DllImport nbt_tag_t* nbt_new_tag_short_array(int16_t* value, size_t size);
DllImport nbt_tag_t* nbt_new_tag_float_array(float* value, size_t size);
DllImport nbt_tag_t* nbt_new_tag_double_array(double* value, size_t size);
DllImport nbt_tag_t* nbt_new_tag_string_array(char** value, size_t size);
DllImport void nbt_set_tag_name(nbt_tag_t* tag, const char* name);
DllImport void nbt_set_tag_name0(nbt_tag_t* tag, const char* name, size_t size);
DllImport void nbt_tag_list_append(nbt_tag_t* list, nbt_tag_t* value);
DllImport nbt_tag_t* nbt_tag_list_get(nbt_tag_t* tag, size_t index);
DllImport void nbt_tag_compound_append(nbt_tag_t* compound, nbt_tag_t* value);
DllImport nbt_tag_t* nbt_tag_compound_get(nbt_tag_t* tag, const char* key);
DllImport void nbt_free_tag(nbt_tag_t* tag);
#ifdef __cplusplus
}
#endif
#endif