ExCodecs.CodecRegistry (ex_codecs v0.1.0)

Copy Markdown View Source

Runtime codec registry for ExCodecs.

The registry maintains a mapping of codec names to their implementations and metadata. Codecs are registered at application startup and can be queried at runtime.

Registry Operations

iex> ExCodecs.available_codecs()
[:blosc2, :bzip2, :lz4, :snappy, :zstd]

iex> ExCodecs.supports?(:zstd)
true

iex> {:ok, info} = ExCodecs.codec_info(:zstd)
iex> info.name
:zstd

The registry is backed by an ETS table for fast lookups and is populated when the application starts.

Summary

Functions

Returns all registered codec names (including unavailable ones).

Returns a list of all available codec names.

Returns a specification to start this module under a supervisor.

Returns detailed information about a codec.

Returns all codecs in a given category.

Looks up a codec by name.

Registers a codec with the registry.

Registers a codec as unavailable (known but not loadable).

Starts the registry agent.

Checks if a codec is supported and available.

Functions

all_codecs()

@spec all_codecs() :: [atom()]

Returns all registered codec names (including unavailable ones).

available_codecs()

@spec available_codecs() :: [atom()]

Returns a list of all available codec names.

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

codec_info(name)

@spec codec_info(atom()) :: {:ok, ExCodecs.Codec.t()} | {:error, :unsupported_codec}

Returns detailed information about a codec.

codecs_by_category(category)

@spec codecs_by_category(atom()) :: [ExCodecs.Codec.t()]

Returns all codecs in a given category.

lookup(name)

@spec lookup(atom()) ::
  {:ok, {module(), atom(), ExCodecs.Codec.t()}} | {:error, :unsupported_codec}

Looks up a codec by name.

Returns

  • {:ok, {module, category, info}} - Codec found
  • {:error, :unsupported_codec} - Codec not found

register(name, module, category)

@spec register(atom(), module(), atom()) :: :ok | {:error, term()}

Registers a codec with the registry.

Arguments

  • name - The atom name of the codec (e.g., :zstd)
  • module - The module implementing ExCodecs.Codec
  • category - The codec category (e.g., :compression)

Returns

  • :ok - Codec registered successfully
  • {:error, reason} - Registration failed

register_unavailable(name, category)

@spec register_unavailable(atom(), atom()) :: :ok

Registers a codec as unavailable (known but not loadable).

start_link(opts \\ [])

@spec start_link(keyword()) :: Agent.on_start()

Starts the registry agent.

supports?(name)

@spec supports?(atom()) :: boolean()

Checks if a codec is supported and available.