lib/nbt: Yesterday’s progress of implementing more of the functions in the header

Soda
BodgeMaster 2022-10-04 02:39:58 +02:00
parent 4c4366f7e6
commit 2d2b67373c
2 changed files with 33 additions and 13 deletions

View File

@ -873,7 +873,8 @@ namespace NBT {
}
Helper::writeInt32(rawData, this->tags.size());
for (int32_t i=0; i<this->tags.size(); i++) {
// unsigned integer bc of compiler warning (shouldn't matter)
for (uint32_t i=0; i<this->tags.size(); i++) {
ErrorOrVoid result = this->tags.at(i)->serializeWithoutHeader(rawData);
if (result.isError) {
return result;
@ -884,28 +885,47 @@ namespace NBT {
}
ErrorOr<Generic*> List::getElementPointer(uint64_t position) {
#pragma message("TODO: Implement.")
return ErrorOr<Generic*>(true, ErrorCodes::UNIMPLEMENTED);
if (this->tags.size() <= position) {
return ErrorOr<Generic*>(true, ErrorCodes::OUT_OF_RANGE);
}
return ErrorOr<Generic*>(this->tags.at(position));
}
ErrorOrVoid List::setElementPointerAt(uint64_t position, Generic*) {
#pragma message("TODO: Implement.")
return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED);
ErrorOrVoid List::setElementPointerAt(uint64_t position, Generic* pointer) {
if (this->tags.size() <= position) {
return ErrorOrVoid(true, ErrorCodes::OUT_OF_RANGE);
}
ErrorOrVoid List::appendPointer(Generic*) {
#pragma message("TODO: Implement.")
return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED);
if (pointer->getTagType() != this->containedType) {
return ErrorOrVoid(true, ErrorCodes::INVALID_TYPE);
}
delete this->tags[position];
this->tags[position] = pointer;
return ErrorOrVoid();
}
ErrorOrVoid List::appendPointer(Generic* pointer) {
if (pointer->getTagType() != this->containedType) {
return ErrorOrVoid(true, ErrorCodes::INVALID_TYPE);
}
this->tags.push_back(pointer);
return ErrorOrVoid();
}
ErrorOrVoid List::deleteElement(uint64_t position) {
#pragma message("TODO: Implement.")
// Step 1) delete pointer
// Step 2) remove element from vector
return ErrorOrVoid(true, ErrorCodes::UNIMPLEMENTED);
}
uint64_t List::length() {
#pragma message("TODO: Implement.")
return 0;
return this->tags.size();
}
}

View File

@ -235,8 +235,8 @@ namespace NBT {
ErrorOrVoid serializeWithoutHeader(std::vector<uint8_t>* rawData) override;
ErrorOr<Generic*> getElementPointer(uint64_t position);
ErrorOrVoid setElementPointerAt(uint64_t position, Generic*);
ErrorOrVoid appendPointer(Generic*);
ErrorOrVoid setElementPointerAt(uint64_t position, Generic* pointer);
ErrorOrVoid appendPointer(Generic* pointer);
ErrorOrVoid deleteElement(uint64_t position);
uint64_t length();
};