basin/include/basin/nbt.h

73 lines
1.6 KiB
C
Raw Normal View History

2019-05-02 08:09:24 +00:00
#ifndef BASIN_NBT_H_
#define BASIN_NBT_H_
2016-06-24 04:41:14 +00:00
2019-04-14 22:57:59 +00:00
#include <avuna/hash.h>
#include <avuna/pmem.h>
2016-06-24 04:41:14 +00:00
#include <stdlib.h>
#include <stdint.h>
#define NBT_TAG_END 0
#define NBT_TAG_BYTE 1
#define NBT_TAG_SHORT 2
#define NBT_TAG_INT 3
#define NBT_TAG_LONG 4
#define NBT_TAG_FLOAT 5
#define NBT_TAG_DOUBLE 6
#define NBT_TAG_BYTEARRAY 7
#define NBT_TAG_STRING 8
#define NBT_TAG_LIST 9
#define NBT_TAG_COMPOUND 10
#define NBT_TAG_INTARRAY 11
2019-04-14 22:57:59 +00:00
#define NBT_TAG_LONGARRAY 12
2016-06-24 04:41:14 +00:00
union nbt_data {
2019-05-01 10:03:13 +00:00
signed char nbt_byte;
int16_t nbt_short;
int32_t nbt_int;
int64_t nbt_long;
float nbt_float;
double nbt_double;
struct {
int32_t len;
unsigned char* data;
} nbt_bytearray;
char* nbt_string;
struct {
unsigned char type;
int32_t count;
} nbt_list;
struct {
int32_t count;
int32_t* ints;
} nbt_intarray;
struct {
int32_t count;
int64_t* longs;
} nbt_longarray;
2016-06-24 04:41:14 +00:00
};
struct nbt_tag {
2019-05-01 10:03:13 +00:00
unsigned char id;
char* name;
struct hashmap* children;
struct llist* children_list;
union nbt_data data;
struct mempool* pool;
2016-06-24 04:41:14 +00:00
};
2019-04-14 22:57:59 +00:00
ssize_t nbt_decompress(struct mempool* pool, void* data, size_t size, void** dest);
2019-04-14 22:57:59 +00:00
struct nbt_tag* nbt_clone(struct mempool* pool, struct nbt_tag* nbt);
2016-06-24 04:41:14 +00:00
2019-04-14 22:57:59 +00:00
struct nbt_tag* nbt_get(struct nbt_tag* nbt, char* name);
2016-06-24 04:41:14 +00:00
2019-04-14 22:57:59 +00:00
ssize_t nbt_read(struct mempool* pool, struct nbt_tag** root, unsigned char* buffer, size_t buflen);
2016-08-16 07:18:30 +00:00
2019-04-14 22:57:59 +00:00
ssize_t nbt_write(struct nbt_tag* root, unsigned char* buffer, size_t buflen);
2016-06-24 04:41:14 +00:00
struct nbt_tag* nbt_new(struct mempool* pool, uint8_t type);
void nbt_put(struct nbt_tag* parent, struct nbt_tag* child);
2019-05-02 08:09:24 +00:00
#endif /* BASIN_NBT_H_ */