From: Kostya Shishkov Date: Mon, 25 May 2020 13:49:55 +0000 (+0200) Subject: core/byteio: add read_tag/peek_tag for reading four-byte tags X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=943d7b1498096582b13e6c2957dab2b9e82d7eac;p=nihav.git core/byteio: add read_tag/peek_tag for reading four-byte tags --- diff --git a/nihav-core/src/io/byteio.rs b/nihav-core/src/io/byteio.rs index ba3d95c..e7bb6c3 100644 --- a/nihav-core/src/io/byteio.rs +++ b/nihav-core/src/io/byteio.rs @@ -267,6 +267,20 @@ impl<'a> ByteReader<'a> { self.io.peek_byte() } + /// Reads four-byte array from the stream. + pub fn read_tag(&mut self) -> ByteIOResult<[u8; 4]> { + let mut buf = [0u8; 4]; + self.io.read_buf(&mut buf)?; + Ok(buf) + } + + /// Reads four-byte array from the stream without advancing read position. + pub fn peek_tag(&mut self) -> ByteIOResult<[u8; 4]> { + let mut buf = [0u8; 4]; + self.io.peek_buf(&mut buf)?; + Ok(buf) + } + /// Reads 16-bit big-endian integer from the stream. pub fn read_u16be(&mut self) -> ByteIOResult { read_int!(self, u16, 2, to_be)