ZXC 0.15.0
High-performance asymmetric lossless compression library
Loading...
Searching...
No Matches
zxc_buffer.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause */
2/*
3 * ZXC - High-performance lossless compression
4 *
5 * Copyright (c) Bertrand Lebonnois and contributors.
6 */
7
34#ifndef ZXC_BUFFER_H
35#define ZXC_BUFFER_H
36
37#include <stddef.h>
38#include <stdint.h>
39
40#include "zxc_export.h"
41#include "zxc_opts.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
61ZXC_EXPORT int zxc_min_level(void);
62
67ZXC_EXPORT int zxc_max_level(void);
68
73ZXC_EXPORT int zxc_default_level(void);
74
79ZXC_EXPORT const char* zxc_version_string(void);
80
/* end of library_info */
82
98ZXC_EXPORT uint64_t zxc_compress_bound(const size_t input_size);
99
120ZXC_EXPORT int64_t zxc_compress(const void* src, const size_t src_size, void* dst,
121 const size_t dst_capacity, const zxc_compress_opts_t* opts);
122
158ZXC_EXPORT int64_t zxc_decompress(const void* src, const size_t src_size, void* dst,
159 const size_t dst_capacity, const zxc_decompress_opts_t* opts);
160
173ZXC_EXPORT size_t zxc_decompress_inplace_bound(const void* src, const size_t src_size);
174
200ZXC_EXPORT int64_t zxc_decompress_inplace(void* buffer, const size_t buffer_capacity,
201 const size_t comp_size,
202 const zxc_decompress_opts_t* opts);
203
217ZXC_EXPORT uint64_t zxc_get_decompressed_size(const void* src, const size_t src_size);
218
226ZXC_EXPORT uint32_t zxc_get_dict_id(const void* src, size_t src_size);
227
235typedef struct {
238 uint64_t digest;
239 size_t block_size;
240 uint32_t dict_id;
242 uint8_t has_checksum;
245
261ZXC_EXPORT int zxc_get_frame_info(const void* src, size_t src_size, zxc_frame_info_t* info,
262 size_t info_size);
263
284ZXC_EXPORT int zxc_get_last_frame_info(const void* src, size_t src_size, zxc_frame_info_t* info,
285 size_t info_size);
286
291ZXC_EXPORT size_t zxc_frame_info_size(void);
292
293/* ========================================================================= */
294/* Block-Level API (no file framing) */
295/* ========================================================================= */
296
325/* Forward declarations for context types (defined below). */
327typedef struct zxc_cctx_s zxc_cctx;
329typedef struct zxc_dctx_s zxc_dctx;
330
342ZXC_EXPORT uint64_t zxc_compress_block_bound(size_t input_size);
343
359ZXC_EXPORT uint64_t zxc_decompress_block_bound(const size_t uncompressed_size);
360
391ZXC_EXPORT int64_t zxc_compress_block(zxc_cctx* cctx, const void* src, size_t src_size, void* dst,
392 size_t dst_capacity, const zxc_compress_opts_t* opts);
393
430ZXC_EXPORT int64_t zxc_decompress_block(zxc_dctx* dctx, const void* src, size_t src_size, void* dst,
431 size_t dst_capacity, const zxc_decompress_opts_t* opts);
432
468ZXC_EXPORT int64_t zxc_decompress_block_safe(zxc_dctx* dctx, const void* src, const size_t src_size,
469 void* dst, const size_t dst_capacity,
470 const zxc_decompress_opts_t* opts);
471
487ZXC_EXPORT uint64_t zxc_estimate_cctx_size(size_t src_size, int level);
488
/* end of block_api */
490
491/* ========================================================================= */
492/* Reusable Context API (opaque, heap-allocated) */
493/* ========================================================================= */
494
505/* --- Compression context ------------------------------------------------- */
506
519ZXC_EXPORT zxc_cctx* zxc_create_cctx(const zxc_compress_opts_t* opts);
520
526ZXC_EXPORT void zxc_free_cctx(zxc_cctx* cctx);
527
562ZXC_EXPORT int64_t zxc_compress_cctx(zxc_cctx* cctx, const void* src, size_t src_size, void* dst,
563 size_t dst_capacity, const zxc_compress_opts_t* opts);
564
565/* --- Decompression context ----------------------------------------------- */
566
575ZXC_EXPORT zxc_dctx* zxc_create_dctx(void);
576
582ZXC_EXPORT void zxc_free_dctx(zxc_dctx* dctx);
583
615ZXC_EXPORT int64_t zxc_decompress_dctx(zxc_dctx* dctx, const void* src, size_t src_size, void* dst,
616 size_t dst_capacity, const zxc_decompress_opts_t* opts);
617
644ZXC_EXPORT int64_t zxc_decompress_inplace_dctx(zxc_dctx* dctx, void* buffer,
645 const size_t buffer_capacity, const size_t comp_size,
646 const zxc_decompress_opts_t* opts);
647
648/* ========================================================================= */
649/* Static Context API (caller-allocated workspace) */
650/* ========================================================================= */
651
699ZXC_EXPORT size_t zxc_static_cctx_workspace_size(const size_t block_size, const int level);
700
727ZXC_EXPORT zxc_cctx* zxc_init_static_cctx(void* workspace, const size_t workspace_size,
728 const zxc_compress_opts_t* opts);
729
741ZXC_EXPORT size_t zxc_static_dctx_workspace_size(const size_t block_size);
742
767ZXC_EXPORT zxc_dctx* zxc_init_static_dctx(void* workspace, const size_t workspace_size,
768 const size_t block_size);
769
/* end of static_context_api */ /* end of context_api */ /* end of buffer_api */
773
774#ifdef __cplusplus
775}
776#endif
777
778#endif // ZXC_BUFFER_H
struct zxc_cctx_s zxc_cctx
Opaque reusable compression context (see zxc_create_cctx).
Definition zxc_buffer.h:327
uint64_t zxc_compress_block_bound(size_t input_size)
Maximum compressed size for a single block.
uint64_t zxc_estimate_cctx_size(size_t src_size, int level)
Estimates peak compression memory for a given block size and level.
int64_t zxc_compress_block(zxc_cctx *cctx, const void *src, size_t src_size, void *dst, size_t dst_capacity, const zxc_compress_opts_t *opts)
Compresses a single block without file framing.
struct zxc_dctx_s zxc_dctx
Opaque reusable decompression context (see zxc_create_dctx).
Definition zxc_buffer.h:329
int64_t zxc_decompress_block_safe(zxc_dctx *dctx, const void *src, const size_t src_size, void *dst, const size_t dst_capacity, const zxc_decompress_opts_t *opts)
Decompresses a single block into an exactly-sized destination.
int64_t zxc_decompress_block(zxc_dctx *dctx, const void *src, size_t src_size, void *dst, size_t dst_capacity, const zxc_decompress_opts_t *opts)
Decompresses a single block produced by zxc_compress_block().
uint64_t zxc_decompress_block_bound(const size_t uncompressed_size)
Minimum dst_capacity zxc_decompress_block() needs for a block of uncompressed_size bytes.
int64_t zxc_decompress(const void *src, const size_t src_size, void *dst, const size_t dst_capacity, const zxc_decompress_opts_t *opts)
Decompresses a complete ZXC archive.
size_t zxc_frame_info_size(void)
Returns sizeof(zxc_frame_info_t) as compiled into the library.
Definition zxc_common.c:51
int zxc_get_frame_info(const void *src, size_t src_size, zxc_frame_info_t *info, size_t info_size)
Reads a frame's header and footer, without decoding.
uint64_t zxc_get_decompressed_size(const void *src, const size_t src_size)
Reads the original size from the archive footers, without decoding.
int64_t zxc_compress(const void *src, const size_t src_size, void *dst, const size_t dst_capacity, const zxc_compress_opts_t *opts)
Compresses a buffer into a complete ZXC archive.
int64_t zxc_decompress_inplace(void *buffer, const size_t buffer_capacity, const size_t comp_size, const zxc_decompress_opts_t *opts)
Decompresses inside a single caller-owned buffer.
size_t zxc_decompress_inplace_bound(const void *src, const size_t src_size)
Buffer size required for an in-place decompression of src.
uint32_t zxc_get_dict_id(const void *src, size_t src_size)
Reads the dictionary ID from an archive header, without decoding.
uint64_t zxc_compress_bound(const size_t input_size)
Maximum compressed size for an input of input_size bytes.
int zxc_get_last_frame_info(const void *src, size_t src_size, zxc_frame_info_t *info, size_t info_size)
Reads the last frame of src, without decoding.
zxc_cctx * zxc_create_cctx(const zxc_compress_opts_t *opts)
Creates a reusable compression context.
int64_t zxc_compress_cctx(zxc_cctx *cctx, const void *src, size_t src_size, void *dst, size_t dst_capacity, const zxc_compress_opts_t *opts)
Compresses data using a reusable context.
void zxc_free_cctx(zxc_cctx *cctx)
Frees a compression context and its resources.
zxc_dctx * zxc_create_dctx(void)
Creates a reusable decompression context.
int64_t zxc_decompress_dctx(zxc_dctx *dctx, const void *src, size_t src_size, void *dst, size_t dst_capacity, const zxc_decompress_opts_t *opts)
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, const zxc_decompress_opts_t *opts)
In-place decompression with a caller-supplied context.
void zxc_free_dctx(zxc_dctx *dctx)
Frees a decompression context and its resources.
const char * zxc_version_string(void)
Library version string, "MAJOR.MINOR.PATCH".
int zxc_default_level(void)
Default compression level.
int zxc_max_level(void)
Maximum supported compression level.
int zxc_min_level(void)
Minimum supported compression level.
size_t zxc_static_dctx_workspace_size(const size_t block_size)
Exact size of a static decompression workspace.
size_t zxc_static_cctx_workspace_size(const size_t block_size, const int level)
Exact size of a static compression workspace.
zxc_dctx * zxc_init_static_dctx(void *workspace, const size_t workspace_size, const size_t block_size)
Initialises a decompression context inside a caller-supplied workspace.
zxc_cctx * zxc_init_static_cctx(void *workspace, const size_t workspace_size, const zxc_compress_opts_t *opts)
Initialises a compression context inside a caller-supplied workspace.
Options for compression.
Definition zxc_opts.h:58
Options for decompression.
Definition zxc_opts.h:86
What a frame's header and footer declare, read without decoding.
Definition zxc_buffer.h:235
uint8_t format_version
Format version of the frame.
Definition zxc_buffer.h:241
uint64_t digest
Archive digest; 0 when has_checksum is 0.
Definition zxc_buffer.h:238
uint8_t has_checksum
1 when blocks carry checksums and the footer a digest.
Definition zxc_buffer.h:242
size_t block_size
Block size, 4 KB to 2 MB.
Definition zxc_buffer.h:239
uint64_t decompressed_size
Source bytes the frame decodes to.
Definition zxc_buffer.h:236
uint32_t dict_id
Dictionary the frame needs; 0 for none.
Definition zxc_buffer.h:240
uint8_t has_seek_table
1 when a seek table precedes the footer.
Definition zxc_buffer.h:243
uint64_t compressed_size
Compressed bytes of the frame, footer included.
Definition zxc_buffer.h:237
Platform-specific symbol visibility macros.
Shared option structures for the ZXC compression APIs.