Skip to content

Commit

Permalink
Lower QR gen memory consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Mar 7, 2024
1 parent 8bfc2d0 commit 4f9da06
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 413 deletions.
13 changes: 13 additions & 0 deletions rs-matter/src/codec/base38.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ pub fn encode(bytes: &[u8]) -> impl Iterator<Item = char> + '_ {
)
}

pub fn encode_bits(bits: u32, bits_count: u8) -> impl Iterator<Item = char> {
assert!(bits_count <= 24);

let repeat = match bits_count / 8 {
3 => 5,
2 => 4,
1 => 2,
_ => unreachable!(),
};

encode_base38(bits, repeat)
}

fn encode_base38(mut value: u32, repeat: usize) -> impl Iterator<Item = char> {
(0..repeat).map(move |_| {
let remainder = value % RADIX;
Expand Down
7 changes: 4 additions & 3 deletions rs-matter/src/pairing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ pub fn print_pairing_code_and_qr(
buf: &mut [u8],
) -> Result<(), Error> {
let pairing_code = compute_pairing_code(comm_data);
let qr_code = compute_qr_code_text(dev_det, comm_data, discovery_capabilities, buf)?;

pretty_print_pairing_code(&pairing_code);
print_qr_code(qr_code)?;

let (qr_code, remaining_buf) =
compute_qr_code_text(dev_det, comm_data, discovery_capabilities, &[], buf)?;
print_qr_code(qr_code, remaining_buf)?;

Ok(())
}
Expand Down
Loading

0 comments on commit 4f9da06

Please sign in to comment.