pub struct RebuiltSource<'a> { /* private fields */ }Expand description
The input a parse decodes to, rebuilt from its literals as it is read, as
a decoder would (C ZSTD_compressSequencesAndLiterals takes the literals
rather than the input). Matches reaching before the start read from
dict; literals past the last sequence are the trailing ones. Only the
last window bytes are held for the matches to copy from (more only
while a match reaching further, into the dictionary, is being copied), so
a frame is built from it without the whole input in memory.
use structured_zstd::encoding::sequences::{ExternalSequence, RebuiltSource};
use std::io::Read;
let parse = [
ExternalSequence { offset: 3, lit_len: 3, match_len: 6, rep: 0 },
ExternalSequence { offset: 0, lit_len: 1, match_len: 0, rep: 0 },
];
let mut source = RebuiltSource::new(&parse, b"abc!", &[], 1 << 10).unwrap();
assert_eq!(source.len(), 10);
let mut out = Vec::new();
source.read_to_end(&mut out).unwrap();
assert_eq!(out, b"abcabcabc!");Implementations§
Source§impl<'a> RebuiltSource<'a>
impl<'a> RebuiltSource<'a>
Sourcepub fn new(
sequences: &'a [ExternalSequence],
literals: &'a [u8],
dict: &'a [u8],
window: usize,
) -> Result<Self, SequenceError>
pub fn new( sequences: &'a [ExternalSequence], literals: &'a [u8], dict: &'a [u8], window: usize, ) -> Result<Self, SequenceError>
Check that sequences and literals rebuild to a whole input with
every match within the output so far plus dict while the output is
within window, and within window after (as validate_parse
checks), and set up to read it.
§Errors
SequenceError::LengthMismatch when the sequences need more literals
than there are, SequenceError::OffsetTooFar when a match reaches
further back than that, SequenceError::ZeroOffset for a match at
offset 0.
Trait Implementations§
Source§impl Read for RebuiltSource<'_>
impl Read for RebuiltSource<'_>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)