pub unsafe extern "C" fn compression_encode_buffer(
dst_buffer: *mut uint8_t,
dst_size: size_t,
src: *const uint8_t,
src_size: size_t,
scratch_buffer: *mut c_void,
algorithm: compression_algorithm,
) -> size_t
Expand description
Compresses the contents of a source buffer into a destination buffer.
§Arguments
dst_buffer
- Pointer to the buffer that receives the compressed data.dst_size
- Size of the destination buffer in bytes.src
- Pointer to a buffer containing all of the source data.src_size
- Size of the data in the source buffer in bytes.scratch_buffer
- If scratch_buffer is notcrate::objective_c_runtime::nil
, this parameter is a pointer to a buffer that the function uses for scratch purposes. The size of this buffer must be at least the size returned by a previous call tocompression_encode_scratch_buffer_size
.Ifscratch_buffer
iscrate::objective_c_runtime::nil
, the function creates and manages its own scratch space, but with a possible performance hit.algorithm
- Set to the desired algorithm:compression_algorithm::LZ4
,compression_algorithm::ZLIB
,compression_algorithm::LZMA
, orcompression_algorithm::LZFSE
.
§Examples
use rust_macios::{compression::{compression_algorithm, compression_encode_buffer}, kernel::size_t};
let source_string = r#"
Lorem ipsum dolor sit amet consectetur adipiscing elit mi
nibh ornare proin blandit diam ridiculus, faucibus mus
dui eu vehicula nam donec dictumst sed vivamus bibendum
aliquet efficitur. Felis imperdiet sodales dictum morbi
vivamus augue dis duis aliquet velit ullamcorper porttitor,
lobortis dapibus hac purus aliquam natoque iaculis blandit
montes nunc pretium."#;
let source_buffer = source_string.as_bytes();
let mut dest_buffer = vec![0; source_string.len()];
let algorithm = compression_algorithm::LZFSE;
let compressed_size = unsafe {
compression_encode_buffer(
dest_buffer.as_mut_ptr(),
source_string.len() as size_t,
source_buffer.as_ptr(),
source_string.len() as size_t,
std::ptr::null_mut(),
algorithm,
)
};
assert!(compressed_size != 0, "Encoding failed.");
§Returns
The number of bytes written to the destination buffer after compressing the input. If the funtion can’t compress the entire input to fit into the provided destination buffer, or an error occurs, 0 is returned.