pub trait Protocol: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn can_parse(&self, context: &ParseContext) -> Option<u32>;
fn parse<'a>(
&self,
data: &'a [u8],
context: &ParseContext,
) -> ParseResult<'a>;
fn schema_fields(&self) -> Vec<FieldDescriptor>;
// Provided methods
fn display_name(&self) -> &'static str { ... }
fn child_protocols(&self) -> &[&'static str] { ... }
fn payload_mode(&self) -> PayloadMode { ... }
fn dependencies(&self) -> &'static [&'static str] { ... }
fn parse_projected<'a>(
&self,
data: &'a [u8],
context: &ParseContext,
_fields: Option<&HashSet<String>>,
) -> ParseResult<'a> { ... }
fn cheap_fields(&self) -> &'static [&'static str] { ... }
fn expensive_fields(&self) -> &'static [&'static str] { ... }
}Expand description
Core trait all protocol parsers must implement.
Required Methods§
Sourcefn can_parse(&self, context: &ParseContext) -> Option<u32>
fn can_parse(&self, context: &ParseContext) -> Option<u32>
Check if this parser can handle the given context.
Returns a priority score (higher = more specific match).
Returns None if this parser cannot handle the context.
Sourcefn parse<'a>(&self, data: &'a [u8], context: &ParseContext) -> ParseResult<'a>
fn parse<'a>(&self, data: &'a [u8], context: &ParseContext) -> ParseResult<'a>
Parse bytes into structured fields.
Sourcefn schema_fields(&self) -> Vec<FieldDescriptor>
fn schema_fields(&self) -> Vec<FieldDescriptor>
Return the schema fields this protocol produces.
Provided Methods§
Sourcefn display_name(&self) -> &'static str
fn display_name(&self) -> &'static str
Human-readable display name.
Sourcefn child_protocols(&self) -> &[&'static str]
fn child_protocols(&self) -> &[&'static str]
Protocols that might follow this one.
Sourcefn payload_mode(&self) -> PayloadMode
fn payload_mode(&self) -> PayloadMode
How should remaining bytes be handled after parsing?
Chain: Continue parsing with child protocols (default)Stream: Route to StreamManager for TCP reassemblyNone: Stop parsing (terminal protocol)
Sourcefn dependencies(&self) -> &'static [&'static str]
fn dependencies(&self) -> &'static [&'static str]
Protocols that must be parsed before this one can be reached.
Used for protocol pruning optimization - when a query only needs certain protocols, we can skip parsing protocols not in the transitive dependency chain.
Returns a list of protocol names that could appear in the parse chain before this protocol (e.g., TCP depends on ipv4, ipv6).
Sourcefn parse_projected<'a>(
&self,
data: &'a [u8],
context: &ParseContext,
_fields: Option<&HashSet<String>>,
) -> ParseResult<'a>
fn parse_projected<'a>( &self, data: &'a [u8], context: &ParseContext, _fields: Option<&HashSet<String>>, ) -> ParseResult<'a>
Parse with field projection - only extract requested fields.
If fields is None, extract all fields (default behavior).
If fields is Some, only extract fields in the set.
Note: frame_number and timestamp are always available from
the packet metadata, not from parsing.
The default implementation ignores projection and calls parse().
Protocols can override this to skip expensive field extraction.
Sourcefn cheap_fields(&self) -> &'static [&'static str]
fn cheap_fields(&self) -> &'static [&'static str]
Returns fields that are “cheap” to extract (header fields parsed anyway).
These fields come from the basic header parse that must happen regardless of projection. Used to decide if projection is worthwhile.
Sourcefn expensive_fields(&self) -> &'static [&'static str]
fn expensive_fields(&self) -> &'static [&'static str]
Returns fields that are “expensive” to extract.
These fields require additional parsing beyond the basic header, such as variable-length options, compressed data, or string parsing.