From fc2caf3bc0cc3124ade91572e856b2f9a4a93c28 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Sat, 1 Oct 2022 04:51:53 +0200 Subject: [PATCH 1/2] lib/nbt: Implement more member functions for tag types --- src/lib/nbt.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++++++- src/lib/nbt.hpp | 2 +- 2 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/lib/nbt.cpp b/src/lib/nbt.cpp index 9e66fee..22124f6 100644 --- a/src/lib/nbt.cpp +++ b/src/lib/nbt.cpp @@ -840,8 +840,99 @@ namespace NBT { } ErrorOrVoid Int8Array::removeElement(uint64_t position) { - //TODO: implement + #pragma message("TODO: implement") //this->data.erase(position); + return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); + } + + String::String() { + this->type = TagType::STRING; + } + + String::String(tiny_utf8::string name, tiny_utf8::string value) { + this->type = TagType::STRING; + this->name = name; + this->value = value; + } + + ErrorOrVoid String::toRawData(std::vector* rawData) { + rawData->push_back(this->type); + + if (Helper::writeString(rawData, this->name).isError) { + return ErrorOrVoid(true, ErrorCodes::OVERRUN); + } + + return Helper::writeString(rawData, this->value); + } + + tiny_utf8::string String::getValue() { + return this->value; + } + + void String::setValue(tiny_utf8::string value) { + this->value = value; + } + + List::List() { + this->type = TagType::LIST; + this->containedType = TagType::INVALID; + } + + List::List(tiny_utf8::string name, uint8_t type) { + this->type = TagType::LIST; + this->name = name; + this->containedType = type; + } + + // WARNING: The pointers inside the vector are automatically cleaned + // up upon deletion of the List object. Do not retain a copy of them + // elsewhere and especially do not delete them externally. + List::List(tiny_utf8::string name, std::vector data) { + this->type = TagType::LIST; + this->name = name; + this->tags = data; + + if (data.size() == 0) { + this->containedType = TagType::END; + } else { + this->containedType = data.at(0)->getTagType(); + } + } + + List::~List() { + for (uint64_t i=0; itags.size(); i++) { + delete this->tags.at(i); + } + } + + ErrorOrVoid toRawData(std::vector* rawData) { + #pragma message("TODO: Implement.") + return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); + } + + ErrorOr getElementPointer(uint64_t position) { + #pragma message("TODO: Implement.") + return ErrorOr(true, ErrorCodes::UNIMPLEMENTED); + } + + ErrorOrVoid setElementPointerAt(uint64_t position, Generic*) { + #pragma message("TODO: Implement.") + return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); + } + + ErrorOrVoid appendPointer(Generic*) { + #pragma message("TODO: Implement.") + return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); + } + + ErrorOrVoid deleteElement(uint64_t position) { + #pragma message("TODO: Implement.") + return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); + } + + uint64_t length() { + #pragma message("TODO: Implement.") + return 0; } } diff --git a/src/lib/nbt.hpp b/src/lib/nbt.hpp index f9a3887..0635d44 100644 --- a/src/lib/nbt.hpp +++ b/src/lib/nbt.hpp @@ -220,7 +220,7 @@ namespace NBT { class List: public Generic { private: std::vector tags; - uint8_t type; + uint8_t containedType; public: List(); List(tiny_utf8::string name, uint8_t type); From 8b1491c311009b5f6a0cd9061b8e055b22163d27 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Sat, 1 Oct 2022 04:57:45 +0200 Subject: [PATCH 2/2] lib/nbt: Add missing class prefix to function names --- src/lib/nbt.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/nbt.cpp b/src/lib/nbt.cpp index 22124f6..393a92e 100644 --- a/src/lib/nbt.cpp +++ b/src/lib/nbt.cpp @@ -905,32 +905,32 @@ namespace NBT { } } - ErrorOrVoid toRawData(std::vector* rawData) { + ErrorOrVoid List::toRawData(std::vector* rawData) { #pragma message("TODO: Implement.") return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); } - ErrorOr getElementPointer(uint64_t position) { + ErrorOr List::getElementPointer(uint64_t position) { #pragma message("TODO: Implement.") return ErrorOr(true, ErrorCodes::UNIMPLEMENTED); } - ErrorOrVoid setElementPointerAt(uint64_t position, Generic*) { + ErrorOrVoid List::setElementPointerAt(uint64_t position, Generic*) { #pragma message("TODO: Implement.") return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); } - ErrorOrVoid appendPointer(Generic*) { + ErrorOrVoid List::appendPointer(Generic*) { #pragma message("TODO: Implement.") return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); } - ErrorOrVoid deleteElement(uint64_t position) { + ErrorOrVoid List::deleteElement(uint64_t position) { #pragma message("TODO: Implement.") return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED); } - uint64_t length() { + uint64_t List::length() { #pragma message("TODO: Implement.") return 0; }