forge
ExploreLog in

Tahinli/forge

public
0 watching
★ 0
824 bytes
1//! pkt-line framing for smart HTTP.
2
3use crate::service::GitService;
4
5/// The flush packet `0000`.
6pub const FLUSH_PKT: &[u8] = b"0000";
7
8/// Frames `data` as a pkt-line (4 hex length digits, including the 4 length bytes).
9/// The payload must be at most 65516 bytes; callers pass short protocol strings.
10pub fn pkt_line(data: &str) -> Vec<u8> {
11 let len = data.len() + 4;
12 debug_assert!(len <= 0xffff, "pkt-line payload too long");
13 let mut out = format!("{len:04x}").into_bytes();
14 out.extend_from_slice(data.as_bytes());
15 out
16}
17
18/// The smart-HTTP advertisement preamble: `# service=git-<svc>` as a pkt-line, then a flush.
19pub fn service_advertisement_header(svc: GitService) -> Vec<u8> {
20 let mut out = pkt_line(&format!("# service={}\n", svc.name()));
21 out.extend_from_slice(FLUSH_PKT);
22 out
23}