rbx_loader/src/lib.rs

26 lines
792 B
Rust
Raw Normal View History

use std::io::Read;
mod rbx;
2024-01-31 01:41:16 +00:00
mod primitives;
#[derive(Debug)]
pub enum Error{
RbxBinary(rbx_binary::DecodeError),
RbxXml(rbx_xml::DecodeError),
Io(std::io::Error),
UnknownFileFormat,
}
fn load_dom<R:Read>(input:R)->Result<rbx_dom_weak::WeakDom,Error>{
let mut buf=std::io::BufReader::new(input);
let peek=std::io::BufRead::fill_buf(&mut buf).map_err(Error::Io)?;
match &peek[0..8]{
b"<roblox!"=>return rbx_binary::from_reader(buf).map_err(Error::RbxBinary),
b"<roblox "=>return rbx_xml::from_reader_default(buf).map_err(Error::RbxXml),
_=>Err(Error::UnknownFileFormat),
}
}
pub fn read<R:Read,F:FnMut(&str)->Option<strafesnet_common::model::TextureId>>(input:R,acquire_id:F)->Result<strafesnet_common::map::CompleteMap,Error>{
Ok(rbx::convert(load_dom(input)?,acquire_id))
}