PcapFileEx.DecoderRegistry (pcap_file_ex v0.1.5)

View Source

Registry of application-layer payload decoders.

Each decoder entry supplies:

  • :protocol — atom identifying the protocol (e.g., :http)
  • :matcherfn layers, payload -> boolean end returning true when the decoder applies
  • :decoderfn payload -> {:ok, term} | {:error, term} returning structured data

Matchers receive the list of protocol layers returned by :pkt.decode/2 and the raw payload binary from the previous layer. Decoders should return {:ok, value} on success; any other return is wrapped in {:ok, value} automatically.

Summary

Functions

Lists the registered decoder entries in registration order.

Registers a new decoder entry.

Unregisters a decoder by protocol atom. No-op if not present.

Types

entry()

@type entry() :: %{
  protocol: atom(),
  matcher: (list(), binary() -> boolean()),
  decoder: (binary() -> {:ok, term()} | {:error, term()} | term()),
  fields: [field_descriptor()]
}

field_descriptor()

@type field_descriptor() :: %{
  id: String.t(),
  type: :string | :integer | :list_integer,
  extractor: (term() -> term())
}

Functions

list()

@spec list() :: [entry()]

Lists the registered decoder entries in registration order.

register(entry)

@spec register(entry()) :: :ok

Registers a new decoder entry.

If a decoder for entry.protocol already exists it is replaced.

unregister(protocol)

@spec unregister(atom()) :: :ok

Unregisters a decoder by protocol atom. No-op if not present.