| 439 | } |
| 440 | |
| 441 | std::vector<char> zlib_uncompress(const std::vector<char>& compressed) { |
| 442 | // Mirrors TabularBackends.cpp:52-69: start at 5x the compressed |
| 443 | // size, double on Z_BUF_ERROR until it fits or we exhaust patience. |
| 444 | std::vector<char> out(compressed.size() * 5); |
| 445 | auto out_size = static_cast<mz_ulong>(out.size()); |
| 446 | auto in_size = static_cast<mz_ulong>(compressed.size()); |
| 447 | int code = 0; |
| 448 | int retries = 0; |
| 449 | do { |
| 450 | // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast) — zlib C API takes unsigned char* (pre-existing glue). |
| 451 | code = |
| 452 | uncompress(reinterpret_cast<unsigned char*>(out.data()), &out_size, reinterpret_cast<const unsigned char*>(compressed.data()), in_size); |
| 453 | // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast) |
| 454 | if (code == Z_BUF_ERROR) { |
| 455 | if (++retries > 8) { |
| 456 | throw std::runtime_error("SVDSurfaceSerializer: zlib uncompress would not fit after 8 retries"); |
| 457 | } |
| 458 | out.resize(out.size() * 2); |
| 459 | out_size = static_cast<mz_ulong>(out.size()); |
| 460 | } else if (code != Z_OK) { |
| 461 | throw std::runtime_error(std::string("SVDSurfaceSerializer: zlib uncompress failed (code ") + std::to_string(code) + ")"); |
| 462 | } |
| 463 | } while (code != Z_OK); |
| 464 | out.resize(out_size); |
| 465 | return out; |
| 466 | } |
| 467 | |
| 468 | } // namespace |
| 469 |
no test coverage detected