rawbin 1.0.0

Minimal, pure-Rust bincode-like serializer/deserializer used by pacm.
Documentation
use crate::config::Config;

/// Encode a length-prefixed byte slice according to `Config`.
/// - if `cfg.use_varint` is true, length is varint-encoded (LEB-like)
/// - otherwise length is a little-endian `u64`
pub fn encode_len_prefixed(bytes: &[u8], cfg: Config) -> Vec<u8> {
    let mut out = Vec::with_capacity(bytes.len() + 8);
    if cfg.use_varint {
        let mut v = bytes.len() as u64;
        loop {
            let mut b = (v & 0x7F) as u8;
            v >>= 7;
            if v != 0 {
                b |= 0x80;
            }
            out.push(b);
            if v == 0 { break; }
        }
    } else {
        out.extend_from_slice(&(bytes.len() as u64).to_le_bytes());
    }
    out.extend_from_slice(bytes);
    out
}

/// Convenience for encoding a UTF-8 string with the selected config.
pub fn encode_str(s: &str, cfg: Config) -> Vec<u8> {
    encode_len_prefixed(s.as_bytes(), cfg)
}