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
impl LongEccHeader
Source§impl LongEccHeader
impl LongEccHeader
Sourcepub fn from_byte_slice(
bytes: &[u8],
) -> Result<Self, LongEccHeaderFromByteSliceError>
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
impl LongEccHeader
Sourcepub fn from_bytes(bytes: [u8; 32]) -> Result<Self, LongEccHeaderFromBytesError>
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
impl LongEccHeader
Sourcepub const fn full_length(&self) -> u32
pub const fn full_length(&self) -> u32
Returns the length of the full codeword, including the header and parity.
Source§impl LongEccHeader
impl LongEccHeader
Sourcepub const fn header_checksum(&self) -> u32
pub const fn header_checksum(&self) -> u32
Returns the checksum protecting the header fields, folded to 32 bits.
Source§impl LongEccHeader
impl LongEccHeader
Sourcepub const fn header_parity(&self) -> [u8; 8]
pub const fn header_parity(&self) -> [u8; 8]
Returns the parity bytes protecting the header itself.
Source§impl LongEccHeader
impl LongEccHeader
Sourcepub const fn last_segment_length(&self) -> u8
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
impl LongEccHeader
Source§impl LongEccHeader
impl LongEccHeader
Sourcepub const fn message_length(&self) -> u32
pub const fn message_length(&self) -> u32
Returns the length of the encoded message.
Source§impl LongEccHeader
impl LongEccHeader
Sourcepub fn new(
parity: u8,
overlap_factor: OverlapFactor,
full_length: u32,
message_length: u32,
checksum: u64,
) -> Result<Self, LongEccHeaderConstructorError>
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
impl LongEccHeader
Sourcepub const fn overlap_factor(&self) -> OverlapFactor
pub const fn overlap_factor(&self) -> OverlapFactor
Returns the overlap factor: the approximate number of codewords covering each byte.
Source§impl LongEccHeader
impl LongEccHeader
Source§impl LongEccHeader
impl LongEccHeader
Sourcepub const fn parity_bytes(&self) -> u8
pub const fn parity_bytes(&self) -> u8
Returns the number of parity bytes per segment: 2 * parity, two
per correctable error.
Source§impl LongEccHeader
impl LongEccHeader
Sourcepub const fn segment_count(&self) -> u32
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
impl LongEccHeader
Sourcepub const fn segment_distance(&self) -> u8
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
impl LongEccHeader
Sourcepub const fn segment_length(&self) -> u8
pub const fn segment_length(&self) -> u8
Usable data bytes per 255-byte segment: 255 minus the 2 * parity parity bytes.
Source§impl LongEccHeader
impl LongEccHeader
Trait Implementations§
Source§impl Clone for LongEccHeader
impl Clone for LongEccHeader
Source§fn clone(&self) -> LongEccHeader
fn clone(&self) -> LongEccHeader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more