Function lzfse_rust::encode_bytes[][src]

pub fn encode_bytes(src: &[u8], dst: &mut Vec<u8>) -> Result<u64>

Encode src into dst returning the number of bytes written into dst.

Due to internal mechanics src is cannot exceed i32::MAX bytes in length.

This is a convenience method that constructs a temporary LzfseEncoder instance and then calls encode_bytes. For multiple invocations, creating and reusing a LzfseEncoder instance is more efficient.

Errors

Aborts

With limited system memory Vec may abort when attempting to allocate sufficient memory. This issue will be resolved in future releases when try_reserve() is stabilized.

Examples

use std::io;

fn main() -> io::Result<()> {
    let mut enc = Vec::default();
    let n_bytes = lzfse_rust::encode_bytes(b"test", &mut enc)?;
    assert_eq!(n_bytes, 16);
    // "test" string encoded.
    assert_eq!(enc, &[0x62, 0x76, 0x78, 0x2d, 0x04, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74,
                      0x62, 0x76, 0x78, 0x24]);
    Ok(())
}