parse_packet_pruned

Function parse_packet_pruned 

Source
pub fn parse_packet_pruned<'a>(
    registry: &ProtocolRegistry,
    link_type: u16,
    data: &'a [u8],
    required: &HashSet<String>,
) -> Vec<(&'static str, ParseResult<'a>)>
Expand description

Parse a packet with protocol pruning.

Only parses protocols in the required set and their dependencies. This can significantly reduce CPU usage for selective queries.

§Arguments

  • registry - Protocol registry containing parser definitions
  • link_type - Link layer type (e.g., 1 for Ethernet)
  • data - Raw packet bytes
  • required - Set of protocol names needed for the query

§Returns

Vector of (protocol_name, parse_result) pairs for protocols in the required set. Protocols parsed but not in the required set (i.e., intermediate layers) are still included as they may be needed for correct result interpretation.

§Example

use std::collections::HashSet;
use pcapsql_core::protocol::{default_registry, parse_packet_pruned};

let registry = default_registry();
let required: HashSet<String> = ["tcp"].iter().map(|s| s.to_string()).collect();

let results = parse_packet_pruned(&registry, 1, &packet_data, &required);
// Will parse Ethernet, IPv4/IPv6, TCP but skip DNS, HTTP, TLS, etc.