Skip to content

Commit

Permalink
fix our StreamingReader impl (WouldBlock woes)
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp committed Jun 27, 2019
1 parent a91d6d5 commit 825a56f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions core/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,22 +477,33 @@ impl<'a> StreamingReader<'a> {

impl<'a> Reader for StreamingReader<'a> {
fn read_u8(&mut self) -> Result<u8, Error> {
self.stream.read_u8().map_err(map_io_err)
let buf = self.read_fixed_bytes(1)?;
Ok(buf[0])
}

fn read_u16(&mut self) -> Result<u16, Error> {
self.stream.read_u16::<BigEndian>().map_err(map_io_err)
let buf = self.read_fixed_bytes(2)?;
Ok(BigEndian::read_u16(&buf[..]))
}

fn read_u32(&mut self) -> Result<u32, Error> {
self.stream.read_u32::<BigEndian>().map_err(map_io_err)
let buf = self.read_fixed_bytes(4)?;
Ok(BigEndian::read_u32(&buf[..]))
}

fn read_i32(&mut self) -> Result<i32, Error> {
self.stream.read_i32::<BigEndian>().map_err(map_io_err)
let buf = self.read_fixed_bytes(4)?;
Ok(BigEndian::read_i32(&buf[..]))
}

fn read_u64(&mut self) -> Result<u64, Error> {
self.stream.read_u64::<BigEndian>().map_err(map_io_err)
let buf = self.read_fixed_bytes(8)?;
Ok(BigEndian::read_u64(&buf[..]))
}

fn read_i64(&mut self) -> Result<i64, Error> {
self.stream.read_i64::<BigEndian>().map_err(map_io_err)
let buf = self.read_fixed_bytes(8)?;
Ok(BigEndian::read_i64(&buf[..]))
}

/// Read a variable size vector from the underlying stream. Expects a usize
Expand Down

0 comments on commit 825a56f

Please sign in to comment.