core/byteio: add read_tag/peek_tag for reading four-byte tags
authorKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 25 May 2020 13:49:55 +0000 (15:49 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Mon, 25 May 2020 13:49:55 +0000 (15:49 +0200)
nihav-core/src/io/byteio.rs

index ba3d95c08a3044a4dc9264f38c4de37a03cb6796..e7bb6c396a817e9c4cc50f94c32a6616832880d5 100644 (file)
@@ -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<u16> {
         read_int!(self, u16, 2, to_be)