mod decode;
mod parse;
mod validate;
pub use validate::validate_slab_values;
use crate::error::UrnaError;
use crate::layout::{SectionEntry, UrnaFooter, UrnaHeader};
use crate::manifest::Manifest;
pub struct UrnaView<'a> {
pub(super) data: &'a [u8],
pub header: UrnaHeader,
pub section_table: Vec<SectionEntry>,
pub manifest: Manifest,
pub footer: UrnaFooter,
}
impl<'a> UrnaView<'a> {
pub fn len(&self) -> usize {
self.data.len()
}
pub fn is_empty(&self) -> bool {
self.data.is_empty()
}
pub fn raw_bytes(&self) -> &[u8] {
self.data
}
pub fn entry(&self, section_id: u32) -> crate::Result<&SectionEntry> {
self.section_table
.iter()
.find(|e| e.section_id == section_id)
.ok_or(UrnaError::SectionNotFound(section_id))
}
pub fn get_section_data(&self, section_id: u32) -> crate::Result<&'a [u8]> {
let entry = self.entry(section_id)?;
let start = entry.offset as usize;
let end = start + entry.size as usize;
Ok(&self.data[start..end])
}
}