diff options
author | Daniel Schadt <kingdread@gmx.de> | 2020-05-21 12:46:02 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2020-05-21 12:46:02 +0200 |
commit | b65630871a5c14489270d1e6bfe19879f1010587 (patch) | |
tree | b1b4eb4f84f8ab2f935c13fd65459bc076dd9c42 /src/raw/parser.rs | |
parent | 1e4eaeae1bfd794213f8eee09cb189e7c6fff4d6 (diff) | |
download | evtclib-b65630871a5c14489270d1e6bfe19879f1010587.tar.gz evtclib-b65630871a5c14489270d1e6bfe19879f1010587.tar.bz2 evtclib-b65630871a5c14489270d1e6bfe19879f1010587.zip |
ignore unknown statechanges in parse_events
The reason why we "unwrap" the error so late is because we want to
recover from this error, which means the file pointer has to be at the
right position. Unwrapping early would leave the pointer in the middle
of an event, which is not what we want.
If we want to bullet-proof this, it might be good to read the whole
event first into a buffer, and then read from that buffer instead.
Diffstat (limited to 'src/raw/parser.rs')
-rw-r--r-- | src/raw/parser.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/raw/parser.rs b/src/raw/parser.rs index 8401146..05f6711 100644 --- a/src/raw/parser.rs +++ b/src/raw/parser.rs @@ -155,6 +155,9 @@ pub enum ParseError { /// The revision used by the file is not known. #[error("unknown revision: {0}")] UnknownRevision(u8), + /// The event contains a statechange that we don't know about. + #[error("unknown statechange event: {0}")] + UnknownStateChange(u8), /// The given ZIP archive is invalid. #[error("invalid archive: {0}")] InvalidZip(#[from] zip::result::ZipError), @@ -312,6 +315,9 @@ pub fn parse_events<R: Read>( let event = parser(&mut input); match event { Ok(x) => result.push(x), + Err(ParseError::UnknownStateChange(_)) => { + // Ignore unknown statechanges, as advised by arcdps. + }, Err(ParseError::Io(ref e)) if e.kind() == ErrorKind::UnexpectedEof => { return Ok(result) } @@ -349,8 +355,9 @@ pub fn parse_event_rev0<R: Read>(mut input: R) -> ParseResult<CbtEvent> { let is_ninety = input.read_u8()? != 0; let is_fifty = input.read_u8()? != 0; let is_moving = input.read_u8()? != 0; + let statechange = input.read_u8()?; let is_statechange = - CbtStateChange::from_u8(input.read_u8()?).unwrap_or(CbtStateChange::Unknown); + CbtStateChange::from_u8(statechange).ok_or(ParseError::UnknownStateChange(statechange)); let is_flanking = input.read_u8()? != 0; let is_shields = input.read_u8()? != 0; @@ -377,7 +384,7 @@ pub fn parse_event_rev0<R: Read>(mut input: R) -> ParseResult<CbtEvent> { is_ninety, is_fifty, is_moving, - is_statechange, + is_statechange: is_statechange?, is_flanking, is_shields, is_offcycle: false, @@ -410,8 +417,9 @@ pub fn parse_event_rev1<R: Read>(mut input: R) -> ParseResult<CbtEvent> { let is_ninety = input.read_u8()? != 0; let is_fifty = input.read_u8()? != 0; let is_moving = input.read_u8()? != 0; + let statechange = input.read_u8()?; let is_statechange = - CbtStateChange::from_u8(input.read_u8()?).unwrap_or(CbtStateChange::Unknown); + CbtStateChange::from_u8(statechange).ok_or(ParseError::UnknownStateChange(statechange)); let is_flanking = input.read_u8()? != 0; let is_shields = input.read_u8()? != 0; let is_offcycle = input.read_u8()? != 0; @@ -439,7 +447,7 @@ pub fn parse_event_rev1<R: Read>(mut input: R) -> ParseResult<CbtEvent> { is_ninety, is_fifty, is_moving, - is_statechange, + is_statechange: is_statechange?, is_flanking, is_shields, is_offcycle, |