From ad291ee77dda3a65d55f106e472f840b7002ed16 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Thu, 15 Sep 2022 02:00:07 +0200 Subject: [PATCH] lib/nbt: Capitalize NBT::Helper because I feel like it --- src/lib/nbt.cpp | 68 ++++++++++++++++++++++++------------------------- src/lib/nbt.hpp | 2 +- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/lib/nbt.cpp b/src/lib/nbt.cpp index ba80d7e..4782ad9 100644 --- a/src/lib/nbt.cpp +++ b/src/lib/nbt.cpp @@ -36,7 +36,7 @@ #endif namespace NBT { - namespace helper { + namespace Helper { ErrorOr readInt8(uint8_t data[], uint64_t dataSize, uint64_t currentPosition) { if (currentPosition>=dataSize) return ErrorOr(true, ErrorCodes::OUT_OF_RANGE); return ErrorOr((int8_t) data[currentPosition]); @@ -92,7 +92,7 @@ namespace NBT { *(valueAsBytes+2) = data[currentPosition+1]; *(valueAsBytes+3) = data[currentPosition]; #else - #error "NBT::helper::readFloat: An implementation for your endianness is unavailable." + #error "NBT::Helper::readFloat: An implementation for your endianness is unavailable." #endif #endif float dereferencedValue = *value; @@ -126,7 +126,7 @@ namespace NBT { *(valueAsBytes+6) = data[currentPosition+1]; *(valueAsBytes+7) = data[currentPosition]; #else - #error "NBT::helper::readDouble: An implementation for your endianness is unavailable." + #error "NBT::Helper::readDouble: An implementation for your endianness is unavailable." #endif #endif double dereferencedValue = *value; @@ -232,7 +232,7 @@ namespace NBT { destination->push_back(*(valueAsBytes+1)); destination->push_back(*valueAsBytes); #else - #error "NBT::helper::writeInt16: An implementation for your endianness is unavailable." + #error "NBT::Helper::writeInt16: An implementation for your endianness is unavailable." #endif #endif delete value; @@ -255,7 +255,7 @@ namespace NBT { destination->push_back(*(valueAsBytes+1)); destination->push_back(*valueAsBytes); #else - #error "NBT::helper::writeInt16: An implementation for your endianness is unavailable." + #error "NBT::Helper::writeInt16: An implementation for your endianness is unavailable." #endif #endif delete value; @@ -286,7 +286,7 @@ namespace NBT { destination->push_back(*(valueAsBytes+1)); destination->push_back(*valueAsBytes); #else - #error "NBT::helper::writeInt16: An implementation for your endianness is unavailable." + #error "NBT::Helper::writeInt16: An implementation for your endianness is unavailable." #endif #endif delete value; @@ -309,7 +309,7 @@ namespace NBT { destination->push_back(*(valueAsBytes+1)); destination->push_back(*valueAsBytes); #else - #error "NBT::helper::writeInt16: An implementation for your endianness is unavailable." + #error "NBT::Helper::writeInt16: An implementation for your endianness is unavailable." #endif #endif delete value; @@ -340,7 +340,7 @@ namespace NBT { destination->push_back(*(valueAsBytes+1)); destination->push_back(*valueAsBytes); #else - #error "NBT::helper::writeInt16: An implementation for your endianness is unavailable." + #error "NBT::Helper::writeInt16: An implementation for your endianness is unavailable." #endif #endif delete value; @@ -363,7 +363,7 @@ namespace NBT { void writeString(std::vector* destination, tiny_utf8::string data) { ErrorOr> exportedString = JavaCompat::exportJavaString(data); if(exportedString.isError){ - std::cerr << "NBT::helpers::writeString encountered an error: " << (int) exportedString.errorCode << std::endl; + std::cerr << "NBT::Helpers::writeString encountered an error: " << (int) exportedString.errorCode << std::endl; std::abort(); } *destination = exportedString.value; @@ -426,7 +426,7 @@ namespace NBT { // deal with end tag before trying to access the name if (nextTag == TagType::END) return ErrorOr(1); - ErrorOr nameSize = helper::readInt16(data, dataSize, currentPosition+1); + ErrorOr nameSize = Helper::readInt16(data, dataSize, currentPosition+1); if (nameSize.isError) { return ErrorOr(true, nameSize.errorCode); } @@ -446,28 +446,28 @@ namespace NBT { case TagType::DOUBLE: return ErrorOr(prefixSize+8); case TagType::INT8_ARRAY: { - ErrorOr arrayLength = helper::readInt32(data, dataSize, currentPosition+prefixSize); + ErrorOr arrayLength = Helper::readInt32(data, dataSize, currentPosition+prefixSize); if (arrayLength.isError) { return ErrorOr(true, arrayLength.errorCode); } return ErrorOr((uint64_t) arrayLength.value + prefixSize + 4); } case TagType::STRING: { - ErrorOr stringSize = helper::readInt16(data, dataSize, currentPosition+prefixSize); + ErrorOr stringSize = Helper::readInt16(data, dataSize, currentPosition+prefixSize); if (stringSize.isError) { return ErrorOr(true, stringSize.errorCode); } return ErrorOr((uint64_t) stringSize.value + prefixSize + 2); } case TagType::INT32_ARRAY: { - ErrorOr arrayLength = helper::readInt32(data, dataSize, currentPosition+prefixSize); + ErrorOr arrayLength = Helper::readInt32(data, dataSize, currentPosition+prefixSize); if (arrayLength.isError) { return ErrorOr(true, arrayLength.errorCode); } return ErrorOr((uint64_t) arrayLength.value*4 + prefixSize + 4); } case TagType::INT64_ARRAY: { - ErrorOr arrayLength = helper::readInt32(data, dataSize, currentPosition+prefixSize); + ErrorOr arrayLength = Helper::readInt32(data, dataSize, currentPosition+prefixSize); if (arrayLength.isError) { return ErrorOr(true, arrayLength.errorCode); } @@ -509,7 +509,7 @@ namespace NBT { return ErrorOr(1); } - ErrorOr nameSize = helper::readInt16(data, dataSize, currentPosition+1); + ErrorOr nameSize = Helper::readInt16(data, dataSize, currentPosition+1); if (nameSize.isError) { return ErrorOr(true, nameSize.errorCode); } @@ -517,10 +517,10 @@ namespace NBT { uint64_t prefixSize = (uint64_t) nameSize.value + 3; switch (nextTag) { case TagType::INT8_ARRAY: { - return helper::readInt32(data, dataSize, currentPosition+prefixSize); + return Helper::readInt32(data, dataSize, currentPosition+prefixSize); } case TagType::STRING: { - ErrorOr stringSize = helper::readInt16(data, dataSize, currentPosition+prefixSize); + ErrorOr stringSize = Helper::readInt16(data, dataSize, currentPosition+prefixSize); if (stringSize.isError) { return ErrorOr(true, stringSize.errorCode); } @@ -528,13 +528,13 @@ namespace NBT { } case TagType::LIST: { // add an additional byte for the contained data type - return helper::readInt32(data, dataSize, currentPosition+prefixSize+1); + return Helper::readInt32(data, dataSize, currentPosition+prefixSize+1); } case TagType::INT32_ARRAY: { - return helper::readInt32(data, dataSize, currentPosition+prefixSize); + return Helper::readInt32(data, dataSize, currentPosition+prefixSize); } case TagType::INT64_ARRAY: { - return helper::readInt32(data, dataSize, currentPosition+prefixSize); + return Helper::readInt32(data, dataSize, currentPosition+prefixSize); } default: // unknown tag or parsing error @@ -562,7 +562,7 @@ namespace NBT { uint8_t nameSizeSlice[] = {data[1], data[2]}; - ErrorOr readIntResult = helper::readInt16(nameSizeSlice, 2, 0); + ErrorOr readIntResult = Helper::readInt16(nameSizeSlice, 2, 0); if(!readIntResult.isError){ this->nameSize = readIntResult.value; }else{ @@ -574,7 +574,7 @@ namespace NBT { nameSlice[i] = data[i+1]; } - ErrorOr readStringResult = helper::readString(nameSlice, this->nameSize, 0); + ErrorOr readStringResult = Helper::readString(nameSlice, this->nameSize, 0); if(!readStringResult.isError){ this->name = readStringResult.value; }else{ @@ -601,7 +601,7 @@ namespace NBT { // headerless tags // // add one byte to position to skip the type byte - ErrorOr elementCount = helper::readInt32(data, dataSize, initialPosition+1); + ErrorOr elementCount = Helper::readInt32(data, dataSize, initialPosition+1); if (elementCount.isError) { return false; } @@ -634,7 +634,7 @@ namespace NBT { } case TagType::INT8_ARRAY: { for (int32_t i=0; i> nextArray = helper::readInt8Array(data, dataSize, initialPosition+*processedDataSize); + ErrorOr> nextArray = Helper::readInt8Array(data, dataSize, initialPosition+*processedDataSize); if (nextArray.isError) { return false; } @@ -644,12 +644,12 @@ namespace NBT { } case TagType::STRING: { for (int32_t i=0; i nextString = helper::readString(data, dataSize, initialPosition+*processedDataSize); + ErrorOr nextString = Helper::readString(data, dataSize, initialPosition+*processedDataSize); if (nextString.isError) { return false; } // this cannot be an error because it just got checked - int16_t nextStringSize = helper::readInt16(data, dataSize, initialPosition+*processedDataSize).value; + int16_t nextStringSize = Helper::readInt16(data, dataSize, initialPosition+*processedDataSize).value; *processedDataSize += (uint64_t) nextStringSize + 2; } return true; @@ -685,7 +685,7 @@ namespace NBT { } case TagType::INT32_ARRAY: { for (int32_t i=0; i> nextArray = helper::readInt32Array(data, dataSize, initialPosition+*processedDataSize); + ErrorOr> nextArray = Helper::readInt32Array(data, dataSize, initialPosition+*processedDataSize); if (nextArray.isError) { return false; } @@ -695,7 +695,7 @@ namespace NBT { } case TagType::INT64_ARRAY: { for (int32_t i=0; i> nextArray = helper::readInt64Array(data, dataSize, initialPosition+*processedDataSize); + ErrorOr> nextArray = Helper::readInt64Array(data, dataSize, initialPosition+*processedDataSize); if (nextArray.isError) { return false; } @@ -737,11 +737,11 @@ namespace NBT { uint64_t currentPosition = initialPosition; #define return if (processedDataSize!=nullptr) *processedDataSize = currentPosition-initialPosition; return while (currentPosition nextTagSize = helper::totalTagSize(data, dataSize, currentPosition); + ErrorOr nextTagSize = Helper::totalTagSize(data, dataSize, currentPosition); if (nextTagSize.isError) { if (nextTagSize.errorCode == ErrorCodes::NOT_YET_KNOWN) { // attempt parsing the name - ErrorOr tagName = helper::readString(data, dataSize, currentPosition+1); + ErrorOr tagName = Helper::readString(data, dataSize, currentPosition+1); if (tagName.isError) { return false; } @@ -750,7 +750,7 @@ namespace NBT { // // there is no way this is an error bc it gets // checked while trying to parse the string above - int16_t nameSize = helper::readInt16(data, dataSize, currentPosition+1).value; + int16_t nameSize = Helper::readInt16(data, dataSize, currentPosition+1).value; uint64_t* processedTagSize = new uint64_t; *processedTagSize = 0; @@ -791,7 +791,7 @@ namespace NBT { // nameSize cannot be an error here bc it got checked in // nextTagSize() already - int16_t nameSize = helper::readInt16(data, dataSize, currentPosition+1).value; + int16_t nameSize = Helper::readInt16(data, dataSize, currentPosition+1).value; // attempt parsing the name // @@ -800,7 +800,7 @@ namespace NBT { // being guarded against with // if (currentPosition + nextTagSize.value > dataSize) return false; // It might, however, turn out to be a useful check in the future. - ErrorOr name = helper::readString(data, dataSize, currentPosition+1); + ErrorOr name = Helper::readString(data, dataSize, currentPosition+1); if (name.isError) { return false; } @@ -825,7 +825,7 @@ namespace NBT { // in the future. // // type byte + two name size bytes = 3 - ErrorOr content = helper::readString(data, dataSize, currentPosition+nameSize+3); + ErrorOr content = Helper::readString(data, dataSize, currentPosition+nameSize+3); if (content.isError) { return false; } diff --git a/src/lib/nbt.hpp b/src/lib/nbt.hpp index b40d804..e1ade91 100644 --- a/src/lib/nbt.hpp +++ b/src/lib/nbt.hpp @@ -41,7 +41,7 @@ #include "error.hpp" namespace NBT { - namespace helper { + namespace Helper { ErrorOr readInt8(uint8_t data[], uint64_t dataSize, uint64_t currentPosition); ErrorOr readInt16(uint8_t data[], uint64_t dataSize, uint64_t currentPosition); ErrorOr readInt32(uint8_t data[], uint64_t dataSize, uint64_t currentPosition);