1 module nbtd.NBTEnd;
2 
3 import nbtd;
4 import std.zlib;
5 
6 class NBTEnd : INBTItem
7 {
8 private:
9 	string _name;
10 public:
11 	this()
12 	{
13 	}
14 
15 	@property NBTType type() { return NBTType.End; }
16 	@property int size() { return 0; }
17 
18 	@property string name() { throw new Exception("NBTEnd has no name!"); }
19 	@property void name(string name) { throw new Exception("NBTEnd can not have a name!"); }
20 
21 	@property byte value() { throw new Exception("NBTEnd has no value!"); }
22 	@property void value(byte value) { throw new Exception("NBTEnd can not have a value!"); }
23 
24 	ubyte[] encode(bool compressed = true, bool hasName = true)
25 	{
26 		ubyte[] data;
27 		if(hasName)
28 			data = [cast(ubyte)0];
29 		else
30 			data = [];
31 		if(compressed)
32 		{
33 			return compressGZip(data);
34 		}
35 		return data;
36 	}
37 
38 	void decode(ubyte[] data, bool compressed = true, bool hasName = true)
39 	{
40 		if(compressed)
41 		{
42 			data = uncompressGZip(data);
43 		}
44 
45 		if(hasName)
46 			assert(data[0] == cast(ubyte)type);
47 	}
48 
49 	void read(ref ubyte[] stream, bool hasName = true)
50 	{
51 		if(hasName)
52 			stream = stream[1 .. $];
53 	}
54 
55 	@property INBTItem dup()
56 	{
57 		return new NBTEnd();
58 	}
59 
60 	override string toString()
61 	{
62 		return "NBTEnd";
63 	}
64 }