heddle_format/compression/
dictionaries.rs1const TREE_STATE_V1_ID: u32 = 1;
5const TREE_STATE_V1: &[u8] = include_bytes!("dictionaries/tree-state-v1.zdict");
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum CompressionDictionary {
13 TreeStateV1,
15}
16
17impl CompressionDictionary {
18 pub(crate) const fn id(self) -> u32 {
19 match self {
20 Self::TreeStateV1 => TREE_STATE_V1_ID,
21 }
22 }
23
24 pub(crate) const fn bytes(self) -> &'static [u8] {
25 match self {
26 Self::TreeStateV1 => TREE_STATE_V1,
27 }
28 }
29}
30
31pub(crate) const fn lookup(id: u32) -> Option<&'static [u8]> {
32 match id {
33 TREE_STATE_V1_ID => Some(TREE_STATE_V1),
34 _ => None,
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn dictionary_id_is_registered() {
44 let dictionary = CompressionDictionary::TreeStateV1;
45
46 assert_eq!(lookup(dictionary.id()), Some(dictionary.bytes()));
47 }
48
49 #[test]
50 fn tree_state_v1_asset_is_a_trained_zstd_dictionary() {
51 const ZSTD_DICTIONARY_MAGIC: [u8; 4] = [0x37, 0xA4, 0x30, 0xEC];
52 const EXPECTED_BLAKE3: &str =
53 "ca0ee171814fa7bf91f4c22ef7a1a4d87f7f13a4052b47774e50a8c90a85cd80";
54
55 assert_eq!(TREE_STATE_V1.len(), 8 * 1024);
56 assert_eq!(&TREE_STATE_V1[..4], &ZSTD_DICTIONARY_MAGIC);
57 assert_eq!(
58 blake3::hash(TREE_STATE_V1).to_hex().as_str(),
59 EXPECTED_BLAKE3
60 );
61 }
62}