mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 10:44:07 +02:00
binread -> binrw
This commit is contained in:
parent
f890ff2847
commit
a785884bc1
5 changed files with 21 additions and 36 deletions
|
|
@ -16,13 +16,15 @@ bv = "0.11.1"
|
|||
itertools = "0.10.3"
|
||||
thiserror = "1.0.30"
|
||||
lzma-rs = "0.2.0"
|
||||
binread = "2.2.0"
|
||||
binrw = "0.8.0"
|
||||
parse-display = "0.5.3"
|
||||
static_assertions = "1.1.0"
|
||||
miette = "3.2.0"
|
||||
|
||||
[dev-dependencies]
|
||||
obj = "0.10"
|
||||
main_error = "0.1.0"
|
||||
miette = { version = "3.2.0", features = ["fancy"] }
|
||||
|
||||
[features]
|
||||
bench = []
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::*;
|
||||
use binread::io::Cursor;
|
||||
use binread::BinReaderExt;
|
||||
use binrw::io::Cursor;
|
||||
use binrw::BinReaderExt;
|
||||
use lzma_rs::decompress::{Options, UnpackedSize};
|
||||
use std::borrow::Cow;
|
||||
|
||||
|
|
|
|||
33
src/data.rs
33
src/data.rs
|
|
@ -1,7 +1,7 @@
|
|||
use crate::bspfile::LumpType;
|
||||
use arrayvec::ArrayString;
|
||||
use binread::io::SeekFrom;
|
||||
use binread::{BinRead, BinResult, ReadOptions};
|
||||
use binrw::io::SeekFrom;
|
||||
use binrw::{BinRead, BinResult, ReadOptions};
|
||||
use bitflags::bitflags;
|
||||
use bv::BitVec;
|
||||
use parse_display::Display;
|
||||
|
|
@ -11,28 +11,11 @@ use std::iter::once;
|
|||
use std::mem::size_of;
|
||||
use std::ops::{Add, Index};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, BinRead)]
|
||||
pub struct Directories {
|
||||
entries: [LumpEntry; 64],
|
||||
}
|
||||
|
||||
impl BinRead for Directories {
|
||||
type Args = <LumpEntry as BinRead>::Args;
|
||||
|
||||
fn read_options<R: binread::io::Read + binread::io::Seek>(
|
||||
reader: &mut R,
|
||||
options: &ReadOptions,
|
||||
args: Self::Args,
|
||||
) -> BinResult<Self> {
|
||||
let mut entries = [LumpEntry::default(); 64];
|
||||
for i in 0..64 {
|
||||
entries[i] = LumpEntry::read_options(reader, options, args)?;
|
||||
}
|
||||
|
||||
Ok(Directories { entries })
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<LumpType> for Directories {
|
||||
type Output = LumpEntry;
|
||||
|
||||
|
|
@ -184,24 +167,20 @@ pub struct Name(ArrayString<64>);
|
|||
impl BinRead for Name {
|
||||
type Args = ();
|
||||
|
||||
fn read_options<R: binread::io::Read + binread::io::Seek>(
|
||||
fn read_options<R: binrw::io::Read + binrw::io::Seek>(
|
||||
reader: &mut R,
|
||||
options: &ReadOptions,
|
||||
args: Self::Args,
|
||||
) -> BinResult<Self> {
|
||||
use std::str;
|
||||
|
||||
let mut name_buf: [u8; 64] = [0; 64];
|
||||
|
||||
for i in 0..64 {
|
||||
name_buf[i] = u8::read_options(reader, options, args)?;
|
||||
}
|
||||
let name_buf = <[u8; 64]>::read_options(reader, options, args)?;
|
||||
|
||||
let zero_pos =
|
||||
name_buf
|
||||
.iter()
|
||||
.position(|c| *c == 0)
|
||||
.ok_or_else(|| binread::Error::AssertFail {
|
||||
.ok_or_else(|| binrw::Error::AssertFail {
|
||||
pos: reader.seek(SeekFrom::Current(0)).unwrap(),
|
||||
message: "Name not null terminated".to_string(),
|
||||
})?;
|
||||
|
|
|
|||
|
|
@ -6,15 +6,16 @@ use crate::bspfile::LumpType;
|
|||
pub use crate::data::TextureFlags;
|
||||
pub use crate::data::Vector;
|
||||
use crate::data::*;
|
||||
use binread::io::Cursor;
|
||||
use binread::BinRead;
|
||||
use binrw::io::Cursor;
|
||||
use binrw::BinRead;
|
||||
use bspfile::BspFile;
|
||||
use itertools::{GroupBy, Itertools};
|
||||
use miette::Diagnostic;
|
||||
use reader::LumpReader;
|
||||
use std::{io::Read, ops::Deref};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[derive(Debug, Error, Diagnostic)]
|
||||
pub enum BspError {
|
||||
#[error("unexpected magic numbers or version, is this a valve bsp?")]
|
||||
UnexpectedHeader(Header),
|
||||
|
|
@ -41,7 +42,7 @@ pub enum BspError {
|
|||
#[error("error while reading data: {0}")]
|
||||
ReadError(#[from] std::io::Error),
|
||||
#[error("error while reading data: {0}")]
|
||||
BinReadError(#[from] binread::Error),
|
||||
BinReadError(#[from] binrw::Error),
|
||||
}
|
||||
|
||||
pub type BspResult<T> = Result<T, BspError>;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::*;
|
||||
use binread::BinReaderExt;
|
||||
use binrw::BinReaderExt;
|
||||
use std::borrow::Cow;
|
||||
use std::mem::size_of;
|
||||
|
||||
|
|
@ -40,7 +40,10 @@ impl<R: BinReaderExt + Read> LumpReader<R> {
|
|||
Ok(entries)
|
||||
}
|
||||
|
||||
pub fn read<T: BinRead>(&mut self) -> BspResult<T> {
|
||||
pub fn read<T: BinRead>(&mut self) -> BspResult<T>
|
||||
where
|
||||
T::Args: Default,
|
||||
{
|
||||
Ok(self.inner.read_le()?)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue