]> git.nihav.org Git - nihav.git/commitdiff
nihav_core/io: add read_extend() to byte reader
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 16 Aug 2025 14:03:42 +0000 (16:03 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 16 Aug 2025 14:03:42 +0000 (16:03 +0200)
Also change Vivo demuxer to use it as an example.

nihav-core/src/io/byteio.rs
nihav-vivo/src/demuxers/vivo.rs

index 3642422b4c62e9d0fab2734da8b7df4c1ec961e7..b6c0c334711c92aa7b7ed072c7a32d4fafb46621 100644 (file)
@@ -258,6 +258,13 @@ impl<'a> ByteReader<'a> {
         self.io.read_buf(buf)
     }
 
+    /// Allocates additional space in vector and reads data there. Partial read is treated as success.
+    pub fn read_extend(&mut self, buf: &mut Vec<u8>, add_size: usize) -> ByteIOResult<usize> {
+        let cur_size = buf.len();
+        buf.resize(cur_size + add_size, 0);
+        self.io.read_buf(&mut buf[cur_size..])
+    }
+
     /// Reads data into provided buffer. Partial read is treated as success.
     pub fn read_buf_some(&mut self, buf: &mut [u8])  -> ByteIOResult<usize> {
         self.io.read_buf_some(buf)
index 5d455b6961a80494fe1102e9ece703875d8a3a60..cee07530396235f2b265d9dd5964b0c3146e40c9 100644 (file)
@@ -101,10 +101,7 @@ impl<'a> DemuxCore<'a> for VivoDemuxer<'a> {
             }
             if is_video {
                 validate!(self.v_den != 0);
-                let cur_size = self.video_buf.len();
-                let new_size = cur_size + size;
-                self.video_buf.resize(new_size, 0);
-                                          br.read_buf(&mut self.video_buf[cur_size..])?;
+                                          br.read_extend(&mut self.video_buf, size)?;
                 if (hdr >> 4) == 2 {
                     let mut buf = Vec::new();
                     std::mem::swap(&mut self.video_buf, &mut buf);