pub struct WithChecksum<C, T>where
C: CodeqConfig,{ /* private fields */ }Expand description
A wrapper that appends a checksum to the encoded data.
During encoding, the inner data is first encoded, then a checksum of the encoded data is calculated and appended. During decoding, the inner data is first decoded, then the checksum is verified against the decoded data. If the checksums do not match, an error is returned.
The generic parameter C specifies the checksum configuration to use for protecting the data.
Example:
use codeq::config::Crc32fast;
let wc = WithChecksum::<Crc32fast, u64>::new(5);
let mut b = Vec::new();
let n = wc.encode(&mut b).unwrap();
assert_eq!(n, 16);
assert_eq!(
vec![
0, 0, 0, 0, 0, 0, 0, 5, // data
0, 0, 0, 0, 21, 72, 43, 230, // checksum
],
b
);Create a new wrapper with either WithChecksum::new or CodeqConfig::wrap, for example:
ⓘ
let wc = Crc32fast::wrap(5);Implementations§
Source§impl<C, T> WithChecksum<C, T>where
C: CodeqConfig,
impl<C, T> WithChecksum<C, T>where
C: CodeqConfig,
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwraps and returns the inner data
Trait Implementations§
Source§impl<C, T: Clone> Clone for WithChecksum<C, T>where
C: CodeqConfig + Clone,
impl<C, T: Clone> Clone for WithChecksum<C, T>where
C: CodeqConfig + Clone,
Source§fn clone(&self) -> WithChecksum<C, T>
fn clone(&self) -> WithChecksum<C, T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<C, T: Debug> Debug for WithChecksum<C, T>where
C: CodeqConfig + Debug,
impl<C, T: Debug> Debug for WithChecksum<C, T>where
C: CodeqConfig + Debug,
Source§impl<C, T> Decode for WithChecksum<C, T>where
C: CodeqConfig,
T: Decode,
impl<C, T> Decode for WithChecksum<C, T>where
C: CodeqConfig,
T: Decode,
Source§impl<C, T> Encode for WithChecksum<C, T>where
C: CodeqConfig,
T: Encode,
impl<C, T> Encode for WithChecksum<C, T>where
C: CodeqConfig,
T: Encode,
Source§impl<C, T> FixedSize for WithChecksum<C, T>where
C: CodeqConfig,
T: FixedSize,
impl<C, T> FixedSize for WithChecksum<C, T>where
C: CodeqConfig,
T: FixedSize,
Source§fn encoded_size() -> usize
fn encoded_size() -> usize
Returns the size in bytes that this type will occupy when encoded. Read more
Source§impl<C, T: PartialEq> PartialEq for WithChecksum<C, T>where
C: CodeqConfig + PartialEq,
impl<C, T: PartialEq> PartialEq for WithChecksum<C, T>where
C: CodeqConfig + PartialEq,
impl<C, T: Eq> Eq for WithChecksum<C, T>where
C: CodeqConfig + Eq,
impl<C, T> StructuralPartialEq for WithChecksum<C, T>where
C: CodeqConfig,
Auto Trait Implementations§
impl<C, T> Freeze for WithChecksum<C, T>where
T: Freeze,
impl<C, T> RefUnwindSafe for WithChecksum<C, T>where
T: RefUnwindSafe,
C: RefUnwindSafe,
impl<C, T> Send for WithChecksum<C, T>
impl<C, T> Sync for WithChecksum<C, T>
impl<C, T> Unpin for WithChecksum<C, T>
impl<C, T> UnwindSafe for WithChecksum<C, T>where
T: UnwindSafe,
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more