Function uclcli::compress_into_buffer [−][src]
pub fn compress_into_buffer(
src: &[u8],
dst: &mut [u8]
) -> Result<u32, UclErrorKind>
Expand description
NRV compress a buffer into another buffer.
If dst
is not big enough to hold the compressed
buffer, this will return Err(UclErrorKind::DstTooSmall)
. See also
minimum_compression_buffer_size to find out how big dst
should be.
If compression succeeded, this will return the number of usable bytes in dst
.
Panics
If ucl_init was not called prior to calling this function, this function will panic.
let src = [0; 1024]; let mut dst = vec![0xffu8; uclcli::minimum_compression_buffer_size(src.len())]; let result = uclcli::compress_into_buffer(&src, &mut dst); assert_eq!(result, Ok(12)); let nb = result.unwrap() as usize; assert_eq!(&dst[..nb], b"\x92\x00\xaa\xa1\x00\x00\x00\x00\x00\x04\x80\xff"); assert_eq!(&dst[nb..], &vec![0xffu8; dst.len() - nb]);