Skip to main content

peek_long_header_dcid

Function peek_long_header_dcid 

Source
pub fn peek_long_header_dcid(packet: &[u8]) -> Option<&[u8]>
Expand description

Extract the Destination Connection ID from a QUIC Long Header packet without performing a full parse.

Returns None when the buffer is too short or the CID length field is zero or exceeds 20.

Examples found in repository?
examples/parse_header.rs (line 29)
9fn main() {
10	// A minimal QUIC v1 Initial packet (truncated payload).
11	// In practice this would come from a UDP socket.
12	let packet: Vec<u8> = build_sample_initial();
13
14	match quic_parser::parse_initial(&packet) {
15		Ok(header) => {
16			println!("QUIC Initial packet parsed successfully");
17			println!("  version:      {:#010x}", header.version);
18			println!("  dcid:         {}", hex(header.dcid));
19			println!("  scid:         {}", hex(header.scid));
20			println!("  token length: {}", header.token.len());
21			println!("  payload size: {} bytes", header.payload.len());
22		}
23		Err(e) => {
24			eprintln!("parse error: {e}");
25		}
26	}
27
28	// Peek at the DCID without a full parse.
29	if let Some(dcid) = quic_parser::peek_long_header_dcid(&packet) {
30		println!("  peeked dcid:  {}", hex(dcid));
31	}
32}