PcapFileEx.Flows.DecoderMatcher (pcap_file_ex v0.5.5)
View SourceMatcher and invoker for custom flow decoders.
Evaluates decoder specifications against match context and invokes matching decoders in order. Handles :skip fall-through and terminal errors.
Summary
Types
Result of decoder evaluation.
Functions
Find and invoke matching decoders for the given context and payload.
Invoke a decoder with the given context and payload.
Check if a matcher matches the given context.
Process the result from find_and_invoke into the final stored value.
Types
Result of decoder evaluation.
{:ok, term}- Decoder succeeded, to be wrapped as{:custom, term}{:error, term}- Decoder failed (terminal), to be stored as{:decode_error, term}:skip- No decoder matched or all returned :skip
Functions
@spec find_and_invoke( [PcapFileEx.Flows.Decoder.decoder_spec()], PcapFileEx.Flows.Decoder.match_context(), binary() ) :: eval_result()
Find and invoke matching decoders for the given context and payload.
Evaluates decoders in order. If a decoder returns :skip, continues to
the next matching decoder. If a decoder returns {:error, reason}, stops
immediately (terminal). Returns :skip if no decoder matches or all skip.
Parameters
decoders- List of decoder specificationsctx- Match context with protocol, direction, and other metadatapayload- Binary payload to decode
Returns
{:ok, decoded}- A decoder succeeded{:error, reason}- A decoder failed (terminal):skip- No decoder matched or all returned :skip
@spec invoke_decoder( PcapFileEx.Flows.Decoder.decoder_fn() | module(), PcapFileEx.Flows.Decoder.match_context(), binary() ) :: PcapFileEx.Flows.Decoder.decode_result()
Invoke a decoder with the given context and payload.
Handles:
- Arity-1 functions:
decoder.(payload), wraps result - Arity-2 functions:
decoder.(ctx, payload), expects decode_result() - Modules:
module.decode(ctx, payload), expects decode_result()
Exceptions are caught and returned as {:error, %{exception: e, stacktrace: st}}.
@spec matches?( PcapFileEx.Flows.Decoder.matcher(), PcapFileEx.Flows.Decoder.match_context() ) :: boolean()
Check if a matcher matches the given context.
Map Matchers
All specified criteria must match:
:scope- Exact match:port- Integer, Range, or list of integers:content_type- String (exact), Regex, or list of strings:content_id- String (exact) or Regex:method- String or list of strings:path- String (exact) or Regex
Function Matchers
Function receives the full context and returns boolean. Exceptions are caught and treated as no match.
@spec process_result(eval_result()) :: {:custom, term()} | {:decode_error, term()} | :binary_fallback
Process the result from find_and_invoke into the final stored value.
Returns
{:custom, term}- Decoder succeeded{:decode_error, reason}- Decoder failed:binary_fallback- No decoder matched (caller should use{:binary, payload}ornil)