Compress
Lifetime Management
CCtx Compression
Provides the upper bound for the compressed size needed to ensure that compressing totalSrcSize
is successful. When compressing multiple inputs, totalSrcSize
must be the sum of the size of each input.
Parameters:
-
totalSrcSize
–The sum of all input sizes
Returns:
The upper bound of the compressed size
Note
This is a very large over-estimation, to be tightened later
A one-shot (blocking) compression function.
Parameters:
-
dst
–The destination buffer to write the compressed data to
-
dstCapacity
–The capacity of the destination buffer
-
src
–The source buffer to compress
-
srcSize
–The size of the source buffer
Returns:
The number of bytes written into dst
, if successful. Otherwise, returns an error.
Compresses a single typed input presented as a ZL_TypedRef
. See below for TypedRef* object creation.
Parameters:
-
dst
–The destination buffer to write the compressed data to
-
dstCapacity
–The capacity of the destination buffer
-
input
–The input to compress
Returns:
The number of bytes written into dst
, if successful. Otherwise, returns an error.
Compresses multiple typed inputs , presented as an array of ZL_TypedRef
. See below for TypedRef* object creation.
Parameters:
-
dst
–The destination buffer to write the compressed data to
-
dstCapacity
–The capacity of the destination buffer
-
inputs
–The inputs to compress
-
nbInputs
–The number of inputs to compress
Returns:
The number of bytes written into dst
, if successful. Otherwise, returns an error.
Note
These inputs will be regenerated together in the same order at decompression time.
Errors and Warnings
Gets the error context for a given ZL_Report. This context is useful for debugging and for submitting bug reports to Zstrong developers.
Parameters:
-
report
–The report to get the error context for
Returns:
A verbose error string containing context about the error that occurred.
Note
: This string is stored within the cctx
and is only valid for the lifetime of the cctx
.
Gets the warnings that were encountered during the lifetime of the most recent compression operation.
Returns:
The array of warnings encountered
Note
The array's and the errors' lifetimes are valid until the next compression operation.
Typed Inputs
Creates a ZL_TypedRef
that represents a regular buffer of bytes.
Parameters:
-
src
–The reference buffer
-
srcSize
–The size of the reference buffer
Returns:
A ZL_TypedRef*
of type ZL_Type_serial
.
Creates a ZL_TypedRef
that represents a concatenated list of fields of a fixed size of structWidth
.
structWidth
can be any size > 0. Even odd sizes (13, 17, etc.) are allowed. All fields are considered concatenated back to back. There is no alignment requirement.
Parameters:
-
start
–The start of the reference buffer
-
structWidth
–The width of each element in the reference buffer.
-
structCount
–The number of elements in the input buffer. The total size will be
structWidth
*structCount
.
Note
Struct in this case is just short-hand for fixed-size-fields. It's not limited to C-style structures.
Creates a ZL_TypedRef
that references an array of numeric values, employing the local host's endianness. Supported widths are 1, 2, 4, and 8 and the input array must be properly aligned (in local ABI).
Parameters:
-
start
–The start of the reference array
-
numWidth
–The width of the numeric values
-
numCount
–The number of elements in the input array. The total size will be
numWidth
*numCount
.
Creates a ZL_TypedRef
referencing a "flat-strings" representation. All "strings" are concatenated into strBuffer
and their lengths are stored in a strLens
array.
Parameters:
-
strBuffer
–The data buffer
-
bufferSize
–The size of the data buffer
-
strLengths
–The lengths array
-
nbStrings
–The number of strings (i.e. the size of the lengths array)
Note
String is just short-hand for variable-size-fields. It's not limited to null-terminated ascii strings. A string can be any blob of bytes, including some containing 0-value bytes, because length is explicit.
Frees the given ZL_TypedRef
.
Parameters:
-
tref
–the object to free
Note
All ZL_TypedRef* objects of any type are released by the same method
Compression Parameters
Sets a global compression parameter via the CCtx.
Parameters:
-
gcparam
–The global compression parameter to set
-
value
–The value to set the global compression parameter to
Returns:
A ZL_Report containing the result of the operation
Note
Parameters set via CCtx have higher priority than parameters set via CGraph.
Note
By default, parameters set via CCtx are reset at the end of the compression session. To preserve them across sessions, set stickyParameters=1.
Reads a compression parameter's configured value from the CCtx.
Parameters:
-
gcparam
–The global compression parameter to read
Returns:
The value set for the given parameter (0 if unset or does not exist)
Resets the parameters in the cctx to a blank state.
Useful when unsure if ZL_CParam_stickyParameters is set to 1.
Note
Sets the Arena for Data* objects in the CCtx. This frees the previous Data Arena and creates a new one. This choice remains sticky, until set again. The default Data Arena is HeapArena.
Parameters:
-
sat
–The Data Arena type to set
Note
This is an advanced (experimental) parameter.
The list of global compression parameters.
Only meaningful at CCtx level (ignored at CGraph level) By default, parameters are reset between compression sessions setting this parameter to 1 keep the parameters across compression sessions.
Sets the format version number to use for encoding. See @ZL_getDefaultEncodingVersion for details. @default 0 means use format version ZL_getDefaultEncodingVersion().
Select behavior when an internal compression stage fails. For example, when expecting an array of 32-bit integers, but the input size is not a clean multiple of 4. Strict mode stops at such stage and outputs an error. Permissive mode engages a generic backup compression mechanism, to successfully complete compression, at the cost of efficiency. At the time of this writing, backup is ZL_GRAPH_COMPRESS_GENERIC. Valid values for this parameter use the ZS2_cv3_* format. @default 0 currently means strict mode. This may change in the future.
Enable checksum of the compressed frame. This is useful to check for corruption that happens after compression. Valid values for this parameter use the ZS2_cv3_* format. @default 0 currently means checksum, might change in the future.
Enable checksum of the uncompressed content contained in the frame. This is useful to check for corruption that happens after compression, or corruption introduced during (de)compression. However, it cannot distinguish the two alone. In order to determine whether it is corruption or a bug in the ZStrong library, you have to enable both compressed and content checksums. Valid values for this parameter use the ZS2_cv3_* format. @default 0 currently means checksum, might change in the future.
Any time an internal data Stream becomes smaller than this size, it gets STORED immediately, without further processing. This reduces processing time, improves decompression speed, and reduce risks of data expansion. Note(@Cyan): follows convention that setting 0 means "default", aka ZL_MINSTREAMSIZE_DEFAULT. Therefore, in order to completely disable the "automatic store" feature, one must pass a negative threshold value.