nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 56 lines 2.3 kB view raw
1diff --git a/Tensile/Source/lib/source/msgpack/MessagePack.cpp b/Tensile/Source/lib/source/msgpack/MessagePack.cpp 2index de97929c..dbc397e0 100644 3--- a/tensilelite/src/msgpack/MessagePack.cpp 4+++ b/tensilelite/src/msgpack/MessagePack.cpp 5@@ -28,6 +28,8 @@ 6 7 #include <Tensile/msgpack/Loading.hpp> 8 9+#include <zstd.h> 10+ 11 #include <fstream> 12 13 namespace Tensile 14@@ -86,6 +88,34 @@ namespace Tensile 15 return nullptr; 16 } 17 18+ // Check if the file is zstd compressed 19+ char magic[4]; 20+ in.read(magic, 4); 21+ bool isCompressed = (in.gcount() == 4 && magic[0] == '\x28' && magic[1] == '\xB5' && magic[2] == '\x2F' && magic[3] == '\xFD'); 22+ // Reset file pointer to the beginning 23+ in.seekg(0, std::ios::beg); 24+ 25+ if (isCompressed) { 26+ // Decompress zstd file 27+ std::vector<char> compressedData((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>()); 28+ 29+ size_t decompressedSize = ZSTD_getFrameContentSize(compressedData.data(), compressedData.size()); 30+ if (decompressedSize == ZSTD_CONTENTSIZE_ERROR || decompressedSize == ZSTD_CONTENTSIZE_UNKNOWN) { 31+ if(Debug::Instance().printDataInit()) 32+ std::cout << "Error: Unable to determine decompressed size for " << filename << std::endl; 33+ return false; 34+ } 35+ 36+ std::vector<char> decompressedData(decompressedSize); 37+ size_t dSize = ZSTD_decompress(decompressedData.data(), decompressedSize, compressedData.data(), compressedData.size()); 38+ if (ZSTD_isError(dSize)) { 39+ if(Debug::Instance().printDataInit()) 40+ std::cout << "Error: ZSTD decompression failed for " << filename << std::endl; 41+ return false; 42+ } 43+ 44+ msgpack::unpack(result, decompressedData.data(), dSize); 45+ } else { 46 msgpack::unpacker unp; 47 bool finished_parsing; 48 constexpr size_t buffer_size = 1 << 19; 49@@ -109,6 +139,7 @@ namespace Tensile 50 51 return nullptr; 52 } 53+ } 54 } 55 catch(std::runtime_error const& exc) 56 {