From 434048f7252c2490f04866c9a08eff6eb1688dc3 Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Tue, 28 Jul 2015 01:04:59 +0200 Subject: Properly handle EOF while reading msgpack markers If there's no more data, we stop returning events. This will still error on EOF while reading msgpack data though, which is sort-of intended. --- src/format/msgpack.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/format/msgpack.rs b/src/format/msgpack.rs index d823a6d..09bd2bb 100644 --- a/src/format/msgpack.rs +++ b/src/format/msgpack.rs @@ -33,8 +33,12 @@ pub struct Iter<'a, R: 'a> where R: BufRead { impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { type Item = ::Result>; fn next(&mut self) -> Option<::Result>> { - Some(Decodable::decode(&mut Decoder::new(&mut self.input)) - .map_err(|e| ::IlcError::MsgpackDecode(e))) + use msgpack::decode; + match Event::decode(&mut Decoder::new(&mut self.input)) { + Ok(e) => Some(Ok(e)), + Err(decode::serialize::Error::InvalidMarkerRead(decode::ReadError::UnexpectedEOF)) => None, + Err(e) => Some(Err(::IlcError::MsgpackDecode(e))) + } } } -- cgit v1.2.3