forked from spoutn1k/mcmap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nbt.h
71 lines (63 loc) · 1.5 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
#ifndef _NBT_H_
#define _NBT_H_
#include <cstring>
#include <map>
#include <list>
#include <string>
#include "helper.h"
using std::string;
using std::map;
using std::list;
class NBT_Tag;
typedef map<string, NBT_Tag *> tagmap;
enum TagType {
tagUnknown = 0, // Tag_End is not made available, so 0 should never be in any list of available elements
tagByte = 1,
tagShort = 2,
tagInt = 3,
tagLong = 4,
tagFloat = 5,
tagDouble = 6,
tagByteArray = 7,
tagString = 8,
tagList = 9,
tagCompound = 10
};
class NBT_Tag
{
friend class NBT;
private:
tagmap *_elems;
list<NBT_Tag *> *_list;
TagType _type;
uint8_t *_data;
uint32_t _len;
explicit NBT_Tag(uint8_t* &position, const uint8_t *end, string &name);
explicit NBT_Tag(uint8_t* &position, const uint8_t *end, TagType type);
explicit NBT_Tag();
void parseData(uint8_t* &position, const uint8_t *end, string *name = NULL);
public:
bool getCompound(const string name, NBT_Tag* &compound);
bool getShort(const string name, int16_t &value);
bool getInt(const string name, int32_t &value);
bool getLong(const string name, int64_t &value);
bool getByteArray(const string name, uint8_t* &data, int &len);
TagType getType() {
return _type;
}
virtual ~NBT_Tag();
};
class NBT : public NBT_Tag
{
private:
uint8_t *_blob;
char *_filename;
size_t _bloblen;
public:
explicit NBT(const char *file, bool &success);
explicit NBT(uint8_t * const file, const size_t len, const bool shared, bool &success);
explicit NBT();
virtual ~NBT();
//bool save();
};
#endif