cf_snapshot_compress¶
Category: net
GitHub: cute_networking.h
Delta-compresses a snapshot against a baseline of the same size.
int cf_snapshot_compress(const void* baseline, const void* current, int size, void* out, int out_capacity);
| Parameters | Description |
|---|---|
baseline |
The previous snapshot to delta against, or NULL to compress against all-zero. |
current |
The new snapshot to compress. Must be size bytes. |
size |
The size of both snapshots in bytes. |
out |
Destination buffer for the compressed bytes. |
out_capacity |
Capacity of out in bytes. |
Return Value¶
Returns the compressed size in bytes. When out_capacity is too small, returns the
NEGATIVE of the exact capacity required -- if (result >= 0) still means success,
and a retry with -result bytes succeeds. A buffer of
cf_snapshot_compress_bound(size) bytes can never fail.
Remarks¶
baseline and current must have identical layout and size; only their differences
are encoded. Decompress with cf_snapshot_decompress and the same baseline. Output
never exceeds cf_snapshot_compress_bound(size): when the entropy coder cannot beat
raw storage (adversarial or incompressible input), the snapshot is stored raw behind
a one-byte flag, so pathological input costs one byte of expansion, not a blowup.
Compressed streams are not stable across CF versions -- both ends of a connection
must run the same build, which the connect handshake already implies.
Related Pages¶
cf_snapshot_compress_bound
cf_snapshot_decompress
cf_client_send
cf_server_send