use crate::{ParsedBox, Result};
#[derive(Debug, Clone)]
pub struct SchmBox {
pub scheme_type: u32,
pub scheme_version: u32,
pub scheme_uri: Option<String>,
}
impl SchmBox {
pub fn new(box_: &mut ParsedBox) -> Result<Self> {
let reader = &mut box_.reader;
let flags = box_.flags.unwrap_or(0);
let scheme_type = reader.read_u32()?;
let scheme_version = reader.read_u32()?;
let scheme_uri = if flags & 0x000001 != 0 {
let remaining = (reader.get_length() - reader.get_position()) as usize;
if remaining > 0 {
let bytes = reader.read_bytes_u8(remaining)?;
let s = String::from_utf8_lossy(&bytes);
Some(s.trim_end_matches('\0').to_string())
} else {
None
}
} else {
None
};
Ok(Self {
scheme_type,
scheme_version,
scheme_uri,
})
}
}