From b0ccc744091cb0d70b9ac2486d91623557af40c1 Mon Sep 17 00:00:00 2001 From: Shwoomple <> Date: Wed, 6 Jul 2022 16:27:32 +0530 Subject: [PATCH 1/2] NBT: Added writeInt8Array. --- src/lib/nbt.cpp | 7 ++++++- src/lib/nbt.h++ | 2 +- src/test/nbt_helpers.cpp | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/lib/nbt.cpp b/src/lib/nbt.cpp index 45c5d82..73a2baf 100644 --- a/src/lib/nbt.cpp +++ b/src/lib/nbt.cpp @@ -319,9 +319,14 @@ namespace NBT { } void writeInt8Array(std::vector* destination, std::vector data) { + } - void writeInt8Array(std::vector* destination, int8_t data[], uint64_t dataSize) { + void writeInt8Array(std::vector* destination, int8_t data[], uint32_t dataSize) { + writeInt32(destination, dataSize); + for(uint32_t i=0; i < dataSize; i++){ + destination->push_back(data[i]); + } } //void writeString(std::vector* destination, data) { diff --git a/src/lib/nbt.h++ b/src/lib/nbt.h++ index b2bbfa7..245c491 100644 --- a/src/lib/nbt.h++ +++ b/src/lib/nbt.h++ @@ -67,7 +67,7 @@ namespace NBT { // floating point number void writeFloat64(std::vector* destination, double data); void writeInt8Array(std::vector* destination, std::vector data); - void writeInt8Array(std::vector* destination, int8_t data[], uint64_t dataSize); + void writeInt8Array(std::vector* destination, int8_t data[], uint32_t dataSize); //void writeString(std::vector* destination, data); void writeInt32Array(std::vector* destination, std::vector data); void writeInt32Array(std::vector* destination, int32_t data[], uint64_t dataSize); diff --git a/src/test/nbt_helpers.cpp b/src/test/nbt_helpers.cpp index 4e6675d..7d442f7 100644 --- a/src/test/nbt_helpers.cpp +++ b/src/test/nbt_helpers.cpp @@ -204,7 +204,23 @@ int main(){ ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR); - std::cout << "Passed int8[] NBT helper test" << std::endl; + std::cout << "Passed readInt8Array NBT helper test" << std::endl; + + std::vector* int8ArrayTestOutput = new std::vector(); + int8_t writeDataTest[] = {1,2,3,4}; + NBT::helper::writeInt8Array(int8ArrayTestOutput, writeDataTest, (uint32_t)4); + ASSERT( + int8ArrayTestOutput->at(0) == 0 && + int8ArrayTestOutput->at(1) == 0 && + int8ArrayTestOutput->at(2) == 0 && + int8ArrayTestOutput->at(3) == 4 && + int8ArrayTestOutput->at(4) == 1 && + int8ArrayTestOutput->at(5) == 2 && + int8ArrayTestOutput->at(6) == 3 && + int8ArrayTestOutput->at(7) == 4 + ); + delete int8ArrayTestOutput; + std::cout << "Passed writeInt8Array NBT helper test" << std::endl; // int32 "array" ################################################### // read successfully From 8d8c1e6b9075797439aca3b53839b328f6d2a859 Mon Sep 17 00:00:00 2001 From: Shwoomple <> Date: Wed, 6 Jul 2022 16:28:08 +0530 Subject: [PATCH 2/2] NBT: change "[]" to "Array" in unit test messages. --- src/test/nbt_helpers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/nbt_helpers.cpp b/src/test/nbt_helpers.cpp index 7d442f7..6ff7f19 100644 --- a/src/test/nbt_helpers.cpp +++ b/src/test/nbt_helpers.cpp @@ -244,7 +244,7 @@ int main(){ ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR); - std::cout << "Passed int32[] NBT helper test" << std::endl; + std::cout << "Passed int32Array NBT helper test" << std::endl; // int64 "array" ################################################### // read successfully @@ -268,7 +268,7 @@ int main(){ ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR); - std::cout << "Passed int64[] NBT helper test" << std::endl; + std::cout << "Passed int64Array NBT helper test" << std::endl; // float32 ["float" in the current implementation :( ] ############# uint8_t dataForFloat32Test[] = {0xC7, 0x77, 0x77, 0x77};