//! pkt-line framing for smart HTTP. use crate::service::GitService; /// The flush packet `0000`. pub const FLUSH_PKT: &[u8] = b"0000"; /// Frames `data` as a pkt-line (4 hex length digits, including the 4 length bytes). /// The payload must be at most 65516 bytes; callers pass short protocol strings. pub fn pkt_line(data: &str) -> Vec { let len = data.len() + 4; debug_assert!(len <= 0xffff, "pkt-line payload too long"); let mut out = format!("{len:04x}").into_bytes(); out.extend_from_slice(data.as_bytes()); out } /// The smart-HTTP advertisement preamble: `# service=git-` as a pkt-line, then a flush. pub fn service_advertisement_header(svc: GitService) -> Vec { let mut out = pkt_line(&format!("# service={}\n", svc.name())); out.extend_from_slice(FLUSH_PKT); out }