Feed a chunk of bytes into the decoder. This will: Decode at most `Self::batch_size` rows; Return the number of input bytes **consumed** from `data` (which may be 0 if more bytes are required, or less than `data.len()` if a prefix/body straddles the chunk boundary); Defer producing a `RecordBatch` until you call `Self::flush`. # Returns The number of bytes consumed from `data`. # Errors Return
(&mut self, data: &[u8])
| 704 | /// * The Avro body is malformed; |
| 705 | /// * A strict‑mode union rule is violated (see `ReaderBuilder::with_strict_mode`). |
| 706 | pub fn decode(&mut self, data: &[u8]) -> Result<usize, AvroError> { |
| 707 | let mut total_consumed = 0usize; |
| 708 | while total_consumed < data.len() && self.remaining_capacity > 0 { |
| 709 | if self.awaiting_body { |
| 710 | match self.active_decoder.decode(&data[total_consumed..], 1) { |
| 711 | Ok(n) => { |
| 712 | self.remaining_capacity -= 1; |
| 713 | total_consumed += n; |
| 714 | self.awaiting_body = false; |
| 715 | continue; |
| 716 | } |
| 717 | Err(ref e) if is_incomplete_data(e) => break, |
| 718 | Err(e) => return Err(e), |
| 719 | }; |
| 720 | } |
| 721 | match self.handle_prefix(&data[total_consumed..])? { |
| 722 | Some(0) => break, // Insufficient bytes |
| 723 | Some(n) => { |
| 724 | total_consumed += n; |
| 725 | self.apply_pending_schema_if_batch_empty(); |
| 726 | self.awaiting_body = true; |
| 727 | } |
| 728 | None => { |
| 729 | return Err(AvroError::ParseError( |
| 730 | "Missing magic bytes and fingerprint".to_string(), |
| 731 | )); |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | Ok(total_consumed) |
| 736 | } |
| 737 | |
| 738 | // Attempt to handle a prefix at the current position. |
| 739 | // * Ok(None) – buffer does not start with the prefix. |