#![allow(clippy::len_without_is_empty)]
use core::convert::TryInto;
+use core::ops::Range;
use core::{mem, result};
use crate::pod::{from_bytes, slice_from_bytes, Pod};
/// Returns an error if offset or size are out of bounds.
fn read_bytes_at(self, offset: u64, size: u64) -> Result<&'a [u8]>;
- /// Get a reference to a delimited `u8` slice at the given offset.
+ /// Get a reference to a delimited `u8` slice which starts at range.start.
///
/// Does not include the delimiter.
///
- /// Returns an error if offset is out of bounds or the delimiter is
- /// not found.
- fn read_bytes_at_until(self, offset: u64, delimiter: u8) -> Result<&'a [u8]>;
+ /// Returns an error if the range is out of bounds or the delimiter is
+ /// not found in the range.
+ fn read_bytes_at_until(self, range: Range<u64>, delimiter: u8) -> Result<&'a [u8]>;
/// Get a reference to a `u8` slice at the given offset, and update the offset.
///
self.get(offset..).ok_or(())?.get(..size).ok_or(())
}
- fn read_bytes_at_until(self, offset: u64, delimiter: u8) -> Result<&'a [u8]> {
- let offset: usize = offset.try_into().map_err(|_| ())?;
- let bytes = self.get(offset..).ok_or(())?;
+ fn read_bytes_at_until(self, range: Range<u64>, delimiter: u8) -> Result<&'a [u8]> {
+ let start: usize = range.start.try_into().map_err(|_| ())?;
+ let end: usize = range.end.try_into().map_err(|_| ())?;
+ let bytes = self.get(start..end).ok_or(())?;
match memchr::memchr(delimiter, bytes) {
Some(len) => {
// This will never fail.