summaryrefslogtreecommitdiffstats
path: root/nihav-core/src
diff options
context:
space:
mode:
authorKostya Shishkov <[email protected]>2020-05-25 15:49:55 +0200
committerKostya Shishkov <[email protected]>2020-05-25 15:49:55 +0200
commit943d7b1498096582b13e6c2957dab2b9e82d7eac (patch)
treeb44245bf1c2f48cb0a98488bedc0713ef82da4a5 /nihav-core/src
parent586ea1879dd193fa71d16302e1c54deb269bc732 (diff)
core/byteio: add read_tag/peek_tag for reading four-byte tags
Diffstat (limited to 'nihav-core/src')
-rw-r--r--nihav-core/src/io/byteio.rs14
1 files changed, 14 insertions, 0 deletions
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<u16> {
read_int!(self, u16, 2, to_be)