lzfse_rust/decode/
mod.rs

1mod constants;
2mod decoder;
3mod probe;
4mod reader_core;
5mod ring_decoder;
6mod take;
7
8pub use decoder::LzfseDecoder;
9pub use probe::probe;
10pub use reader_core::ReaderCore;
11pub use ring_decoder::{LzfseReader, LzfseReaderBytes, LzfseRingDecoder};
12pub use take::Take;
13
14/// Decode `src` into `dst` returning the number of bytes written into `dst`.
15///
16///
17/// This is a convenience method that constructs a temporary [LzfseDecoder] instance and then calls
18/// [decode_bytes](LzfseDecoder::decode_bytes). For multiple invocations, creating and reusing a
19/// [LzfseDecoder] instance is more efficient.
20///
21/// # Errors
22///
23/// * [Error](crate::Error) detailing the nature of any errors.
24///
25/// # Aborts
26///
27/// With limited system memory [Vec] may abort when attempting to allocate sufficient memory.
28/// This issue will be resolved in future releases when [try_reserve()](Vec::try_reserve) is
29/// stabilized.
30///
31/// # Examples
32///
33/// ```
34/// use std::io;
35///
36/// fn main() -> io::Result<()> {
37///     // "test" string encoded.
38///     let enc = vec![
39///         0x62, 0x76, 0x78, 0x2d, 0x04, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x62, 0x76,
40///         0x78, 0x24,
41///     ];
42///     let mut dec = Vec::default();
43///     let n_bytes = lzfse_rust::decode_bytes(&enc, &mut dec)?;
44///     assert_eq!(n_bytes, 4);
45///     assert_eq!(dec, b"test");
46///     Ok(())
47/// }
48/// ```
49pub fn decode_bytes(src: &[u8], dst: &mut Vec<u8>) -> crate::Result<u64> {
50    LzfseDecoder::default().decode_bytes(src, dst)
51}