use super::asset::Result;
pub(super) const MAX_IMAGE_SIDE: u32 = 16384;
#[cfg(not(target_arch = "wasm32"))]
pub(super) const MAX_LOAD_BYTES: u64 = 4 << 30;
#[cfg(target_arch = "wasm32")]
pub(super) const MAX_LOAD_BYTES: u64 = 1 << 30;
pub(super) struct Budget {
pub(super) remaining: u64,
}
impl Budget {
pub(super) fn new() -> Self {
Self {
remaining: MAX_LOAD_BYTES,
}
}
pub(super) fn remaining(&self) -> u64 {
self.remaining
}
pub(super) fn charge(&mut self, bytes: u64) -> Result<()> {
self.remaining = self.remaining.checked_sub(bytes).ok_or_else(|| {
format!("data exceeds the {MAX_LOAD_BYTES} byte load budget; split the asset")
})?;
Ok(())
}
}