1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-03 16:44:06 +02:00

add peek method to read without advancing

This commit is contained in:
Robin Appelman 2023-10-09 15:02:25 +02:00
commit dd1f0f0808
2 changed files with 41 additions and 0 deletions

View file

@ -680,6 +680,24 @@ where
T::read(self, size)
}
/// Read a value based on the provided type without advancing the stream
#[inline]
pub fn peek<T: BitRead<'a, E>>(&mut self) -> Result<T> {
let pos = self.pos;
let result = T::read(self);
self.pos = pos;
result
}
/// Read a value based on the provided type and size without advancing the stream
#[inline]
pub fn peek_sized<T: BitReadSized<'a, E>>(&mut self, size: usize) -> Result<T> {
let pos = self.pos;
let result = T::read(self, size);
self.pos = pos;
result
}
#[doc(hidden)]
#[inline]
pub unsafe fn read_sized_unchecked<T: BitReadSized<'a, E>>(