rbx_loader::read

This commit is contained in:
Quaternions 2024-02-08 20:58:00 -08:00
parent 5fc2dda3a1
commit 864f9dc551

View File

@ -1,2 +1,26 @@
use std::io::Read;
mod rbx;
mod primitives;
pub mod rbx;
#[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>(input:R)->Result<strafesnet_common::map::CompleteMap,Error>{
Ok(rbx::convert(load_dom(input)?))
}