Skip to main content

LongEccHeader

Struct LongEccHeader 

Source
pub struct LongEccHeader { /* private fields */ }
Expand description

The 32-byte header of a long ECC codeword.

Records the codec geometry (error-correction capability, overlap factor, and lengths) and the payload checksum, and is itself protected by a dedicated checksum and parity bytes.

Implementations§

Source§

impl LongEccHeader

Source

pub const fn checksum(&self) -> u64

Returns the XXH64 checksum of the message and parity bytes.

Source§

impl LongEccHeader

Source

pub fn from_byte_slice( bytes: &[u8], ) -> Result<Self, LongEccHeaderFromByteSliceError>

Parses a header from the first 32 bytes of a slice.

§Errors

Returns InsufficientBytes if bytes holds fewer than 32 bytes, or a LongEccHeaderFromBytesError if parsing the header fails.

Source§

impl LongEccHeader

Source

pub fn from_bytes(bytes: [u8; 32]) -> Result<Self, LongEccHeaderFromBytesError>

Parses a header from its serialized form, correcting errors via the header parity.

§Errors

Returns an error if header correction fails, or if the corrected header carries an incorrect magic number, version, or checksum, a message length that does not fit within the full length, an invalid segment-to-parity ratio, or a full length that does not match the derived codeword length.

Source§

impl LongEccHeader

Source

pub const fn full_length(&self) -> u32

Returns the length of the full codeword, including the header and parity.

Source§

impl LongEccHeader

Source

pub const fn header_checksum(&self) -> u32

Returns the checksum protecting the header fields, folded to 32 bits.

Source§

impl LongEccHeader

Source

pub const fn header_parity(&self) -> [u8; 8]

Returns the parity bytes protecting the header itself.

Source§

impl LongEccHeader

Source

pub const fn last_segment_length(&self) -> u8

Data length of the final ECC segment, always shorter than segment_length.

The constructors enforce 2 * parity < segment_distance, so the subtraction cannot underflow.

Source§

impl LongEccHeader

Source

pub const fn magic(&self) -> u16

Returns the magic number identifying a long ECC header.

Source§

impl LongEccHeader

Source

pub const fn message_length(&self) -> u32

Returns the length of the encoded message.

Source§

impl LongEccHeader

Source

pub fn new( parity: u8, overlap_factor: OverlapFactor, full_length: u32, message_length: u32, checksum: u64, ) -> Result<Self, LongEccHeaderConstructorError>

Constructs a header, computing its checksum and parity.

§Errors

Returns InvalidParityCount if parity exceeds MAX_PARITY, InvalidMessageLength if the header and message do not fit within full_length, InvalidSegmentParityRatio if the parity bytes leave no room for new data within a segment, InvalidFullLength if full_length does not match the codeword length derived from the message length and segment geometry, or GenerateParity if generating the header parity fails.

Source§

impl LongEccHeader

Source

pub const fn overlap_factor(&self) -> OverlapFactor

Returns the overlap factor: the approximate number of codewords covering each byte.

Source§

impl LongEccHeader

Source

pub const fn parity(&self) -> u8

Returns the error-correction capability per segment: the number of byte errors each segment can recover from.

Source§

impl LongEccHeader

Source

pub const fn parity_bytes(&self) -> u8

Returns the number of parity bytes per segment: 2 * parity, two per correctable error.

Source§

impl LongEccHeader

Source

pub const fn segment_count(&self) -> u32

Number of segments: every segment before the last contributes segment_distance - 2 * parity new data bytes, and the final, shorter segment covers the remainder.

The constructors enforce 2 * parity < segment_distance, so the subtraction cannot underflow.

Source§

impl LongEccHeader

Source

pub const fn segment_distance(&self) -> u8

Stride between consecutive segment starts: segment_length divided by the overlap count, rounded down, so segments cover each byte approximately overlap_factor times.

Source§

impl LongEccHeader

Source

pub const fn segment_length(&self) -> u8

Usable data bytes per 255-byte segment: 255 minus the 2 * parity parity bytes.

Source§

impl LongEccHeader

Source

pub fn to_bytes(self) -> [u8; 32]

Serializes the header into its 32-byte wire format.

Source§

impl LongEccHeader

Source

pub const fn version(&self) -> u8

Returns the encoding version number.

Trait Implementations§

Source§

impl Clone for LongEccHeader

Source§

fn clone(&self) -> LongEccHeader

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LongEccHeader

Source§

impl Debug for LongEccHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for LongEccHeader

Source§

impl Hash for LongEccHeader

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for LongEccHeader

Source§

fn cmp(&self, other: &LongEccHeader) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for LongEccHeader

Source§

fn eq(&self, other: &LongEccHeader) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for LongEccHeader

Source§

fn partial_cmp(&self, other: &LongEccHeader) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for LongEccHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToResult for T

Source§

fn ok<Err>(self) -> Result<Self, Err>
where Self: Sized,

Wraps self in Ok(self).
Source§

fn err<Any>(self) -> Result<Any, Self>
where Self: Sized,

Wraps self in Err(self).
Source§

fn some(self) -> Option<Self>
where Self: Sized,

Wraps self in Some(self).
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.