Hoist common features to BinarySource
This commit is contained in:
parent
7a71f72491
commit
7a7469bed1
|
@ -1,5 +1,5 @@
|
|||
use crate::{ValueClass, AtomClass, Atom};
|
||||
use crate::error::{self, ExpectedKind, io_eof};
|
||||
use crate::error::{self, ExpectedKind};
|
||||
|
||||
use num_bigint::BigInt;
|
||||
use num_traits::cast::{FromPrimitive, ToPrimitive};
|
||||
|
@ -78,18 +78,6 @@ impl<'de, 'src, S: BinarySource<'de>> PackedReader<'de, 'src, S> {
|
|||
PackedReader { source, phantom: PhantomData }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn peek_noeof(&mut self) -> io::Result<u8> {
|
||||
self.peek()?.ok_or_else(io_eof)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn read(&mut self) -> io::Result<u8> {
|
||||
let v = self.peek_noeof()?;
|
||||
self.skip()?;
|
||||
Ok(v)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn varint(&mut self) -> io::Result<u64> {
|
||||
let mut shift = 0;
|
||||
|
|
|
@ -17,6 +17,18 @@ pub trait BinarySource<'de>: Sized {
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#[inline(always)]
|
||||
fn peek_noeof(&mut self) -> io::Result<u8> {
|
||||
self.peek()?.ok_or_else(io_eof)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn read(&mut self) -> io::Result<u8> {
|
||||
let v = self.peek_noeof()?;
|
||||
self.skip()?;
|
||||
Ok(v)
|
||||
}
|
||||
|
||||
fn syntax_error(&mut self, message: &str) -> io::Error {
|
||||
io::Error::new(io::ErrorKind::InvalidData, SyntaxError {
|
||||
position: match self.input_position() {
|
||||
|
|
|
@ -67,17 +67,16 @@ impl<'de, 'src, S: BinarySource<'de>> TextReader<'de, 'src, S>
|
|||
|
||||
#[inline(always)]
|
||||
fn peek_noeof(&mut self) -> io::Result<u8> {
|
||||
self.source.peek()?.ok_or_else(io_eof)
|
||||
self.source.peek_noeof()
|
||||
}
|
||||
|
||||
fn skip(&mut self) -> io::Result<()> {
|
||||
self.source.skip()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn next_byte(&mut self) -> io::Result<u8> {
|
||||
let b = self.peek_noeof()?;
|
||||
self.source.skip()?;
|
||||
Ok(b)
|
||||
self.source.read()
|
||||
}
|
||||
|
||||
fn skip_whitespace(&mut self) {
|
||||
|
|
Loading…
Reference in New Issue