1 module nbtd.NBTEnd; 2 3 import nbtd; 4 import std.zlib; 5 6 /// Class for indicating the End of a compound 7 class NBTEnd : INBTItem 8 { 9 private: 10 string _name; 11 public: 12 this() 13 { 14 } 15 16 @property NBTType type() { return NBTType.End; } 17 /// Will return 0 18 @property int size() { return 0; } 19 20 /// Name cannot be get 21 @property string name() { throw new Exception("NBTEnd has no name!"); } 22 /// Name cannot be set 23 @property void name(string name) { throw new Exception("NBTEnd can not have a name!"); } 24 25 /// Value cannot be get 26 @property byte value() { throw new Exception("NBTEnd has no value!"); } 27 /// Value cannot be set 28 @property void value(byte value) { throw new Exception("NBTEnd can not have a value!"); } 29 30 /// Will return [0] if hasName is true and [] if hasName is false. 31 ubyte[] encode(bool compressed = true, bool hasName = true) 32 { 33 ubyte[] data; 34 if(hasName) 35 data = [cast(ubyte)0]; 36 else 37 data = []; 38 if(compressed) 39 { 40 return compressGZip(data); 41 } 42 return data; 43 } 44 45 /// Will only check if first byte is 0 if hasName is true 46 void decode(ubyte[] data, bool compressed = true, bool hasName = true) 47 { 48 if(compressed) 49 { 50 data = uncompressGZip(data); 51 } 52 53 if(hasName) 54 assert(data[0] == cast(ubyte)type); 55 } 56 57 /// Will only advance the stream 1 character if hasName is true 58 void read(ref ubyte[] stream, bool hasName = true) 59 { 60 if(hasName) 61 stream = stream[1 .. $]; 62 } 63 64 @property INBTItem dup() 65 { 66 return new NBTEnd(); 67 } 68 69 /// Returns: `"NBTEnd"` 70 override string toString() 71 { 72 return "NBTEnd"; 73 } 74 }