43namespace ca_checkpoint_detail {
45std::vector<std::uint8_t>
46deflate_bytes(
const std::uint8_t *src,
const std::size_t len,
const int level)
51 const int clamped = std::clamp(level, 1, 9);
52 mz_ulong dest_cap = mz_compressBound(
static_cast<mz_ulong
>(len));
53 std::vector<std::uint8_t>
out(
static_cast<std::size_t
>(dest_cap));
54 const int rc = mz_compress2(
out.data(),
57 static_cast<mz_ulong
>(len),
60 <<
"deflate_bytes: miniz mz_compress2 failed (rc=" << rc <<
")";
61 out.resize(
static_cast<std::size_t
>(dest_cap));
65std::vector<std::uint8_t>
67 const std::size_t len,
68 const std::size_t expected_uncompressed)
70 std::vector<std::uint8_t>
out(expected_uncompressed);
71 if (expected_uncompressed == 0)
74 <<
"inflate_bytes: empty compressed payload but expected " << expected_uncompressed
75 <<
" bytes of output";
77 mz_ulong dest_len =
static_cast<mz_ulong
>(expected_uncompressed);
78 const int rc = mz_uncompress(
out.data(),
81 static_cast<mz_ulong
>(len));
83 <<
"inflate_bytes: miniz mz_uncompress failed (rc=" << rc <<
")";
85 <<
"inflate_bytes: size mismatch (expected " << expected_uncompressed
86 <<
", got " <<
static_cast<std::size_t
>(dest_len) <<
")";
90std::vector<std::uint8_t>
92 const std::size_t len,
93 const std::size_t max_uncompressed)
95 if (max_uncompressed == 0 or len == 0)
97 std::vector<std::uint8_t>
out(max_uncompressed);
98 mz_ulong dest_len =
static_cast<mz_ulong
>(max_uncompressed);
99 const int rc = mz_uncompress(
out.data(),
102 static_cast<mz_ulong
>(len));
104 <<
"inflate_bytes_up_to: miniz mz_uncompress failed (rc=" << rc <<
")";
106 <<
"inflate_bytes_up_to: produced " <<
static_cast<std::size_t
>(dest_len)
107 <<
" bytes, max=" << max_uncompressed;
108 out.resize(
static_cast<std::size_t
>(dest_len));
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
size_t size_t int32_t * out
Internal compress / decompress helpers used by ca-checkpoint.H (Phase 17).
std::vector< std::uint8_t > deflate_bytes(const std::uint8_t *src, const std::size_t len, const int level)
Compress a raw byte buffer with DEFLATE (miniz backend).
std::vector< std::uint8_t > inflate_bytes(const std::uint8_t *src, const std::size_t len, const std::size_t expected_uncompressed)
Decompress a DEFLATE byte buffer back to its raw form.
std::vector< std::uint8_t > inflate_bytes_up_to(const std::uint8_t *src, const std::size_t len, const std::size_t max_uncompressed)
Decompress a DEFLATE byte buffer with an upper bound.
Main namespace for Aleph-w library functions.