X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=src%2Fio%2Fcodebook.rs;h=5bfd71991e186cfe7c855d2ce11411e1d27d8a59;hb=6465a94691189acfc2fc2909e6e24442a1f0b700;hp=d67e790fe77a339b1be3e85af5090fcf73047f87;hpb=843c8c87a1d0df3a3522f34c9c256be72c7c1f18;p=nihav.git diff --git a/src/io/codebook.rs b/src/io/codebook.rs index d67e790..5bfd719 100644 --- a/src/io/codebook.rs +++ b/src/io/codebook.rs @@ -309,6 +309,25 @@ impl CodebookDescReader for ShortCodebookDescReader { fn len(&mut self) -> usize { self.data.len() } } +pub struct TableCodebookDescReader { + bits: &'static [u8], + codes: &'static [CodeType], + idx_map: fn(usize) -> IndexType, +} + +impl<'a, CodeType, IndexType> TableCodebookDescReader { + pub fn new(codes: &'static [CodeType], bits: &'static [u8], idx_map: fn(usize) -> IndexType) -> Self { + Self { bits, codes, idx_map } + } +} +impl, IndexType> CodebookDescReader for TableCodebookDescReader +{ + fn bits(&mut self, idx: usize) -> u8 { self.bits[idx] } + fn code(&mut self, idx: usize) -> u32 { self.codes[idx].into() } + fn sym (&mut self, idx: usize) -> IndexType { (self.idx_map)(idx) } + fn len(&mut self) -> usize { self.bits.len() } +} + #[cfg(test)] mod test { use super::*;