| 422 | // ---------- compression / decompression ------------------------------- |
| 423 | |
| 424 | std::vector<char> zlib_compress(const msgpack::sbuffer& sbuf) { |
| 425 | // Match TabularBackends.cpp's allocation strategy: start with the |
| 426 | // raw size and let zlib write into that buffer. miniz returns |
| 427 | // Z_OK when it fits. |
| 428 | std::vector<char> out(sbuf.size() + (sbuf.size() / 1000) + 128); |
| 429 | auto out_size = static_cast<mz_ulong>(out.size()); |
| 430 | // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast) — zlib's C API takes unsigned char*; our buffers are char (pre-existing glue). |
| 431 | const int code = compress(reinterpret_cast<unsigned char*>(out.data()), &out_size, reinterpret_cast<const unsigned char*>(sbuf.data()), |
| 432 | static_cast<mz_ulong>(sbuf.size())); |
| 433 | // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast) |
| 434 | if (code != Z_OK) { |
| 435 | throw std::runtime_error(std::string("SVDSurfaceSerializer: zlib compress failed (code ") + std::to_string(code) + ")"); |
| 436 | } |
| 437 | out.resize(out_size); |
| 438 | return out; |
| 439 | } |
| 440 | |
| 441 | std::vector<char> zlib_uncompress(const std::vector<char>& compressed) { |
| 442 | // Mirrors TabularBackends.cpp:52-69: start at 5x the compressed |