| 172 | } |
| 173 | |
| 174 | fn copy_to_bytes(&mut self, len: usize) -> Bytes { |
| 175 | // If possible, use the zero-copy implementation on individual segments. |
| 176 | if let Some((seg, _len)) = self.segments.first_mut() { |
| 177 | if len <= seg.len() { |
| 178 | self.len -= len; |
| 179 | return seg.copy_to_bytes(len); |
| 180 | } |
| 181 | } |
| 182 | // Otherwise, fall back to a generic implementation. |
| 183 | assert!( |
| 184 | len <= self.len(), |
| 185 | "tried to copy {len} bytes with {} remaining", |
| 186 | self.len() |
| 187 | ); |
| 188 | let mut out = BytesMut::with_capacity(len); |
| 189 | out.put(self.take(len)); |
| 190 | out.freeze() |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | #[cfg(feature = "parquet")] |