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
//! RAR 2.x decoder constants.
//!
//! The length-base / length-extra-bits / offset-base / offset-extra-bits
//! tables, plus short-match-base / short-match-extra-bits, are dictated by
//! the wire format. See XADMaster's XADRAR20Handle.m for the same constants
//! (LGPL — we don't copy code, but the constants are facts).
/// 1 MiB sliding window — XADMaster initializes `XADFastLZSSHandle` with
/// `windowSize:0x100000` for RAR2 streams. The window size is *fixed* in
/// RAR2; unlike RAR3/RAR5 it isn't negotiated in the stream header.
pub const WINDOW_SIZE: usize = 0x100000;
pub const WINDOW_MASK: usize = WINDOW_SIZE - 1;
/// Main-tree alphabet size (literals 0..=255 + 42 specials).
pub const MAIN_TREE_SIZE: usize = 298;
/// Length-tree alphabet size for matches following an offset symbol.
pub const LENGTH_TREE_SIZE: usize = 28;
/// Offset-tree alphabet size.
pub const OFFSET_TREE_SIZE: usize = 48;
/// Pretree alphabet (the 4-bit-length prefix code that decodes the others).
pub const PRETREE_SIZE: usize = 19;
/// Audio per-channel tree alphabet (0..=255 + EOF/restart sentinel = 257).
pub const AUDIO_TREE_SIZE: usize = 257;
/// `numchannels * AUDIO_TREE_SIZE` upper bound (1..=4 channels).
pub const MAX_AUDIO_LENGTHS: usize = 4 * AUDIO_TREE_SIZE; // 1028
/// Sum of MAIN_TREE_SIZE + OFFSET_TREE_SIZE + LENGTH_TREE_SIZE.
pub const NON_AUDIO_LENGTHS: usize = MAIN_TREE_SIZE + OFFSET_TREE_SIZE + LENGTH_TREE_SIZE; // 374
/// Same size as XADRAR20Handle's `lengthtable[1028]`. The non-audio path
/// uses the first 374 entries; the audio path uses up to 1028 (4 × 257).
pub const LENGTH_TABLE_SIZE: usize = MAX_AUDIO_LENGTHS;
// --- Long-match (symbols >= 270) length & offset tables ---------------------
/// Length base for the 28 long-match length symbols. Indexed by
/// `symbol - 270` (or `symbol - 256` for the 4-way "old-offset" branch).
/// Symbols 0..=7 are exact (no extra bits); higher indices carry extra bits
/// per [`LENGTH_EXTRA`].
pub const LENGTH_BASE: = ;
/// Number of extra raw bits to read after each long-match length symbol.
pub const LENGTH_EXTRA: = ;
/// Offset base for the 48 long-match offset symbols.
pub const OFFSET_BASE: = ;
/// Extra-bit count for each long-match offset symbol.
pub const OFFSET_EXTRA: = ;
// --- Short-match (symbols 261..=268) tables ---------------------------------
/// Base offsets for the 8 short-match symbols (261..=268). Indexed by
/// `symbol - 261`.
pub const SHORT_BASE: = ;
/// Extra bits for each short-match symbol.
pub const SHORT_EXTRA: = ;
// --- Special main-tree symbol numbers ---------------------------------------
/// First main-tree symbol indicating an "old-offset" reuse (256..=260).
pub const SYM_REPEAT_LAST: u16 = 256;
/// 256..=260 are the five repeat-offset slots (the most recent four +
/// "the very last match again").
pub const SYM_OLD_OFFSET_END: u16 = 260;
/// Start of the short-match range (261..=268).
pub const SYM_SHORT_FIRST: u16 = 261;
pub const SYM_SHORT_LAST: u16 = 268;
/// 269 = "re-read the per-block trees and continue".
pub const SYM_REREAD_TREES: u16 = 269;
/// First long-match symbol; the length-base index is `symbol - 270`.
pub const SYM_LONG_FIRST: u16 = 270;