pub fn find_segment_range(
        &self,
        offset: Offset,
        max_bytes: u32,
        seg_bytes: u32,
    ) -> Result<MessageSetRange, RangeFindError> {
        assert!(max_bytes > 0, "Cannot request 0 bytes to be read");

        // position within the index to start finding a sequence
        let start_ind_pos = match self.find_index_pos(offset) {
            Some(v) => v,
            _ => return Err(RangeFindError::OffsetNotAppended),
        };

        let mem_slice = &self.mmap[..];
        let (_, start_file_pos) = entry!(mem_slice, start_ind_pos);

        // try to get until the end of the segment
        if seg_bytes - start_file_pos < max_bytes {
            trace!("Requested range contains the rest of the segment, does not exceed max bytes");
            return Ok(MessageSetRange {
                file_pos: start_file_pos,
                bytes: seg_bytes - start_file_pos,
            });
        }

        let search_range = &mem_slice[start_ind_pos..self.next_write_pos];
        if search_range.is_empty() {
            return Err(RangeFindError::MessageExceededMaxBytes);
        }

        let end_ind_pos =
            binary_search(search_range, |_, pos| (pos - start_file_pos).cmp(&max_bytes));

        let pos = {
            // binary search will choose the next entry when the left value is less, and the
            // right value is greater and not equal, so fix by grabbing the left
            let (_, pos) = entry!(search_range, end_ind_pos * INDEX_ENTRY_BYTES);
            if end_ind_pos > 0 && pos - start_file_pos > max_bytes {
                trace!("Binary search yielded a range too large, trying entry before");
                let (_, pos) = entry!(search_range, (end_ind_pos - 1) * INDEX_ENTRY_BYTES);
                pos
            } else {
                pos
            }
        };

        let bytes = pos - start_file_pos;
        if bytes == 0 || bytes > max_bytes {
            Err(RangeFindError::MessageExceededMaxBytes)
        } else {
            trace!("Found slice range {}..{}", start_file_pos, pos);
            Ok(MessageSetRange { file_pos: start_file_pos, bytes })
        }
    }
/// Finds the longest message set range within a single segment aligning to
/// the `max_bytes` parameter.
Finds the longest message set range within a single segment aligning to
the `max_bytes` parameter.
Finds the longest message set range within a single segment aligning to the ` max_bytes ` parameter .
pub fn find_segment_range(
        &self,
        offset: Offset,
        max_bytes: u32,
        seg_bytes: u32,
    ) -> Result<MessageSetRange, RangeFindError> {
        assert!(max_bytes > 0, "Cannot request 0 bytes to be read");
        // position within the index to start finding a sequence
        let start_ind_pos = match self.find_index_pos(offset) {
            Some(v) => v,
            _ => return Err(RangeFindError::OffsetNotAppended),
        };
        let mem_slice = &self.mmap[..];
        let (_, start_file_pos) = entry!(mem_slice, start_ind_pos);
        // try to get until the end of the segment
        if seg_bytes - start_file_pos < max_bytes {
            trace!("Requested range contains the rest of the segment, does not exceed max bytes");
            return Ok(MessageSetRange {
                file_pos: start_file_pos,
                bytes: seg_bytes - start_file_pos,
            });
        }
        let search_range = &mem_slice[start_ind_pos..self.next_write_pos];
        if search_range.is_empty() {
            return Err(RangeFindError::MessageExceededMaxBytes);
        }
        let end_ind_pos =
            binary_search(search_range, |_, pos| (pos - start_file_pos).cmp(&max_bytes));
        let pos = {
            // binary search will choose the next entry when the left value is less, and the
            // right value is greater and not equal, so fix by grabbing the left
            let (_, pos) = entry!(search_range, end_ind_pos * INDEX_ENTRY_BYTES);
            if end_ind_pos > 0 && pos - start_file_pos > max_bytes {
                trace!("Binary search yielded a range too large, trying entry before");
                let (_, pos) = entry!(search_range, (end_ind_pos - 1) * INDEX_ENTRY_BYTES);
                pos
            } else {
                pos
            }
        };
        let bytes = pos - start_file_pos;
        if bytes == 0 || bytes > max_bytes {
            Err(RangeFindError::MessageExceededMaxBytes)
        } else {
            trace!("Found slice range {}..{}", start_file_pos, pos);
            Ok(MessageSetRange { file_pos: start_file_pos, bytes })
        }
    }
pub fn find_segment_range ( & self , offset : Offset , max_bytes : u32 , seg_bytes : u32 , ) -> Result < MessageSetRange , RangeFindError > { assert ! ( max_bytes 0 " " ) ; // position within the index to start finding a sequence let start_ind_pos = match self . find_index_pos ( offset ) { Some ( v ) => v , _ => return Err ( RangeFindError :: OffsetNotAppended ) , } ; let mem_slice = & self . mmap [ .. ] ; let ( _ , start_file_pos ) = entry ! ( mem_slice start_ind_pos ) ; // try to get until the end of the segment if seg_bytes - start_file_pos < max_bytes { trace ! ( " " ) ; return Ok ( MessageSetRange { file_pos : start_file_pos , bytes : seg_bytes - start_file_pos , } ) ; } let search_range = & mem_slice [ start_ind_pos .. self . next_write_pos ] ; if search_range . is_empty ( ) { return Err ( RangeFindError :: MessageExceededMaxBytes ) ; } let end_ind_pos = binary_search ( search_range , | _ , pos | ( pos - start_file_pos ) . cmp ( & max_bytes ) ) ; let pos = { // binary search will choose the next entry when the left value is less, and the // right value is greater and not equal, so fix by grabbing the left let ( _ , pos ) = entry ! ( search_range end_ind_pos INDEX_ENTRY_BYTES ) ; if end_ind_pos > 0 && pos - start_file_pos > max_bytes { trace ! ( " " ) ; let ( _ , pos ) = entry ! ( search_range ( end_ind_pos 1 ) INDEX_ENTRY_BYTES ) ; pos } else { pos } } ; let bytes = pos - start_file_pos ; if bytes == 0 || bytes > max_bytes { Err ( RangeFindError :: MessageExceededMaxBytes ) } else { trace ! ( " " start_file_pos pos ) ; Ok ( MessageSetRange { file_pos : start_file_pos , bytes } ) } }
Finds the longest message set range within a single segment aligning to
the `max_bytes` parameter.
Finds the longest message set range within a single segment aligning to the ` max_bytes ` parameter .
&self
offset
Offset
max_bytes
u32
seg_bytes
u32
&self
offset
Offset
max_bytes
u32
seg_bytes
u32