Skip to main content

parity_line

Function parity_line 

Source
pub fn parity_line(coded: u16, nb_frag: u16, line: &mut [u8]) -> usize
Expand description

Builds one row of the parity matrix: which uncoded fragments a coded one is made of.

§Arguments

  • coded - which coded fragment this is, counting from one. A session’s fragment n past its nb_frag uncoded ones is coded fragment n.
  • nb_frag - how many uncoded fragments the block was cut into.
  • line - a bit for every uncoded fragment, cleared and then filled in, little end first. It must hold at least nb_frag bits.

§Returns

How many fragments the coded one is the exclusive-or of, which is half of nb_frag rounded down.

§Examples

use pamoja_lorawan::packages::fragment::parity_line;

let mut line = [0u8; 1];
assert_eq!(parity_line(1, 6, &mut line), 3);
assert_eq!(line[0] & 0b0011_1111, 0b0001_0011, "fragments 1, 2 and 5");