Compare commits

..

No commits in common. "ad9f4e21f7adea990e705c0fb25d000a1b68f03a" and "664632d1113b2744786f276fe01ce2eef78c114a" have entirely different histories.

2 changed files with 1 additions and 116 deletions

View File

@ -86,8 +86,6 @@ namespace NBT {
*(valueAsBytes+1) = data[currentPosition+2];
*(valueAsBytes+2) = data[currentPosition+1];
*(valueAsBytes+3) = data[currentPosition];
#else
#error "NBT::helper::readFloat32: An implementation for your endianness is unavailable."
#endif
#endif
float dereferencedValue = *value;
@ -122,8 +120,6 @@ namespace NBT {
*(valueAsBytes+5) = data[currentPosition+2];
*(valueAsBytes+6) = data[currentPosition+1];
*(valueAsBytes+7) = data[currentPosition];
#else
#error "NBT::helper::readFloat64: An implementation for your endianness is unavailable."
#endif
#endif
double dereferencedValue = *value;
@ -186,80 +182,15 @@ namespace NBT {
}
void writeInt8(std::vector<uint8_t>* destination, int8_t data) {
destination->push_back((uint8_t) data);
}
//FIXME: endian dependent implementation
void writeInt16(std::vector<uint8_t>* destination, int16_t data) {
int16_t* value = new int16_t;
uint8_t* valueAsBytes = reinterpret_cast<uint8_t*>(value);
*value = data;
#ifdef FOSSVG_BIG_ENDIAN
destination->push_back(*valueAsBytes);
destination->push_back(*(valueAsBytes+1));
#else
#ifdef FOSSVG_LITTLE_ENDIAN
destination->push_back(*(valueAsBytes+1));
destination->push_back(*valueAsBytes);
#else
#error "NBT::helper::writeInt16: An implementation for your endianness is unavailable."
#endif
#endif
delete value;
}
//FIXME: endian dependent implementation
void writeInt32(std::vector<uint8_t>* destination, int32_t data) {
int32_t* value = new int32_t;
uint8_t* valueAsBytes = reinterpret_cast<uint8_t*>(value);
*value = data;
#ifdef FOSSVG_BIG_ENDIAN
destination->push_back(*valueAsBytes);
destination->push_back(*(valueAsBytes+1));
destination->push_back(*(valueAsBytes+2));
destination->push_back(*(valueAsBytes+3));
#else
#ifdef FOSSVG_LITTLE_ENDIAN
destination->push_back(*(valueAsBytes+3));
destination->push_back(*(valueAsBytes+2));
destination->push_back(*(valueAsBytes+1));
destination->push_back(*valueAsBytes);
#else
#error "NBT::helper::writeInt16: An implementation for your endianness is unavailable."
#endif
#endif
delete value;
}
//FIXME: endian dependent implementation
void writeInt64(std::vector<uint8_t>* destination, int64_t data) {
int64_t* value = new int64_t;
uint8_t* valueAsBytes = reinterpret_cast<uint8_t*>(value);
*value = data;
#ifdef FOSSVG_BIG_ENDIAN
destination->push_back(*valueAsBytes);
destination->push_back(*(valueAsBytes+1));
destination->push_back(*(valueAsBytes+2));
destination->push_back(*(valueAsBytes+3));
destination->push_back(*(valueAsBytes+4));
destination->push_back(*(valueAsBytes+5));
destination->push_back(*(valueAsBytes+6));
destination->push_back(*(valueAsBytes+7));
#else
#ifdef FOSSVG_LITTLE_ENDIAN
destination->push_back(*(valueAsBytes+7));
destination->push_back(*(valueAsBytes+6));
destination->push_back(*(valueAsBytes+5));
destination->push_back(*(valueAsBytes+4));
destination->push_back(*(valueAsBytes+3));
destination->push_back(*(valueAsBytes+2));
destination->push_back(*(valueAsBytes+1));
destination->push_back(*valueAsBytes);
#else
#error "NBT::helper::writeInt16: An implementation for your endianness is unavailable."
#endif
#endif
delete value;
}
//FIXME: we just assume that float is a single-precision IEEE754

View File

@ -48,14 +48,6 @@ int main(){
std::cout << "Passed readInt8 NBT helper test" << std::endl;
std::vector<uint8_t>* writeInt8TestResult = new std::vector<uint8_t>();
NBT::helper::writeInt8(writeInt8TestResult, (int8_t) 8);
std::vector<uint8_t> dereferencedWriteInt8TestResult = *writeInt8TestResult;
delete writeInt8TestResult;
ASSERT(dereferencedWriteInt8TestResult.back() == (uint8_t) 8);
std::cout << "Passed writeInt8 NBT helper test" << std::endl;
// int16 ###########################################################
// read successfully
currentPosition = 5;
@ -80,14 +72,6 @@ int main(){
std::cout << "Passed readInt16 NBT helper test" << std::endl;
std::vector<uint8_t>* writeInt16TestResult = new std::vector<uint8_t>();
NBT::helper::writeInt16(writeInt16TestResult, (int16_t) 0xABCD);
std::vector<uint8_t> dereferencedWriteInt16TestResult = *writeInt16TestResult;
delete writeInt16TestResult;
ASSERT(dereferencedWriteInt16TestResult[0] == (uint8_t) 0xAB && dereferencedWriteInt16TestResult[1] == (uint8_t) 0xCD);
std::cout << "Passed writeInt16 NBT helper test" << std::endl;
// int32 ###########################################################
// read successfully
currentPosition = 5;
@ -112,19 +96,6 @@ int main(){
std::cout << "Passed readInt32 NBT helper test" << std::endl;
std::vector<uint8_t>* writeInt32TestResult = new std::vector<uint8_t>();
NBT::helper::writeInt32(writeInt32TestResult, (int32_t) 0x12345678);
std::vector<uint8_t> dereferencedWriteInt32TestResult = *writeInt32TestResult;
delete writeInt32TestResult;
ASSERT(
dereferencedWriteInt32TestResult[0] == (uint8_t) 0x12 &&
dereferencedWriteInt32TestResult[1] == (uint8_t) 0x34 &&
dereferencedWriteInt32TestResult[2] == (uint8_t) 0x56 &&
dereferencedWriteInt32TestResult[3] == (uint8_t) 0x78
);
std::cout << "Passed writeInt32 NBT helper test" << std::endl;
// int64 ###########################################################
// read successfully
currentPosition = 1;
@ -147,24 +118,7 @@ int main(){
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR);
std::cout << "Passed readInt64 NBT helper test" << std::endl;
std::vector<uint8_t>* writeInt64TestResult = new std::vector<uint8_t>();
NBT::helper::writeInt64(writeInt64TestResult, (int64_t) 0x0123456789ABCDEF);
std::vector<uint8_t> dereferencedWriteInt64TestResult = *writeInt64TestResult;
delete writeInt64TestResult;
ASSERT(
dereferencedWriteInt64TestResult[0] == (uint8_t) 0x01 &&
dereferencedWriteInt64TestResult[1] == (uint8_t) 0x23 &&
dereferencedWriteInt64TestResult[2] == (uint8_t) 0x45 &&
dereferencedWriteInt64TestResult[3] == (uint8_t) 0x67 &&
dereferencedWriteInt64TestResult[4] == (uint8_t) 0x89 &&
dereferencedWriteInt64TestResult[5] == (uint8_t) 0xAB &&
dereferencedWriteInt64TestResult[6] == (uint8_t) 0xCD &&
dereferencedWriteInt64TestResult[7] == (uint8_t) 0xEF
);
std::cout << "Passed writeInt32 NBT helper test" << std::endl;
std::cout << "Passed int64 NBT helper test" << std::endl;
//##################################################################