use crate::encoder::mode::EncodeBits;
pub fn pad_to_byte_boundary(bits: &mut EncodeBits) {
let remainder = bits.len() % 8;
if remainder != 0 {
for _ in 0..(8 - remainder) {
bits.push(false);
}
}
}
pub fn data_capacity(version: u8, ecc: crate::error_correction::ECCLevel) -> Option<usize> {
use crate::error_correction::ECCLevel;
debug_assert!(version == 1, "data_capacity: unsupported version");
match (version, ecc) {
(1, ECCLevel::L) => Some(17),
(1, ECCLevel::M) => Some(14),
(1, ECCLevel::Q) => Some(11),
(1, ECCLevel::H) => Some(7),
_ => None,
}
}
pub fn fill_with_padding(bits: &mut Vec<u8>, target_bytes: usize) {
let padding = [0xEC, 0x11];
let mut idx = 0;
while bits.len() < target_bytes {
bits.push(padding[idx % 2]);
idx += 1;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_data_capacity_table() {
assert_eq!(data_capacity(1, crate::error_correction::ECCLevel::L), Some(17));
}
}