|
ZXC 1.0.3
High-performance asymmetric lossless compression library
|
Opaque, reusable compression / decompression contexts. More...
Topics | |
| Static Context API | |
| Caller-allocated, fixed-footprint compression / decompression contexts. | |
Functions | |
| zxc_cctx * | zxc_create_cctx (void) |
| Creates a reusable compression context, every parameter at its default. | |
| void | zxc_free_cctx (zxc_cctx *cctx) |
| Frees a compression context and its resources. | |
| int | zxc_cctx_set_param (zxc_cctx *cctx, zxc_cparam_t param, int64_t value) |
Sets one parameter on cctx; 0 restores its default. | |
| int | zxc_cctx_get_param (const zxc_cctx *cctx, zxc_cparam_t param, int64_t *value) |
Reads one parameter of cctx. | |
| int | zxc_cctx_set_dict (zxc_cctx *cctx, const void *dict, size_t dict_size, const void *dict_huf) |
Attaches a pre-trained dictionary to cctx; a NULL dict detaches. | |
| int | zxc_cctx_set_progress (zxc_cctx *cctx, zxc_progress_callback_t cb, void *user_data) |
Sets the progress callback; NULL cb disables it. | |
| int | zxc_cctx_reset (zxc_cctx *cctx) |
| Restores every parameter to its default, detaches the dictionary and the callback. | |
| int64_t | zxc_compress_cctx (zxc_cctx *cctx, const void *src, size_t src_size, void *dst, size_t dst_capacity) |
| Compresses data using a reusable context. | |
| zxc_dctx * | zxc_create_dctx (void) |
| Creates a reusable decompression context. | |
| void | zxc_free_dctx (zxc_dctx *dctx) |
| Frees a decompression context and its resources. | |
| int | zxc_dctx_set_param (zxc_dctx *dctx, zxc_dparam_t param, int64_t value) |
Sets one parameter on dctx; 0 restores its default. | |
| int | zxc_dctx_get_param (const zxc_dctx *dctx, zxc_dparam_t param, int64_t *value) |
Reads one parameter of dctx. | |
| int | zxc_dctx_set_dict (zxc_dctx *dctx, const void *dict, size_t dict_size, const void *dict_huf) |
| Attaches the dictionary the archives were compressed with; NULL detaches. | |
| int | zxc_dctx_set_progress (zxc_dctx *dctx, zxc_progress_callback_t cb, void *user_data) |
Sets the progress callback; NULL cb disables it. | |
| int | zxc_dctx_reset (zxc_dctx *dctx) |
| Restores every parameter to its default, detaches the dictionary and the callback. | |
| int64_t | zxc_decompress_dctx (zxc_dctx *dctx, const void *src, size_t src_size, void *dst, size_t dst_capacity) |
| Decompresses data using a reusable context. | |
| int64_t | zxc_decompress_inplace_dctx (zxc_dctx *dctx, void *buffer, const size_t buffer_capacity, const size_t comp_size) |
| In-place decompression with a caller-supplied context. | |
Opaque, reusable compression / decompression contexts.
Keeping a context across calls removes the per-call allocation overhead. The internal layout stays hidden behind an opaque pointer.
| int zxc_cctx_get_param | ( | const zxc_cctx * | cctx, |
| zxc_cparam_t | param, | ||
| int64_t * | value ) |
Reads one parameter of cctx.
| [in] | cctx | Context. |
| [in] | param | Parameter identifier. |
| [out] | value | Receives the value in force. |
param, or ZXC_ERROR_NULL_INPUT. Definition at line 1207 of file zxc_dispatch.c.
References ZXC_C_BLOCK_SIZE, ZXC_C_CHECKSUM, ZXC_C_LEVEL, ZXC_C_SEEKABLE, ZXC_C_THREADS, ZXC_ERROR_BAD_PARAM, ZXC_ERROR_NULL_INPUT, and ZXC_OK.
| int zxc_cctx_reset | ( | zxc_cctx * | cctx | ) |
Restores every parameter to its default, detaches the dictionary and the callback.
The working buffers are kept.
On a static context the pinned block size and level are the defaults.
| [in,out] | cctx | Context to reset. |
Definition at line 1256 of file zxc_dispatch.c.
References zxc_cparams_defaults(), zxc_dict_copy_set(), ZXC_ERROR_NULL_INPUT, and ZXC_OK.
| int zxc_cctx_set_dict | ( | zxc_cctx * | cctx, |
| const void * | dict, | ||
| size_t | dict_size, | ||
| const void * | dict_huf ) |
Attaches a pre-trained dictionary to cctx; a NULL dict detaches.
The context keeps its own copy of dict and dict_huf: the caller's buffers are free once this returns. dict_huf, when non-NULL, is the shared literal table of ZXC_HUF_TABLE_SIZE bytes (zxc_dict_huf()), used at levels 6-7 and part of the archive's dict_id binding.
| [in,out] | cctx | Context to configure. |
| [in] | dict | Dictionary content, or NULL for none. |
| [in] | dict_size | Size of dict in bytes, at most ZXC_DICT_SIZE_MAX. |
| [in] | dict_huf | Shared literal table, or NULL. |
Definition at line 1232 of file zxc_dispatch.c.
References zxc_dict_copy_set(), ZXC_ERROR_DICT_UNSUPPORTED, ZXC_ERROR_NULL_INPUT, and ZXC_OK.
| int zxc_cctx_set_param | ( | zxc_cctx * | cctx, |
| const zxc_cparam_t | param, | ||
| const int64_t | value ) |
Sets one parameter on cctx; 0 restores its default.
Takes effect on the next call. A value outside zxc_cparam_bounds(), or an unknown param, is refused and the parameter keeps its value (ZXC_ERROR_BAD_LEVEL, ZXC_ERROR_BAD_BLOCK_SIZE or ZXC_ERROR_BAD_PARAM). On a static context (zxc_init_static_cctx()) the block size is pinned, a level raise into ZXC_LEVEL_DENSITY is refused when the workspace was carved below it, and 0 restores the pinned block size and level.
| [in,out] | cctx | Context to configure. |
| [in] | param | Parameter identifier. |
| [in] | value | New value, or 0 for the default. |
Sets one parameter on cctx; 0 restores its default.
Public API; see zxc_buffer.h. Zero restores the default; any other value must sit within zxc_cparam_bounds(). A static context refuses what its workspace cannot hold, so the error comes here, not on the next call.
Definition at line 1158 of file zxc_dispatch.c.
References zxc_cctx_t::opt_scratch, ZXC_BLOCK_SIZE_DEFAULT, ZXC_C_BLOCK_SIZE, ZXC_C_CHECKSUM, ZXC_C_LEVEL, ZXC_C_SEEKABLE, ZXC_C_THREADS, zxc_cparam_bounds(), ZXC_ERROR_BAD_BLOCK_SIZE, ZXC_ERROR_BAD_LEVEL, ZXC_ERROR_BAD_PARAM, ZXC_ERROR_NULL_INPUT, ZXC_LEVEL_DEFAULT, ZXC_LEVEL_DENSITY, ZXC_OK, and zxc_validate_block_size().
| int zxc_cctx_set_progress | ( | zxc_cctx * | cctx, |
| zxc_progress_callback_t | cb, | ||
| void * | user_data ) |
Sets the progress callback; NULL cb disables it.
Honoured by zxc_stream_compress() only: the buffer, block and push APIs are synchronous and never call it.
| [in,out] | cctx | Context to configure. |
| [in] | cb | Callback, or NULL. |
| [in] | user_data | Pointer handed back to cb. |
Definition at line 1249 of file zxc_dispatch.c.
References ZXC_ERROR_NULL_INPUT, and ZXC_OK.
| int64_t zxc_compress_cctx | ( | zxc_cctx * | cctx, |
| const void * | src, | ||
| const size_t | src_size, | ||
| void * | dst, | ||
| const size_t | dst_capacity ) |
Compresses data using a reusable context.
Like zxc_compress(), but with the context's parameters (level, block size, checksum, seek table, dictionary) and its buffers, which are re-carved only when the block size or the dictionary changes, or when the level rises into ZXC_LEVEL_DENSITY for the first time. A static (caller-workspace) context cannot grow: such a raise returns ZXC_ERROR_BAD_LEVEL there. ZXC_C_SEEKABLE appends the seek table without allocating, static contexts included.
| [in,out] | cctx | Configured compression context. |
| [in] | src | Source data; may be NULL when src_size is 0. |
| [in] | src_size | Source size in bytes; 0 writes the empty archive, as zxc_compress() does, without carving the encoder workspace. |
| [out] | dst | Destination buffer. |
| [in] | dst_capacity | Capacity of dst. |
src and dst must not overlap (same contract as memcpy).Public API; full contract in zxc_buffer.h. Resolves the context's parameters and runs the frame walk.
Definition at line 1410 of file zxc_dispatch.c.
References zxc_compress_cctx_resolved(), zxc_cparams_resolve(), and ZXC_ERROR_NULL_INPUT.
| zxc_cctx * zxc_create_cctx | ( | void | ) |
Creates a reusable compression context, every parameter at its default.
Only the handle is allocated here; the working buffers come on the first call, sized from the parameters then in force. Configure it with zxc_cctx_set_param(), zxc_cctx_set_dict() and zxc_cctx_set_progress(); the settings stay until changed or zxc_cctx_reset(). Free with zxc_free_cctx().
NULL on allocation failure. Definition at line 1113 of file zxc_dispatch.c.
References ZXC_CALLOC, zxc_cparams_defaults(), and ZXC_LEVEL_DEFAULT.
Referenced by zxc_cstream_create().
| zxc_dctx * zxc_create_dctx | ( | void | ) |
Creates a reusable decompression context.
Only the handle is allocated here: the working buffers are sized from the archive header, so they come on the first decode. Configure it with zxc_dctx_set_param(), zxc_dctx_set_dict() and zxc_dctx_set_progress(). Free with zxc_free_dctx().
NULL on allocation failure. Definition at line 1441 of file zxc_dispatch.c.
References ZXC_CALLOC.
| int zxc_dctx_get_param | ( | const zxc_dctx * | dctx, |
| zxc_dparam_t | param, | ||
| int64_t * | value ) |
Reads one parameter of dctx.
Definition at line 1486 of file zxc_dispatch.c.
References ZXC_D_CHECKSUM, ZXC_D_THREADS, ZXC_ERROR_BAD_PARAM, ZXC_ERROR_NULL_INPUT, and ZXC_OK.
| int zxc_dctx_reset | ( | zxc_dctx * | dctx | ) |
Restores every parameter to its default, detaches the dictionary and the callback.
The working buffers are kept.
| [in,out] | dctx | Context to reset. |
Definition at line 1524 of file zxc_dispatch.c.
References zxc_dict_copy_set(), ZXC_ERROR_NULL_INPUT, and ZXC_OK.
| int zxc_dctx_set_dict | ( | zxc_dctx * | dctx, |
| const void * | dict, | ||
| size_t | dict_size, | ||
| const void * | dict_huf ) |
Attaches the dictionary the archives were compressed with; NULL detaches.
Copies the bytes, as zxc_cctx_set_dict() does. dict_huf must be the table used at compression time when the archive carries one; the header's dict_id is checked against the pair, ZXC_ERROR_DICT_MISMATCH otherwise.
| [in,out] | dctx | Context to configure. |
| [in] | dict | Dictionary content, or NULL for none. |
| [in] | dict_size | Size of dict in bytes, at most ZXC_DICT_SIZE_MAX. |
| [in] | dict_huf | Shared literal table, or NULL. |
Definition at line 1501 of file zxc_dispatch.c.
References zxc_dict_copy_set(), ZXC_ERROR_DICT_UNSUPPORTED, ZXC_ERROR_NULL_INPUT, and ZXC_OK.
| int zxc_dctx_set_param | ( | zxc_dctx * | dctx, |
| zxc_dparam_t | param, | ||
| int64_t | value ) |
Sets one parameter on dctx; 0 restores its default.
Takes effect on the next call. A value outside zxc_dparam_bounds() is ZXC_ERROR_BAD_PARAM, as is an unknown param; the parameter keeps its value.
| [in,out] | dctx | Context to configure. |
| [in] | param | Parameter identifier. |
| [in] | value | New value, or 0 for the default. |
Definition at line 1467 of file zxc_dispatch.c.
References ZXC_D_CHECKSUM, ZXC_D_THREADS, zxc_dparam_bounds(), ZXC_ERROR_BAD_PARAM, ZXC_ERROR_NULL_INPUT, and ZXC_OK.
| int zxc_dctx_set_progress | ( | zxc_dctx * | dctx, |
| zxc_progress_callback_t | cb, | ||
| void * | user_data ) |
Sets the progress callback; NULL cb disables it.
Honoured by zxc_stream_decompress() only.
| [in,out] | dctx | Context to configure. |
| [in] | cb | Callback, or NULL. |
| [in] | user_data | Pointer handed back to cb. |
Definition at line 1517 of file zxc_dispatch.c.
References ZXC_ERROR_NULL_INPUT, and ZXC_OK.
| int64_t zxc_decompress_dctx | ( | zxc_dctx * | dctx, |
| const void * | src, | ||
| const size_t | src_size, | ||
| void * | dst, | ||
| const size_t | dst_capacity ) |
Decompresses data using a reusable context.
Like zxc_decompress(), dictionary options included, but reuses dctx's buffers; the shared literal table is rebuilt only when it changes between calls. A static context returns ZXC_ERROR_DICT_UNSUPPORTED for any dictionary.
| [in,out] | dctx | Reusable decompression context. |
| [in] | src | Compressed data. |
| [in] | src_size | Compressed size in bytes. |
| [out] | dst | Destination buffer, or NULL to probe (see above). |
| [in] | dst_capacity | Capacity of dst. |
src and dst must not overlap (same contract as memcpy).Decompresses data using a reusable context.
Public API; full contract in zxc_buffer.h. Same frame walk and dictionary binding as zxc_decompress(); the inner buffers are re-carved only when the block or dictionary size changes, the shared table only when it changes.
Definition at line 1575 of file zxc_dispatch.c.
References zxc_dctx_decode_container(), zxc_dctx_probe(), ZXC_ERROR_NULL_INPUT, ZXC_FRAME_MIN_SIZE, and zxc_short_input_verdict().
| int64_t zxc_decompress_inplace_dctx | ( | zxc_dctx * | dctx, |
| void * | buffer, | ||
| const size_t | buffer_capacity, | ||
| const size_t | comp_size ) |
In-place decompression with a caller-supplied context.
Same contract and error codes as zxc_decompress_inplace(), with dctx as the decode context. With a static context (zxc_init_static_dctx()) the call allocates nothing.
A static context rejects a foreign block size (ZXC_ERROR_BAD_BLOCK_SIZE) and any dictionary (ZXC_ERROR_DICT_UNSUPPORTED).
| [in,out] | dctx | Decompression context (static or heap). |
| [in,out] | buffer | Work buffer holding the flush-right archive. |
| [in] | buffer_capacity | Total size of buffer in bytes. |
| [in] | comp_size | Size of the compressed archive in bytes. |
In-place decompression with a caller-supplied context.
Public API; full contract in zxc_buffer.h. The archive sits flush-right, at buffer + buffer_capacity - comp_size, and decodes left-to-right into buffer[0..]. Dictionary archives decode through the context's own bounce buffer, which does not alias buffer.
Definition at line 1594 of file zxc_dispatch.c.
References zxc_dctx_decode_frame(), ZXC_ERROR_NULL_INPUT, zxc_inplace_prepare(), and ZXC_OK.
| void zxc_free_cctx | ( | zxc_cctx * | cctx | ) |
Frees a compression context and its resources.
NULL is a no-op.
| [in] | cctx | Context to free. |
Frees a compression context and its resources.
Public API; see zxc_buffer.h. Frees the inner buffers and the handle. NULL-safe. For a static (caller-workspace) context this is a no-op, since the caller owns the workspace.
Definition at line 1275 of file zxc_dispatch.c.
References zxc_cctx_free(), and ZXC_FREE.
Referenced by zxc_cstream_create(), and zxc_cstream_free().
| void zxc_free_dctx | ( | zxc_dctx * | dctx | ) |
Frees a decompression context and its resources.
NULL is a no-op.
| [in] | dctx | Context to free. |
Frees a decompression context and its resources.
Public API; see zxc_buffer.h. Frees the inner buffers and the handle. NULL-safe; a no-op for a static (caller-workspace) context.
Definition at line 1537 of file zxc_dispatch.c.
References zxc_cctx_free(), and ZXC_FREE.