1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Static tables for LZX, derived from [MS-PATCH] §2 and the libmspack
//! reference implementation.
// ─── Alphabet sizes ─────────────────────────────────────────────────────
/// Single-byte literals 0..=255 occupy the first 256 main-tree slots.
pub const NUM_CHARS: usize = 256;
/// Low 3 bits of a match main symbol encode a "length header" in 0..=7.
/// Value 7 means "consult LENGTH_TREE for the remaining length footer".
pub const NUM_PRIMARY_LENGTHS: u16 = 7;
/// LENGTH_TREE alphabet size — match lengths longer than NUM_PRIMARY_LENGTHS
/// are encoded via this secondary tree.
pub const NUM_SECONDARY_LENGTHS: usize = 249;
/// Smallest match the decoder ever emits.
pub const MIN_MATCH: u16 = 2;
/// Largest unextended match length.
pub const MAX_MATCH: u16 = 257;
/// Pre-tree alphabet size — 20 symbols, each carrying a 4-bit length, used
/// to decode the delta-encoded code lengths of MAIN_TREE / LENGTH_TREE.
pub const PRETREE_NUM_ELEMENTS: usize = 20;
/// ALIGNED_TREE alphabet size — fixed.
pub const ALIGNED_NUM_ELEMENTS: usize = 8;
/// All frames are 32 KiB except possibly the last in a stream.
///
/// Only consumed by the MS-CAB profile (`crate::lzx`); the Amiga profile in
/// `crate::amiga_lzx` does not chunk its bitstream.
pub const FRAME_SIZE: usize = 32_768;
/// Smallest supported window (per CAB LZX).
pub const MIN_WINDOW_BITS: u8 = 15;
/// Largest supported window (per CAB LZX). LZX DELTA goes higher but we stick
/// to the CAB profile.
///
/// Only consumed by the MS-CAB profile (`crate::lzx`); the Amiga profile uses
/// a fixed `window_bits = 16` and does not range-check.
pub const MAX_WINDOW_BITS: u8 = 21;
// ─── Block types (3-bit field at the start of every block) ──────────────
pub const BLOCKTYPE_VERBATIM: u8 = 1;
pub const BLOCKTYPE_ALIGNED: u8 = 2;
pub const BLOCKTYPE_UNCOMPRESSED: u8 = 3;
// ─── Position slot tables ───────────────────────────────────────────────
/// Number of position slots per window size, indexed by `window_bits - 15`.
pub const POSITION_SLOTS: = ;
/// `EXTRA_BITS[slot]` — number of verbatim bits that follow a position-slot
/// main-element (capped at 17 per spec).
pub const EXTRA_BITS: = ;
/// `POSITION_BASE[slot]` — accumulated base offset for each position slot.
/// Generated from `EXTRA_BITS` by `POSITION_BASE[0] = 0;
/// POSITION_BASE[i] = POSITION_BASE[i-1] + (1 << EXTRA_BITS[i-1])`.
pub const POSITION_BASE: = ;
/// Number of position slots used for a `window_bits` setting in CAB range
/// 15..=21.
pub const
/// MAIN_TREE alphabet size for a given window: 256 literals + 8 length-headers
/// per position slot.
pub const
/// Compile-time upper bound on MAIN_TREE size — large enough for any window
/// in our supported range.
pub const MAIN_TREE_MAX: usize = NUM_CHARS + ; // = 656 for window_bits=21