Compare commits
	
		
			3 Commits 
		
	
	
		
			664632d111
			...
			ad9f4e21f7
		
	
	| Author | SHA1 | Date | 
|---|---|---|
|  BodgeMaster | ad9f4e21f7 | |
|  BodgeMaster | 6d62d995df | |
|  BodgeMaster | 044593e081 | 
|  | @ -86,6 +86,8 @@ namespace NBT { | ||||||
|                     *(valueAsBytes+1) = data[currentPosition+2]; |                     *(valueAsBytes+1) = data[currentPosition+2]; | ||||||
|                     *(valueAsBytes+2) = data[currentPosition+1]; |                     *(valueAsBytes+2) = data[currentPosition+1]; | ||||||
|                     *(valueAsBytes+3) = data[currentPosition]; |                     *(valueAsBytes+3) = data[currentPosition]; | ||||||
|  |                 #else | ||||||
|  |                     #error "NBT::helper::readFloat32: An implementation for your endianness is unavailable." | ||||||
|                 #endif |                 #endif | ||||||
|             #endif |             #endif | ||||||
|             float dereferencedValue = *value; |             float dereferencedValue = *value; | ||||||
|  | @ -120,6 +122,8 @@ namespace NBT { | ||||||
|                     *(valueAsBytes+5) = data[currentPosition+2]; |                     *(valueAsBytes+5) = data[currentPosition+2]; | ||||||
|                     *(valueAsBytes+6) = data[currentPosition+1]; |                     *(valueAsBytes+6) = data[currentPosition+1]; | ||||||
|                     *(valueAsBytes+7) = data[currentPosition]; |                     *(valueAsBytes+7) = data[currentPosition]; | ||||||
|  |                 #else | ||||||
|  |                     #error "NBT::helper::readFloat64: An implementation for your endianness is unavailable." | ||||||
|                 #endif |                 #endif | ||||||
|             #endif |             #endif | ||||||
|             double dereferencedValue = *value; |             double dereferencedValue = *value; | ||||||
|  | @ -182,15 +186,80 @@ namespace NBT { | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         void writeInt8(std::vector<uint8_t>* destination, int8_t data) { |         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) { |         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) { |         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) { |         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
 |         //FIXME: we just assume that float is a single-precision IEEE754
 | ||||||
|  |  | ||||||
|  | @ -48,6 +48,14 @@ int main(){ | ||||||
| 
 | 
 | ||||||
|     std::cout << "Passed readInt8 NBT helper test" << std::endl; |     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 ###########################################################
 |     // int16 ###########################################################
 | ||||||
|     // read successfully
 |     // read successfully
 | ||||||
|     currentPosition = 5; |     currentPosition = 5; | ||||||
|  | @ -72,6 +80,14 @@ int main(){ | ||||||
| 
 | 
 | ||||||
|     std::cout << "Passed readInt16 NBT helper test" << std::endl; |     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 ###########################################################
 |     // int32 ###########################################################
 | ||||||
|     // read successfully
 |     // read successfully
 | ||||||
|     currentPosition = 5; |     currentPosition = 5; | ||||||
|  | @ -96,6 +112,19 @@ int main(){ | ||||||
| 
 | 
 | ||||||
|     std::cout << "Passed readInt32 NBT helper test" << std::endl; |     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 ###########################################################
 |     // int64 ###########################################################
 | ||||||
|     // read successfully
 |     // read successfully
 | ||||||
|     currentPosition = 1; |     currentPosition = 1; | ||||||
|  | @ -118,7 +147,24 @@ int main(){ | ||||||
|     ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == true); |     ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == true); | ||||||
|     ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR); |     ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR); | ||||||
| 
 | 
 | ||||||
|     std::cout << "Passed int64 NBT helper test" << std::endl; |     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; | ||||||
| 
 | 
 | ||||||
|     //##################################################################
 |     //##################################################################
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue