#![cfg(feature = "alloc")]
mod test;
mod dump;
mod flatten;
mod inner;
mod with_lump;
use inner::Inner;
use crate::wad::Wad;
use alloc::vec;
use alloc::boxed::Box;
use alloc::vec::Vec;
#[must_use = "constructing `Builder` does nothing in and of itself"]
#[derive(Clone, Debug)]
pub struct Builder {
data: Vec<u8>,
inner: Inner,
}
impl Builder {
pub fn new_iwad() -> Self {
Self {
data: Vec::new(),
inner: Inner::Wad {
is_pwad: false,
directory: Vec::new(),
},
}
}
pub fn new_pwad() -> Self {
Self {
data: Vec::new(),
inner: Inner::Wad {
is_pwad: true,
directory: Vec::new(),
},
}
}
pub fn new_wad2() -> Self {
Self {
data: Vec::new(),
inner: Inner::Wad2 {
directory: Vec::new(),
},
}
}
pub fn new_wad3() -> Self {
Self {
data: Vec::new(),
inner: Inner::Wad3 {
directory: Vec::new(),
},
}
}
#[must_use]
pub fn buf_size(&self) -> usize {
let mut size = 0;
size += self.inner.tag().header_size();
size += size_of_val(self.data.as_slice());
match self.inner {
Inner::Wad { ref directory, .. } => {
size += size_of_val(directory.as_slice());
}
Inner::Wad2 { ref directory, .. } => {
size += size_of_val(directory.as_slice());
}
Inner::Wad3 { ref directory, .. } => {
size += size_of_val(directory.as_slice());
}
}
size
}
pub fn build(&self) -> Box<Wad> {
let mut buf = vec![0; self.buf_size()].into_boxed_slice();
self.dump(&mut buf);
unsafe { Wad::from_boxed_bytes_unchecked(buf) }
}
}
impl Drop for Builder {
#[inline]
fn drop(&mut self) {}
}