pub(crate) mod rfc4648;
use core::{fmt::Debug, ops::RangeInclusive};
pub trait Alphabet: 'static + Copy + Debug + Eq + Send + Sized + Sync {
const BASE: u8;
const DECODER: &'static [DecodeStep];
const ENCODER: &'static [EncodeStep];
const PADDED: bool;
fn decode_5bits(byte: u8) -> i16 {
let src = byte as i16;
let mut ret: i16 = -1;
for DecodeStep(range, offset) in Self::DECODER {
let start = *range.start() as i16 - 1;
let end = *range.end() as i16 + 1;
ret += (((start - src) & (src - end)) >> 8) & (src + *offset);
}
ret
}
fn encode_5bits(byte: u8) -> u8 {
let src = byte as i16;
let mut diff = src + Self::BASE as i16;
for &EncodeStep(threshold, offset) in Self::ENCODER {
diff -= ((threshold as i16 - src) >> 8) & offset;
}
diff as u8
}
}
#[derive(Debug)]
pub struct DecodeStep(RangeInclusive<u8>, i16);
#[derive(Copy, Clone, Debug)]
pub struct EncodeStep(u8, i16);