tamp_compressor_poll

Function tamp_compressor_poll 

Source
pub unsafe extern "C" fn tamp_compressor_poll(
    compressor: *mut TampCompressor,
    output: *mut c_uchar,
    output_size: usize,
    output_written_size: *mut usize,
) -> tamp_res
Expand description

@brief Run a single compression iteration on the internal input buffer.

This is a computationally intensive function.

The most that will ever be written to output in a single invocation is:

(1 + 8 + WINDOW_BITS + 7) // 8

or more simply:

(16 + WINDOW_BITS) // 8

where // represents floor-division. Explanation: * 1 - is_literal bit * 8 - maximum huffman code length * WINDOW_BITS - The number of bits to represent the match index. By default, 10. * 7 - The internal bit buffer may have up to 7 bits from a previous invocation. See NOTE below. * // 8 - Floor divide by 8 to get bytes; the upto remaining 7 bits remain in the internal output bit buffer.

NOTE: Unintuitively, tamp_compressor_poll partially flushes (flushing multiples of 8-bits) the internal output bit buffer at the beginning of the function call (not the end). This means that a previous tamp_compressor_poll call may have placed up to (16 + WINDOW_BITS) bits in the internal output bit buffer. The partial flush at the beginning of tamp_compressor_poll clears as many whole-bytes as possible from this buffer. After this flush, there remains up to 7 bits, to which the current call’s compressed token/literal is added to.

A 3-byte output buffer should be able to handle any compressor configuration.

@param[in,out] compressor TampCompressor object to perform compression with. @param[out] output Pointer to a pre-allocated buffer to hold the output compressed data. @param[in] output_size Size of the pre-allocated output buffer. @param[out] output_written_size Number of bytes written to output. May be NULL.

@return Tamp Status Code. Can return TAMP_OK, TAMP_OUTPUT_FULL, or TAMP_EXCESS_BITS.