use wram::AlignedBuf;
pub(crate) struct DiskWindow {
buf: Option<AlignedBuf>,
offset: u64,
}
impl DiskWindow {
#[inline]
pub const fn new() -> Self {
Self {
buf: None,
offset: 0,
}
}
#[inline]
pub fn covers(&self, offset: u64, need: usize) -> bool {
match &self.buf {
Some(buf) => offset >= self.offset && offset + need as u64 <= self.offset + buf.len() as u64,
None => false,
}
}
#[inline]
pub fn replace(&mut self, offset: u64, buf: AlignedBuf) {
self.offset = offset;
self.buf = Some(buf);
}
#[inline]
pub fn offset(&self) -> u64 {
self.offset
}
#[inline]
pub fn slice(&self) -> &[u8] {
unsafe { self.buf.as_ref().unwrap_unchecked() }.as_slice()
}
}