| 92 | |
| 93 | impl<R: Read> VarIntReader for R { |
| 94 | fn read_varint<VI: VarInt>(&mut self) -> Result<VI> { |
| 95 | let mut buf = [0_u8; 1]; |
| 96 | let mut p = VarIntProcessor::new::<VI>(); |
| 97 | |
| 98 | while !p.finished() { |
| 99 | let read = self.read(&mut buf)?; |
| 100 | |
| 101 | // EOF |
| 102 | if read == 0 && p.i == 0 { |
| 103 | return Err(io::Error::new(io::ErrorKind::UnexpectedEof, "Reached EOF")); |
| 104 | } |
| 105 | if read == 0 { |
| 106 | break; |
| 107 | } |
| 108 | |
| 109 | p.push(buf[0])?; |
| 110 | } |
| 111 | |
| 112 | p.decode() |
| 113 | .ok_or_else(|| io::Error::new(io::ErrorKind::UnexpectedEof, "Reached EOF")) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /// A trait for reading [`FixedInts`] from any other `Reader`. |