Path: blob/main/crates/polars-parquet/src/parquet/encoding/plain_byte_array.rs
6940 views
/// Decodes according to [Plain strings](https://github.com/apache/parquet-format/blob/master/Encodings.md#plain-plain--0),1/// prefixes, lengths and values2/// # Implementation3/// This struct does not allocate on the heap.4use crate::parquet::error::ParquetError;56#[derive(Debug)]7pub struct BinaryIter<'a> {8values: &'a [u8],9length: Option<usize>,10}1112impl<'a> BinaryIter<'a> {13pub fn new(values: &'a [u8], length: Option<usize>) -> Self {14Self { values, length }15}16}1718impl<'a> Iterator for BinaryIter<'a> {19type Item = Result<&'a [u8], ParquetError>;2021#[inline]22fn next(&mut self) -> Option<Self::Item> {23if self.values.len() < 4 {24return None;25}26if let Some(x) = self.length.as_mut() {27*x = x.saturating_sub(1)28}29let length = u32::from_le_bytes(self.values[0..4].try_into().unwrap()) as usize;30self.values = &self.values[4..];31if length > self.values.len() {32return Some(Err(ParquetError::oos(33"A string in plain encoding declares a length that is out of range",34)));35}36let (result, remaining) = self.values.split_at(length);37self.values = remaining;38Some(Ok(result))39}4041#[inline]42fn size_hint(&self) -> (usize, Option<usize>) {43(self.length.unwrap_or_default(), self.length)44}45}464748