Take a specified number of bytes from the buffer. Returns as many bytes as possible, or an empty slice if the buffer has already been read to completion.
(&mut self, mut nbytes: usize)
| 316 | /// Returns as many bytes as possible, or an empty slice if the buffer has |
| 317 | /// already been read to completion. |
| 318 | fn take(&mut self, mut nbytes: usize) -> Result<&[u8], Error> { |
| 319 | debug_assert!(self.position <= self.length); |
| 320 | let start_pos = self.position; |
| 321 | let remaining_len = self.length.checked_sub(start_pos).ok_or(InvalidLength)?; |
| 322 | |
| 323 | if nbytes > remaining_len { |
| 324 | nbytes = remaining_len; |
| 325 | } |
| 326 | |
| 327 | self.position = self.position.checked_add(nbytes).ok_or(InvalidLength)?; |
| 328 | Ok(&self.decoded[start_pos..][..nbytes]) |
| 329 | } |
| 330 | |
| 331 | /// Have all of the bytes in this buffer been consumed? |
| 332 | fn is_empty(&self) -> bool { |
no test coverage detected