sark-http 0.40.0

HTTP wire types, semantics, codecs, and ownership invariants for Sark
Documentation
pub(crate) mod raw;

pub const PAIRS: [[u8; 2]; 100] = {
    let mut pairs = [[0; 2]; 100];
    let mut value = 0;
    while value < pairs.len() {
        pairs[value] = [b'0' + (value / 10) as u8, b'0' + (value % 10) as u8];
        value += 1;
    }
    pairs
};

pub(crate) const fn decimal_length(length: usize) -> ([u8; 20], usize) {
    let mut digits = [0; 20];
    let start = 20 - raw::write(length as u64, &mut digits).len();
    (digits, start)
}

pub trait Wire<const N: usize> {
    /// Writes only the decimal suffix and preserves its padding.
    fn decimal(self, buf: &mut [u8; N]) -> &[u8];
}

impl Wire<10> for u32 {
    fn decimal(self, buf: &mut [u8; 10]) -> &[u8] {
        raw::write(u64::from(self), buf)
    }
}

impl Wire<20> for usize {
    fn decimal(self, buf: &mut [u8; 20]) -> &[u8] {
        raw::write(self as u64, buf)
    }
}

const _: () = assert!(usize::BITS <= u64::BITS);