pub fn decode_with_correction(
s: &str,
) -> Result<(Tag, Payload, Vec<CorrectionDetail>)>Expand description
BCH-error-correcting decode for a single ms1 string.
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 (Tag, Payload)” should use.
Algorithm:
- Parse the input as ms1 (
ms1HRP + codex32 data-part) into a 5-bit symbol vector. - Compute the BCH polymod residue
(
hrp_expand("ms") || data_with_checksum) XOR’d againstcrate::bch::MS_REGULAR_CONST. - Residue
== 0⇒ clean codeword; pass through to the existingdecodeentry point unchanged. - Residue
!= 0⇒ invokecrate::bch_decode::decode_regular_errors. IfNone, returnErr(Error::TooManyErrors { bound: 8 })per plan §2.B.4 D29 error-mapping table. - Apply corrections to the symbol vector, re-verify via polymod (a
defensive catch for pathological 5+-error patterns that fool BM
into returning a degree-≤4 locator with 4 valid roots), and record
one
CorrectionDetailper repaired character. - Re-encode the corrected symbol vector as an ms1 string and forward
it to the existing
decodeentry point.
Per Q1 lock + D29 error-mapping table, any §4-rule error from the
full decode (orphan variants like ThresholdNotZero,
ReservedTagNotEmittedInV01, etc.) surfaces directly; toolkit-side
repair_via_ms_codec (B.7) absorbs these into
RepairError::PostCorrectionDecodeFailed.
Returns (Tag, Payload, Vec<CorrectionDetail>) on success. The
correction-detail vector is in ascending position order; an empty
vector means the input was already a valid codeword.