SnmpKit.MIB.TableIndex (snmpkit v2.0.1)

Decodes the instance sub-identifiers of a conceptual row into the values of the table's INDEX objects (RFC 2578 section 7.7).

Each index object is described by %{name, base, size, implied}:

  • integer-like bases (:integer, :gauge32, :counter32, :timeticks) take one sub-identifier;

  • :ip_address takes four and yields a tuple;

  • :octet_string with a fixed size takes that many, otherwise a length sub-identifier followed by the octets (or the rest when implied);

  • :object_identifier likewise takes a length then the sub-identifiers (or the rest when implied).

    iex> SnmpKit.MIB.TableIndex.decode([10, 0, 0, 1, 7], [ ...> %{name: "ipAdEntAddr", base: :ip_address}, ...> %{name: "slot", base: :integer} ...> ]) {:ok, %{"ipAdEntAddr" => {10, 0, 0, 1}, "slot" => 7}}

Summary

Functions

Decodes sub_ids with specs; {:error, reason} when they do not fit.

Types

index_spec()

@type index_spec() :: %{
  :name => String.t(),
  :base => atom() | nil,
  optional(:size) => {non_neg_integer(), non_neg_integer()} | nil,
  optional(:implied) => boolean()
}

Functions

decode(sub_ids, specs)

@spec decode([non_neg_integer()], [index_spec()]) ::
  {:ok, %{required(String.t()) => term()}} | {:error, term()}

Decodes sub_ids with specs; {:error, reason} when they do not fit.