nightly commit + working on NBT

v1
Brett 2023-07-24 03:40:09 -04:00
parent 983d7de820
commit c3aab51030
2 changed files with 37 additions and 0 deletions

View File

@ -7,6 +7,8 @@
#ifndef BLT_TESTS_NBT_H #ifndef BLT_TESTS_NBT_H
#define BLT_TESTS_NBT_H #define BLT_TESTS_NBT_H
#include <utility>
#include "blt/std/format.h" #include "blt/std/format.h"
#include "blt/std/filesystem.h" #include "blt/std/filesystem.h"
@ -31,6 +33,29 @@ namespace blt::nbt {
LONG_ARRAY = 12 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 { class NBTDecoder {
private: private:
blt::fs::block_reader* m_reader; blt::fs::block_reader* m_reader;

View File

@ -27,4 +27,16 @@ namespace blt::nbt {
delete[] str.characters; delete[] str.characters;
return strOut; 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');
}
} }