Compare commits
2 Commits
a1b200b694
...
346161de1d
Author | SHA1 | Date |
---|---|---|
Shwoomple | 346161de1d | |
Shwoomple | 68484c6a20 |
|
@ -336,15 +336,31 @@ namespace NBT {
|
|||
//}
|
||||
|
||||
void writeInt32Array(std::vector<uint8_t>* destination, std::vector<int32_t> data) {
|
||||
writeInt32(destination, data.size());
|
||||
for(int32_t element: data){
|
||||
writeInt32(destination, element);
|
||||
}
|
||||
}
|
||||
|
||||
void writeInt32Array(std::vector<uint8_t>* destination, int32_t data[], uint64_t dataSize) {
|
||||
void writeInt32Array(std::vector<uint8_t>* destination, int32_t data[], uint32_t dataSize) {
|
||||
writeInt32(destination, dataSize);
|
||||
for(uint32_t i = 0; i<dataSize; i++){
|
||||
writeInt32(destination, data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void writeInt64Array(std::vector<uint8_t>* destination, std::vector<int64_t> data) {
|
||||
writeInt32(destination, data.size());
|
||||
for(int64_t element: data){
|
||||
writeInt64(destination, element);
|
||||
}
|
||||
}
|
||||
|
||||
void writeInt64Array(std::vector<uint8_t>* destination, int64_t data[], uint64_t dataSize) {
|
||||
void writeInt64Array(std::vector<uint8_t>* destination, int64_t data[], uint32_t dataSize) {
|
||||
writeInt32(destination, dataSize);
|
||||
for(uint32_t i = 0; i<dataSize; i++){
|
||||
writeInt64(destination, data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,9 +70,9 @@ namespace NBT {
|
|||
void writeInt8Array(std::vector<uint8_t>* destination, int8_t data[], uint32_t dataSize);
|
||||
//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, int32_t data[], uint64_t dataSize);
|
||||
void writeInt32Array(std::vector<uint8_t>* destination, int32_t data[], uint32_t dataSize);
|
||||
void writeInt64Array(std::vector<uint8_t>* destination, std::vector<int64_t> data);
|
||||
void writeInt64Array(std::vector<uint8_t>* destination, int64_t data[], uint64_t dataSize);
|
||||
void writeInt64Array(std::vector<uint8_t>* destination, int64_t data[], uint32_t dataSize);
|
||||
}
|
||||
|
||||
bool validateRawNBTData(uint8_t data[], int length);
|
||||
|
|
|
@ -256,7 +256,44 @@ 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 int32Array NBT helper test" << std::endl;
|
||||
std::cout << "Passed readInt32Array NBT helper test" << std::endl;
|
||||
|
||||
std::vector<uint8_t>* int32ArrayTestOutput = new std::vector<uint8_t>();
|
||||
int32_t input32[] = {0x01234567, 0x01234567};
|
||||
NBT::helper::writeInt32Array(int32ArrayTestOutput, input32, 2);
|
||||
ASSERT(
|
||||
int32ArrayTestOutput->at(0) == 0x00 &&
|
||||
int32ArrayTestOutput->at(1) == 0x00 &&
|
||||
int32ArrayTestOutput->at(2) == 0x00 &&
|
||||
int32ArrayTestOutput->at(3) == 0x02 &&
|
||||
int32ArrayTestOutput->at(4) == 0x01 &&
|
||||
int32ArrayTestOutput->at(5) == 0x23 &&
|
||||
int32ArrayTestOutput->at(6) == 0x45 &&
|
||||
int32ArrayTestOutput->at(7) == 0x67 &&
|
||||
int32ArrayTestOutput->at(8) == 0x01 &&
|
||||
int32ArrayTestOutput->at(9) == 0x23 &&
|
||||
int32ArrayTestOutput->at(10) == 0x45 &&
|
||||
int32ArrayTestOutput->at(11) == 0x67
|
||||
);
|
||||
int32ArrayTestOutput->clear();
|
||||
NBT::helper::writeInt32Array(int32ArrayTestOutput, std::vector<int32_t>({0x01234567, 0x01234567}));
|
||||
ASSERT(
|
||||
int32ArrayTestOutput->at(0) == 0x00 &&
|
||||
int32ArrayTestOutput->at(1) == 0x00 &&
|
||||
int32ArrayTestOutput->at(2) == 0x00 &&
|
||||
int32ArrayTestOutput->at(3) == 0x02 &&
|
||||
int32ArrayTestOutput->at(4) == 0x01 &&
|
||||
int32ArrayTestOutput->at(5) == 0x23 &&
|
||||
int32ArrayTestOutput->at(6) == 0x45 &&
|
||||
int32ArrayTestOutput->at(7) == 0x67 &&
|
||||
int32ArrayTestOutput->at(8) == 0x01 &&
|
||||
int32ArrayTestOutput->at(9) == 0x23 &&
|
||||
int32ArrayTestOutput->at(10) == 0x45 &&
|
||||
int32ArrayTestOutput->at(11) == 0x67
|
||||
);
|
||||
delete int32ArrayTestOutput;
|
||||
|
||||
std::cout << "Passed writeInt32Array NBT helper test" << std::endl;
|
||||
|
||||
// int64 "array" ###################################################
|
||||
// read successfully
|
||||
|
@ -280,7 +317,61 @@ 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 int64Array NBT helper test" << std::endl;
|
||||
std::cout << "Passed readInt64Array NBT helper test" << std::endl;
|
||||
|
||||
std::vector<uint8_t>* int64ArrayTestOutput = new std::vector<uint8_t>();
|
||||
int64_t input64[] = {0x0123456789ABCDEF, 0x0123456789ABCDEF};
|
||||
NBT::helper::writeInt64Array(int64ArrayTestOutput, input64, 2);
|
||||
ASSERT(
|
||||
int64ArrayTestOutput->at(0) == 0x00 &&
|
||||
int64ArrayTestOutput->at(1) == 0x00 &&
|
||||
int64ArrayTestOutput->at(2) == 0x00 &&
|
||||
int64ArrayTestOutput->at(3) == 0x02 &&
|
||||
int64ArrayTestOutput->at(4) == 0x01 &&
|
||||
int64ArrayTestOutput->at(5) == 0x23 &&
|
||||
int64ArrayTestOutput->at(6) == 0x45 &&
|
||||
int64ArrayTestOutput->at(7) == 0x67 &&
|
||||
int64ArrayTestOutput->at(8) == 0x89 &&
|
||||
int64ArrayTestOutput->at(9) == 0xAB &&
|
||||
int64ArrayTestOutput->at(10) == 0xCD &&
|
||||
int64ArrayTestOutput->at(11) == 0xEF &&
|
||||
int64ArrayTestOutput->at(12) == 0x01 &&
|
||||
int64ArrayTestOutput->at(13) == 0x23 &&
|
||||
int64ArrayTestOutput->at(14) == 0x45 &&
|
||||
int64ArrayTestOutput->at(15) == 0x67 &&
|
||||
int64ArrayTestOutput->at(16) == 0x89 &&
|
||||
int64ArrayTestOutput->at(17) == 0xAB &&
|
||||
int64ArrayTestOutput->at(18) == 0xCD &&
|
||||
int64ArrayTestOutput->at(19) == 0xEF
|
||||
);
|
||||
int64ArrayTestOutput->clear();
|
||||
NBT::helper::writeInt64Array(int64ArrayTestOutput, std::vector<int64_t>({0x0123456789ABCDEF, 0x0123456789ABCDEF}));
|
||||
ASSERT(
|
||||
int64ArrayTestOutput->at(0) == 0x00 &&
|
||||
int64ArrayTestOutput->at(1) == 0x00 &&
|
||||
int64ArrayTestOutput->at(2) == 0x00 &&
|
||||
int64ArrayTestOutput->at(3) == 0x02 &&
|
||||
int64ArrayTestOutput->at(4) == 0x01 &&
|
||||
int64ArrayTestOutput->at(5) == 0x23 &&
|
||||
int64ArrayTestOutput->at(6) == 0x45 &&
|
||||
int64ArrayTestOutput->at(7) == 0x67 &&
|
||||
int64ArrayTestOutput->at(8) == 0x89 &&
|
||||
int64ArrayTestOutput->at(9) == 0xAB &&
|
||||
int64ArrayTestOutput->at(10) == 0xCD &&
|
||||
int64ArrayTestOutput->at(11) == 0xEF &&
|
||||
int64ArrayTestOutput->at(12) == 0x01 &&
|
||||
int64ArrayTestOutput->at(13) == 0x23 &&
|
||||
int64ArrayTestOutput->at(14) == 0x45 &&
|
||||
int64ArrayTestOutput->at(15) == 0x67 &&
|
||||
int64ArrayTestOutput->at(16) == 0x89 &&
|
||||
int64ArrayTestOutput->at(17) == 0xAB &&
|
||||
int64ArrayTestOutput->at(18) == 0xCD &&
|
||||
int64ArrayTestOutput->at(19) == 0xEF &&
|
||||
true
|
||||
);
|
||||
delete int64ArrayTestOutput;
|
||||
|
||||
std::cout << "Passed writeInt32Array NBT helper test" << std::endl;
|
||||
|
||||
// float32 ["float" in the current implementation :( ] #############
|
||||
uint8_t dataForFloat32Test[] = {0xC7, 0x77, 0x77, 0x77};
|
||||
|
|
Loading…
Reference in New Issue