pub struct ByteIterator<'a> {
buf: &'a [u8],
index: usize,
}
impl ByteIterator<'_> {
pub fn new(buf: &[u8]) -> ByteIterator {
ByteIterator { buf, index: 0 }
}
pub fn rewind(&mut self) {
self.index -= 1;
}
#[allow(unused)]
pub fn set_index(&mut self, new_index: usize) {
self.index = new_index;
}
#[allow(unused)]
pub fn is_eof(&self) -> bool {
self.index >= self.buf.len()
}
pub fn prev(&self) -> Option<&u8> {
self.buf.get(self.index - 1)
}
pub fn read(&mut self) -> Option<&u8> {
let byte = self.buf.get(self.index);
self.index += 1;
byte
}
pub fn peek(&self) -> Option<&u8> {
self.buf.get(self.index)
}
}
#[macro_export]
#[doc(hidden)]
macro_rules! read {
($b_iter: expr) => {{
let v = *match $b_iter.read() {
Some(byte) => byte,
None => break,
};
v
}};
}
pub type ByteString = Box<[u8]>;