pub struct SnapshotPlan<'a> { /* private fields */ }Expand description
Validated plan that can compute its encoded length and write itself.
SnapshotPlan performs all kind-order, alignment, and count checks at
construction. After construction, encoded_len
and write_into are guaranteed to succeed for any
caller-supplied buffer that is at least encoded_len() bytes long.
§Performance
Construction is O(s) for s sections. encoded_len is O(s);
write_into is O(s + total payload bytes) (payload copies plus one
checksum fold per section).
Implementations§
Source§impl<'a> SnapshotPlan<'a>
impl<'a> SnapshotPlan<'a>
Sourcepub fn new(sections: &'a [PendingSection<'a>]) -> Result<Self, PlanError>
pub fn new(sections: &'a [PendingSection<'a>]) -> Result<Self, PlanError>
Sourcepub const fn section_count(&self) -> usize
pub const fn section_count(&self) -> usize
Sourcepub fn encoded_len(&self) -> Result<usize, PlanError>
pub fn encoded_len(&self) -> Result<usize, PlanError>
Computes the total bytes the encoded snapshot will occupy.
§Errors
Returns PlanError::PayloadOverflow when offset arithmetic
exceeds usize or u64 representable values.
§Performance
This function is O(s) for s sections.
Sourcepub fn write_into(
&self,
out: &mut [u8],
checksum: Checksum32,
) -> Result<usize, PlanError>
pub fn write_into( &self, out: &mut [u8], checksum: Checksum32, ) -> Result<usize, PlanError>
Writes the encoded snapshot into out and returns the number of
bytes written.
Each section entry records checksum(0, payload); the header records
the table checksum over the entry bytes. Padding bytes between the
section table and each section payload are zero-filled
deterministically; the resulting bytes are stable for any logical
input and checksum function.
§Errors
Returns PlanError::BufferTooSmall when out.len() is less than
encoded_len or PlanError::PayloadOverflow
when offset arithmetic overflows during the write walk.
§Performance
This function is O(s + total payload bytes) (payload copies plus
one checksum fold per section and one over the table).
Trait Implementations§
Source§impl<'a> Clone for SnapshotPlan<'a>
impl<'a> Clone for SnapshotPlan<'a>
Source§fn clone(&self) -> SnapshotPlan<'a>
fn clone(&self) -> SnapshotPlan<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more