From 943d7b1498096582b13e6c2957dab2b9e82d7eac Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Mon, 25 May 2020 15:49:55 +0200 Subject: [PATCH] core/byteio: add read_tag/peek_tag for reading four-byte tags --- nihav-core/src/io/byteio.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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) -- 2.30.2