Skip to main content

decode_with_correction

Function decode_with_correction 

Source
pub fn decode_with_correction(
    strings: &[&str],
) -> Result<(Descriptor, Vec<CorrectionDetail>), Error>
Expand description

BCH-error-correcting decode for a chunk-set of md1 strings.

Per plan §1 Q1 lock — full-decode semantics: this is the single entry point that callers needing both “did anything get repaired?” AND “the fully-decoded descriptor” should use.

Algorithm:

  1. For each chunk, parse the data-part into 5-bit symbols and compute the BCH polymod residue (hrp_expand("md") || data_with_checksum) XOR’d against crate::bch::MD_REGULAR_CONST.
  2. Residue == 0 ⇒ chunk passes through unchanged.
  3. Residue != 0 ⇒ invoke crate::bch_decode::decode_regular_errors. If None, return Err(Error::TooManyErrors { chunk_index, bound: 8 }) per plan §2.B.4 D29 error-mapping table.
  4. Apply corrections to the chunk’s symbol vector, re-encode as a fresh md1 string, and record one CorrectionDetail per repaired character.
  5. After ALL chunks have been processed (any single uncorrectable chunk aborts atomically per plan §1 D28), forward the corrected chunk strings to reassemble to produce the Descriptor.

On success returns (Descriptor, Vec<CorrectionDetail>). The correction-detail vector is in (chunk_index ascending, position ascending within chunk) order; an empty vector means every input chunk was already a valid codeword.