use super::TABLE;
pub(crate) fn encode(input: &[u8]) -> Vec<u8> {
let mut output = Vec::with_capacity(input.len()); let mut accumulator: u64 = 0;
let mut bits_used: u8 = 0;
for &byte in input {
let (code, bit_length) = TABLE[byte as usize];
accumulator |= u64::from(code) << (64 - bits_used - bit_length);
bits_used += bit_length;
while bits_used >= 8 {
output.push((accumulator >> 56) as u8);
accumulator <<= 8;
bits_used -= 8;
}
}
if bits_used > 0 {
accumulator |= 0xFF_u64 << (56 - bits_used);
output.push((accumulator >> 56) as u8);
}
output
}