NBT: implement the overloaded writeInt8Array

BodgeMaster-unfinished
Shwoomple 2022-07-06 17:16:47 +05:30
parent ecd1bfa496
commit 847b73c6ae
2 changed files with 16 additions and 1 deletions

View File

@ -319,7 +319,10 @@ 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) {
writeInt32(destination, data.size());
for(int8_t datum: data){
destination->push_back(datum);
}
} }
void writeInt8Array(std::vector<uint8_t>* destination, int8_t data[], uint32_t dataSize) { void writeInt8Array(std::vector<uint8_t>* destination, int8_t data[], uint32_t dataSize) {

View File

@ -219,6 +219,18 @@ int main(){
int8ArrayTestOutput->at(6) == 3 && int8ArrayTestOutput->at(6) == 3 &&
int8ArrayTestOutput->at(7) == 4 int8ArrayTestOutput->at(7) == 4
); );
int8ArrayTestOutput->clear();
NBT::helper::writeInt8Array(int8ArrayTestOutput, std::vector<int8_t>({1,2,3,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; delete int8ArrayTestOutput;
std::cout << "Passed writeInt8Array NBT helper test" << std::endl; std::cout << "Passed writeInt8Array NBT helper test" << std::endl;