Improve error handling in the map and array custom parsers
This commit is contained in:
parent
f304304d19
commit
6b7d4c66dd
2 changed files with 6 additions and 6 deletions
|
@ -6,12 +6,12 @@ use binrw::{BinRead, BinResult, binrw};
|
||||||
fn custom_parser(size_in_bytes: u32, value_type: &str) -> BinResult<Vec<ArrayEntry>> {
|
fn custom_parser(size_in_bytes: u32, value_type: &str) -> BinResult<Vec<ArrayEntry>> {
|
||||||
let mut result = Vec::<ArrayEntry>::new();
|
let mut result = Vec::<ArrayEntry>::new();
|
||||||
|
|
||||||
let mut current = reader.stream_position().unwrap();
|
let mut current = reader.stream_position()?;
|
||||||
let end = current + size_in_bytes as u64 - 4;
|
let end = current + size_in_bytes as u64 - 4;
|
||||||
|
|
||||||
while current < end {
|
while current < end {
|
||||||
result.push(ArrayEntry::read_options(reader, endian, (value_type,)).unwrap());
|
result.push(ArrayEntry::read_options(reader, endian, (value_type,))?);
|
||||||
current = reader.stream_position().unwrap();
|
current = reader.stream_position()?;
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,12 +185,12 @@ fn custom_parser(
|
||||||
) -> BinResult<Vec<MapEntry>> {
|
) -> BinResult<Vec<MapEntry>> {
|
||||||
let mut result = Vec::<MapEntry>::new();
|
let mut result = Vec::<MapEntry>::new();
|
||||||
|
|
||||||
let mut current = reader.stream_position().unwrap();
|
let mut current = reader.stream_position()?;
|
||||||
let end = current + size_in_bytes as u64 - 5 - 3;
|
let end = current + size_in_bytes as u64 - 5 - 3;
|
||||||
|
|
||||||
while current < end {
|
while current < end {
|
||||||
result.push(MapEntry::read_options(reader, endian, (key_type, value_type)).unwrap());
|
result.push(MapEntry::read_options(reader, endian, (key_type, value_type))?);
|
||||||
current = reader.stream_position().unwrap();
|
current = reader.stream_position()?;
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue