Function lzfse_rust::encode_bytes
source · pub fn encode_bytes(src: &[u8], dst: &mut Vec<u8>) -> Result<u64>
Expand description
Encode src
into dst
returning the number of bytes written into dst
.
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
- ErrorKind::Other in case of
src
ordst
buffer overflow.
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(())
}