MCPcopy Create free account
hub / github.com/dermesser/integer-encoding-rs / read_varint

Method read_varint

src/reader.rs:94–114  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

92
93impl<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`.

Callers

nothing calls this directly

Calls 3

finishedMethod · 0.80
pushMethod · 0.80
decodeMethod · 0.80

Tested by

no test coverage detected