MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / read

Method read

src/ore/src/bytes.rs:328–356  ·  view source on GitHub ↗
(&mut self, buf: &mut [u8])

Source from the content-addressed store, hash-verified

326
327 impl<const N: usize> io::Read for SegmentedReader<N> {
328 fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
329 // We've seeked past the end, return nothing.
330 if self.overall_ptr >= self.len {
331 return Ok(0);
332 }
333
334 let (segment, accum_length) = &self.segments[self.segment_ptr];
335
336 // How many bytes we have left in this segment.
337 let remaining_len = accum_length.checked_sub(self.overall_ptr).unwrap();
338 // Position within the segment to begin reading.
339 let segment_pos = segment.len().checked_sub(remaining_len).unwrap();
340
341 // How many bytes we'll read.
342 let len = core::cmp::min(remaining_len, buf.len());
343 // Copy bytes from the current segment into the buffer.
344 let segment_buf = &segment[..];
345 buf[..len].copy_from_slice(&segment_buf[segment_pos..segment_pos + len]);
346
347 // Advance our pointers.
348 self.overall_ptr += len;
349
350 // Advance to the next segment if we've reached the end of the current.
351 if self.overall_ptr == *accum_length {
352 self.segment_ptr += 1;
353 }
354
355 Ok(len)
356 }
357 }
358
359 impl<const N: usize> io::Seek for SegmentedReader<N> {

Callers 7

test_emptyFunction · 0.45
test_io_readFunction · 0.45
test_io_read_multiFunction · 0.45
test_multiFunction · 0.45
test_last_segment_emptyFunction · 0.45

Calls 3

unwrapMethod · 0.80
checked_subMethod · 0.45
lenMethod · 0.45

Tested by 7

test_emptyFunction · 0.36
test_io_readFunction · 0.36
test_io_read_multiFunction · 0.36
test_multiFunction · 0.36
test_last_segment_emptyFunction · 0.36