Skip to main content

orc_format/read/decode/
variable_length.rs

1use crate::error::Error;
2
3use std::io::Read;
4
5pub struct Values<R: Read> {
6    reader: R,
7    scratch: Vec<u8>,
8}
9
10impl<R: Read> Values<R> {
11    pub fn new(reader: R, scratch: Vec<u8>) -> Self {
12        Self { reader, scratch }
13    }
14
15    pub fn next(&mut self, length: usize) -> Result<&[u8], Error> {
16        self.scratch.clear();
17        self.scratch.reserve(length);
18        (&mut self.reader)
19            .take(length as u64)
20            .read_to_end(&mut self.scratch)?;
21
22        Ok(&self.scratch)
23    }
24
25    pub fn into_inner(self) -> Vec<u8> {
26        self.scratch
27    }
28}