#[derive(Debug, Clone)]
pub struct FileAllocator {
next_offset: u64,
}
impl FileAllocator {
pub fn new(start_offset: u64) -> Self {
Self {
next_offset: start_offset,
}
}
pub fn allocate(&mut self, size: u64, align: u64) -> u64 {
if align > 1 {
let remainder = self.next_offset % align;
if remainder != 0 {
self.next_offset += align - remainder;
}
}
let offset = self.next_offset;
self.next_offset += size;
offset
}
pub fn eof(&self) -> u64 {
self.next_offset
}
}