bug: Fix synchronous binary operations

This commit is contained in:
Lucas Schwiderski 2022-12-09 14:50:54 +01:00
parent d1ff738098
commit 4ac9c88dfc
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8

View file

@ -154,7 +154,7 @@ where
} }
pub mod sync { pub mod sync {
use std::io::{self, Read, Seek, SeekFrom, Write}; use std::io::{self, Read, Seek, SeekFrom};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use color_eyre::eyre::WrapErr; use color_eyre::eyre::WrapErr;
@ -163,12 +163,12 @@ pub mod sync {
macro_rules! make_read { macro_rules! make_read {
($func:ident, $read:ident, $type:ty) => { ($func:ident, $read:ident, $type:ty) => {
fn $read(&mut self) -> io::Result<$type> { fn $read(&mut self) -> io::Result<$type> {
ReadBytesExt::$func::<LittleEndian>(&mut self) ReadBytesExt::$func::<LittleEndian>(self)
} }
fn $func(&mut self) -> Result<$type> { fn $func(&mut self) -> Result<$type> {
let res = ReadExt::$read(&mut self) let res =
.wrap_err(concat!("failed to read ", stringify!($type))); ReadExt::$read(self).wrap_err(concat!("failed to read ", stringify!($type)));
if res.is_ok() { if res.is_ok() {
return res; return res;
@ -189,11 +189,11 @@ pub mod sync {
macro_rules! make_write { macro_rules! make_write {
($func:ident, $write:ident, $type:ty) => { ($func:ident, $write:ident, $type:ty) => {
fn $write(&mut self, val: $type) -> io::Result<()> { fn $write(&mut self, val: $type) -> io::Result<()> {
WriteBytesExt::$func::<LittleEndian>(&mut self, val) WriteBytesExt::$func::<LittleEndian>(self, val)
} }
fn $func(&mut self, val: $type) -> Result<()> { fn $func(&mut self, val: $type) -> Result<()> {
let res = WriteExt::$write(&mut self, val) let res = WriteExt::$write(self, val)
.wrap_err(concat!("failed to write ", stringify!($type))); .wrap_err(concat!("failed to write ", stringify!($type)));
if res.is_ok() { if res.is_ok() {
@ -215,7 +215,7 @@ pub mod sync {
macro_rules! make_skip { macro_rules! make_skip {
($func:ident, $read:ident, $type:ty) => { ($func:ident, $read:ident, $type:ty) => {
fn $func(&mut self, cmp: $type) -> Result<()> { fn $func(&mut self, cmp: $type) -> Result<()> {
let val = ReadExt::$read(&mut self)?; let val = ReadExt::$read(self)?;
if val != cmp { if val != cmp {
let pos = self.stream_position().unwrap_or(u64::MAX); let pos = self.stream_position().unwrap_or(u64::MAX);
@ -235,7 +235,7 @@ pub mod sync {
pub trait ReadExt: ReadBytesExt + Seek { pub trait ReadExt: ReadBytesExt + Seek {
fn read_u8(&mut self) -> io::Result<u8> { fn read_u8(&mut self) -> io::Result<u8> {
ReadBytesExt::read_u8(&mut self) ReadBytesExt::read_u8(self)
} }
make_read!(read_u32, read_u32_le, u32); make_read!(read_u32, read_u32_le, u32);