pub mod section;
use std::io::{self, Read, Seek, SeekFrom};
use section::{Section, BWTB};
pub struct CompiledSpace<R> {
pub inner: R,
pub bwtb: BWTB,
}
impl<R: Read + Seek> CompiledSpace<R> {
pub fn new(mut inner: R) -> io::Result<Self> {
let bwtb = BWTB::decode(&mut inner)?;
Ok(CompiledSpace {
inner,
bwtb,
})
}
pub fn decode_section<S: Section>(&mut self) -> Option<S> {
let meta = self.bwtb.get_section_meta(S::ID)?;
self.inner.seek(SeekFrom::Start(meta.off as u64)).ok()?;
Some(S::decode(&mut self.inner).unwrap())
}
}