diff --git a/include/blt/nbt/nbt.h b/include/blt/nbt/nbt.h index 9321091..f68f319 100755 --- a/include/blt/nbt/nbt.h +++ b/include/blt/nbt/nbt.h @@ -7,6 +7,8 @@ #ifndef BLT_TESTS_NBT_H #define BLT_TESTS_NBT_H +#include + #include "blt/std/format.h" #include "blt/std/filesystem.h" @@ -31,6 +33,29 @@ namespace blt::nbt { LONG_ARRAY = 12 }; + class tag { + public: + virtual void writePayload(std::fstream& out) = 0; + virtual void readPayload(std::fstream& in) = 0; + }; + + class named_tag : public tag { + private: + std::string name; + public: + explicit named_tag(std::string name): name(std::move(name)) {} + named_tag() = default; + void writeName(std::fstream& out); + void readName(std::fstream& in); + }; + + class tag_end : public tag { + public: + void writePayload(std::fstream& out) final; + // nothing to read + void readPayload(std::fstream& in) final {} + }; + class NBTDecoder { private: blt::fs::block_reader* m_reader; diff --git a/src/blt/nbt/nbt.cpp b/src/blt/nbt/nbt.cpp index 4dc259b..9653f1b 100755 --- a/src/blt/nbt/nbt.cpp +++ b/src/blt/nbt/nbt.cpp @@ -27,4 +27,16 @@ namespace blt::nbt { delete[] str.characters; return strOut; } + + void named_tag::writeName(std::fstream& out) { + writeUTF8String(out, name); + } + + void named_tag::readName(std::fstream& in) { + name = readUTF8String(in); + } + + void tag_end::writePayload(std::fstream& out) { + out.put('\0'); + } } \ No newline at end of file