Decode records from `buf` returning the number of bytes read This method returns once `batch_size` objects have been parsed since the last call to [`Self::flush`], or `buf` is exhausted. Any remaining bytes should be included in the next call to [`Self::decode`] There is no requirement that `buf` contains a whole number of records, facilitating integration with arbitrary byte streams, such as th
(&mut self, buf: &[u8])
| 634 | /// integration with arbitrary byte streams, such as that yielded by [`BufRead`] or |
| 635 | /// network sources such as object storage |
| 636 | pub fn decode(&mut self, buf: &[u8]) -> Result<usize, ArrowError> { |
| 637 | if self.to_skip != 0 { |
| 638 | // Skip in units of `to_read` to avoid over-allocating buffers |
| 639 | let to_skip = self.to_skip.min(self.batch_size); |
| 640 | let (skipped, bytes) = self.record_decoder.decode(buf, to_skip)?; |
| 641 | self.to_skip -= skipped; |
| 642 | self.record_decoder.clear(); |
| 643 | return Ok(bytes); |
| 644 | } |
| 645 | |
| 646 | let to_read = self.batch_size.min(self.end - self.line_number) - self.record_decoder.len(); |
| 647 | let (_, bytes) = self.record_decoder.decode(buf, to_read)?; |
| 648 | Ok(bytes) |
| 649 | } |
| 650 | |
| 651 | /// Flushes the currently buffered data to a [`RecordBatch`] |
| 652 | /// |