use super::Exception;
use crate::{bitpack::bitpack_encoded, float::AlpFloat, params::pack_params};
#[inline(always)]
#[allow(clippy::too_many_arguments)]
pub fn encode_standard<F: AlpFloat>(
count: u16,
exp: u8,
fac: u8,
use_div: bool,
encoded_ints: &[F::Int],
base: F::Int,
bit_width: u8,
exceptions: &[Exception<F::RawBits>],
dst: &mut Vec<u8>,
) {
let count_bytes = count.to_le_bytes();
let params_bytes = pack_params(exp, fac, bit_width).to_le_bytes();
let type_byte = if use_div {
F::TYPE_DEC_BYTE
} else {
F::TYPE_BYTE
};
let header = [
type_byte,
count_bytes[0],
count_bytes[1],
params_bytes[0],
params_bytes[1],
];
dst.extend_from_slice(&header);
F::write_base(base, dst);
bitpack_encoded::<F>(encoded_ints, base, bit_width, dst);
if !exceptions.is_empty() {
let exc_count = exceptions.len() as u16;
dst.extend_from_slice(&exc_count.to_le_bytes());
for exc in exceptions {
F::write_exception(exc.pos, exc.bits, dst);
}
}
}