If `validate_utf8` this verifies that the first character of `data` is the start of a UTF-8 codepoint Note: This does not verify that the entirety of `data` is valid UTF-8. This should be done by calling [`Self::check_valid_utf8`] after all data has been written
(&mut self, data: &[u8], validate_utf8: bool)
| 62 | /// UTF-8. This should be done by calling [`Self::check_valid_utf8`] after |
| 63 | /// all data has been written |
| 64 | pub fn try_push(&mut self, data: &[u8], validate_utf8: bool) -> Result<()> { |
| 65 | if validate_utf8 { |
| 66 | if let Some(&b) = data.first() { |
| 67 | // A valid code-point iff it does not start with 0b10xxxxxx |
| 68 | // Bit-magic taken from `std::str::is_char_boundary` |
| 69 | if (b as i8) < -0x40 { |
| 70 | return Err(ParquetError::General( |
| 71 | "encountered non UTF-8 data".to_string(), |
| 72 | )); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | self.values.extend_from_slice(data); |
| 78 | |
| 79 | let index_offset = I::from_usize(self.values.len()) |
| 80 | .ok_or_else(|| general_err!("index overflow decoding byte array"))?; |
| 81 | |
| 82 | self.offsets.push(index_offset); |
| 83 | Ok(()) |
| 84 | } |
| 85 | |
| 86 | /// Extends this buffer with a list of keys |
| 87 | /// |