Compare commits

..

3 Commits

Author SHA1 Message Date
Shwoomple 18184294df Merge branch 'master' of https://lostcave.ddnss.de/git/BodgeMaster/FOSS-VG 2022-07-06 16:30:16 +05:30
Shwoomple 8d8c1e6b90 NBT: change "[]" to "Array" in unit test messages. 2022-07-06 16:28:08 +05:30
Shwoomple b0ccc74409 NBT: Added writeInt8Array. 2022-07-06 16:27:32 +05:30
3 changed files with 26 additions and 5 deletions

View File

@ -319,9 +319,14 @@ namespace NBT {
} }
void writeInt8Array(std::vector<uint8_t>* destination, std::vector<int8_t> data) { void writeInt8Array(std::vector<uint8_t>* destination, std::vector<int8_t> data) {
} }
void writeInt8Array(std::vector<uint8_t>* destination, int8_t data[], uint64_t dataSize) { void writeInt8Array(std::vector<uint8_t>* 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<uint8_t>* destination, <string type> data) { //void writeString(std::vector<uint8_t>* destination, <string type> data) {

View File

@ -67,7 +67,7 @@ namespace NBT {
// floating point number // floating point number
void writeFloat64(std::vector<uint8_t>* destination, double data); void writeFloat64(std::vector<uint8_t>* destination, double data);
void writeInt8Array(std::vector<uint8_t>* destination, std::vector<int8_t> data); void writeInt8Array(std::vector<uint8_t>* destination, std::vector<int8_t> data);
void writeInt8Array(std::vector<uint8_t>* destination, int8_t data[], uint64_t dataSize); void writeInt8Array(std::vector<uint8_t>* destination, int8_t data[], uint32_t dataSize);
//void writeString(std::vector<uint8_t>* destination, <string type> data); //void writeString(std::vector<uint8_t>* destination, <string type> data);
void writeInt32Array(std::vector<uint8_t>* destination, std::vector<int32_t> data); void writeInt32Array(std::vector<uint8_t>* destination, std::vector<int32_t> data);
void writeInt32Array(std::vector<uint8_t>* destination, int32_t data[], uint64_t dataSize); void writeInt32Array(std::vector<uint8_t>* destination, int32_t data[], uint64_t dataSize);

View File

@ -204,7 +204,23 @@ int main(){
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR); 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<uint8_t>* int8ArrayTestOutput = new std::vector<uint8_t>();
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" ################################################### // int32 "array" ###################################################
// read successfully // read successfully
@ -228,7 +244,7 @@ int main(){
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR); 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" ################################################### // int64 "array" ###################################################
// read successfully // read successfully
@ -252,7 +268,7 @@ int main(){
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR); 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 :( ] ############# // float32 ["float" in the current implementation :( ] #############
uint8_t dataForFloat32Test[] = {0xC7, 0x77, 0x77, 0x77}; uint8_t dataForFloat32Test[] = {0xC7, 0x77, 0x77, 0x77};