miniz_oxide/deflate/
buffer.rs

1//! Buffer wrappers implementing default so we can allocate the buffers with `Box::default()`
2//! to avoid stack copies. Box::new() doesn't at the moment, and using a vec means we would lose
3//! static length info.
4
5use crate::deflate::core::{LZ_DICT_SIZE, MAX_MATCH_LEN};
6
7/// Size of the buffer of lz77 encoded data.
8pub const LZ_CODE_BUF_SIZE: usize = 64 * 1024;
9/// Size of the output buffer.
10pub const OUT_BUF_SIZE: usize = (LZ_CODE_BUF_SIZE * 13) / 10;
11pub const LZ_DICT_FULL_SIZE: usize = LZ_DICT_SIZE + MAX_MATCH_LEN - 1 + 1;
12
13pub struct HashBuffers {
14    pub dict: [u8; LZ_DICT_FULL_SIZE],
15    pub next: [u16; LZ_DICT_SIZE],
16    pub hash: [u16; LZ_DICT_SIZE],
17}
18
19impl HashBuffers {
20    #[inline]
21    pub fn reset(&mut self) {
22        *self = HashBuffers::default();
23    }
24}
25
26impl Default for HashBuffers {
27    fn default() -> HashBuffers {
28        HashBuffers {
29            dict: [0; LZ_DICT_FULL_SIZE],
30            next: [0; LZ_DICT_SIZE],
31            hash: [0; LZ_DICT_SIZE],
32        }
33    }
34}
35
36pub struct LocalBuf {
37    pub b: [u8; OUT_BUF_SIZE],
38}
39
40impl Default for LocalBuf {
41    fn default() -> LocalBuf {
42        LocalBuf {
43            b: [0; OUT_BUF_SIZE],
44        }
45    }
46}