#[non_exhaustive]pub struct DecodedString {
pub code: BchCode,
pub corrections_applied: usize,
pub corrected_positions: Vec<usize>,
pub data_with_checksum: Vec<u8>,
}Expand description
Result of a successful mk1 string decode at the BCH layer.
Use Self::data to access the data part as 5-bit values (header
symbols + payload, checksum stripped); the string-layer reassembler
in crate::string_layer splits header symbols off and feeds the
remaining payload through five_bit_to_bytes to recover the original
fragment bytes.
The full post-correction 5-bit symbol sequence (data plus the trailing
13- or 15-char checksum) is retained internally as Self::data_with_checksum
and can be queried by Self::corrected_char_at for any position in
the data part — including positions that fall inside the checksum region.
The decoder-report layer uses this to surface the real corrected
character when BCH ECC repairs a substitution inside the checksum
(parallels md-codec’s Correction.corrected field).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.code: BchCodeDetected BCH code variant.
corrections_applied: usizeNumber of substitution errors corrected (0 = clean input, 1 = recovered).
corrected_positions: Vec<usize>Indices into the data-part (chars after "md1") of any corrected positions.
data_with_checksum: Vec<u8>Full post-correction 5-bit symbol sequence (data part + checksum), in
the same coordinate system as Self::corrected_positions.
Length is data().len() + 13 (regular code) or data().len() + 15
(long code). Indices 0..data().len() mirror Self::data symbol-for-symbol;
indices data().len().. are the corrected checksum symbols. Use
Self::corrected_char_at for the human-readable bech32 character at
any position.
Implementations§
Source§impl DecodedString
impl DecodedString
Sourcepub fn data(&self) -> &[u8] ⓘ
pub fn data(&self) -> &[u8] ⓘ
Data part as 5-bit values, with the trailing checksum stripped.
Returns a slice into Self::data_with_checksum — the data part is
data_with_checksum[..len - checksum_len], where checksum_len is 13
for BchCode::Regular and 15 for BchCode::Long.
Sourcepub fn corrected_char_at(&self, char_position: usize) -> char
pub fn corrected_char_at(&self, char_position: usize) -> char
Look up the corrected bech32 character at the given position in the
data part (chars after the "md1" HRP+separator).
char_position is 0-indexed. Positions 0..data().len() are in the
data region; positions data().len()..data().len() + checksum_len are
inside the BCH checksum (13 chars for BchCode::Regular, 15 for
BchCode::Long). All positions return the post-correction
character — i.e., what the symbol should be after BCH repair, which
is exactly what [Correction.corrected][crate::Correction::corrected]
is documented to report.
§Panics
Panics if char_position >= data_with_checksum.len(). Callers are
responsible for clamping the position to a valid range; in the decode
pipeline this is guaranteed by the BCH layer (it never reports a
corrected_position outside data_with_checksum). Note that
data_with_checksum includes the checksum region; “outside the data
part” elsewhere in this crate excludes the checksum and is a tighter
bound than what this method requires.
Trait Implementations§
Source§impl Clone for DecodedString
impl Clone for DecodedString
Source§fn clone(&self) -> DecodedString
fn clone(&self) -> DecodedString
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DecodedString
impl Debug for DecodedString
Source§impl PartialEq for DecodedString
impl PartialEq for DecodedString
Source§fn eq(&self, other: &DecodedString) -> bool
fn eq(&self, other: &DecodedString) -> bool
self and other values to be equal, and is used by ==.