SnmpKit.SnmpLib.MIB.Utilities (snmpkit v0.6.6)

Direct port of Erlang snmpc_lib.erl utility functions to Elixir.

This is a 1:1 port of the utility functions from the official Erlang SNMP compiler from OTP lib/snmp/src/compile/snmpc_lib.erl

Original copyright: Ericsson AB 1996-2025 (Apache License 2.0)

Summary

Functions

Check if size constraint is allowed for given type (RFC 1902 compliance). Port of allow_size_rfc1902/1 from snmpc_lib.erl

Validate sub-identifier ranges. Port of check_sub_ids/3 from snmpc_lib.erl

Terminate compilation with error. Port of error/2 and error/3 from snmpc_lib.erl

Safe key lookup in list of tuples/maps. Port of key1search/2 and key1search/3 from snmpc_lib.erl

Generic lookup function with multiple criteria. Port of lookup/2 from snmpc_lib.erl

Validate and transform ASN.1 type definition. Port of make_ASN1type/1 from snmpc_lib.erl

Print error message with formatting. Port of print_error/2 and print_error/3 from snmpc_lib.erl

Determine if message should be printed based on verbosity. Port of printable/2 from snmpc_lib.erl

Register an OID entry in the OID table. Port of register_oid/4 from snmpc_lib.erl

Resolve symbolic OID references to numeric OIDs. Port of resolve_oids/1 from snmpc_lib.erl

Set directory path helper. Port of set_dir/2 from snmpc_lib.erl

Validate bit definitions for BITS syntax. Port of test_kibbles/2 from snmpc_lib.erl

Translate symbolic name to numeric OID. Port of tr_oid/2 from snmpc_lib.erl

Update MIB entries with resolved OIDs. Port of update_me_oids/3 from snmpc_lib.erl

Configurable verbose printing. Port of vprint/6 from snmpc_lib.erl

Validate verbosity level. Port of vvalidate/1 from snmpc_lib.erl

Types

oid()

@type oid() :: [integer()]

oid_status()

@type oid_status() :: :resolved | :unresolved

verbosity()

@type verbosity() :: :silent | :warning | :info | :debug

Functions

allow_size_rfc1902(type)

@spec allow_size_rfc1902(atom()) :: boolean()

Check if size constraint is allowed for given type (RFC 1902 compliance). Port of allow_size_rfc1902/1 from snmpc_lib.erl

check_sub_ids(oid, min_value, max_value)

@spec check_sub_ids(oid(), integer(), integer()) :: :ok | {:error, binary()}

Validate sub-identifier ranges. Port of check_sub_ids/3 from snmpc_lib.erl

compilation_error(message)

@spec compilation_error(binary()) :: no_return()

Terminate compilation with error. Port of error/2 and error/3 from snmpc_lib.erl

compilation_error(format, args)

@spec compilation_error(binary(), term()) :: no_return()

key1search(key, list)

@spec key1search(term(), [tuple()]) :: {:value, term()} | false

Safe key lookup in list of tuples/maps. Port of key1search/2 and key1search/3 from snmpc_lib.erl

key1search(key, list, default)

@spec key1search(term(), [tuple()], term()) :: term()

lookup(key, list)

@spec lookup(term(), [term()]) :: {:ok, term()} | {:error, :not_found}

Generic lookup function with multiple criteria. Port of lookup/2 from snmpc_lib.erl

make_asn1_type(type_def)

@spec make_asn1_type(term()) :: {:ok, map()} | {:error, binary()}

Validate and transform ASN.1 type definition. Port of make_ASN1type/1 from snmpc_lib.erl

printable?(current_verbosity, required_verbosity)

@spec printable?(verbosity(), verbosity()) :: boolean()

Determine if message should be printed based on verbosity. Port of printable/2 from snmpc_lib.erl

register_oid(name, oid, status, oid_table)

@spec register_oid(binary(), oid(), atom(), map()) :: map()

Register an OID entry in the OID table. Port of register_oid/4 from snmpc_lib.erl

resolve_oids(oid_table)

@spec resolve_oids(map()) :: {:ok, map()} | {:error, [binary()]}

Resolve symbolic OID references to numeric OIDs. Port of resolve_oids/1 from snmpc_lib.erl

set_dir(filename, directory)

@spec set_dir(binary(), binary()) :: binary()

Set directory path helper. Port of set_dir/2 from snmpc_lib.erl

test_kibbles(bit_definitions, verbosity)

@spec test_kibbles([map()], verbosity()) :: :ok | {:error, binary()}

Validate bit definitions for BITS syntax. Port of test_kibbles/2 from snmpc_lib.erl

tr_oid(name, oid_table)

@spec tr_oid(binary(), map()) :: {:ok, oid()} | {:error, :not_found}

Translate symbolic name to numeric OID. Port of tr_oid/2 from snmpc_lib.erl

update_me_oids(mib_entries, oid_table, verbosity)

@spec update_me_oids([map()], map(), verbosity()) :: [map()]

Update MIB entries with resolved OIDs. Port of update_me_oids/3 from snmpc_lib.erl

vprint(current_verbosity, required_verbosity, module, function, format, args)

@spec vprint(verbosity(), verbosity(), binary(), binary(), binary(), [term()]) :: :ok

Configurable verbose printing. Port of vprint/6 from snmpc_lib.erl

vvalidate(verbosity)

@spec vvalidate(term()) :: {:ok, verbosity()} | {:error, binary()}

Validate verbosity level. Port of vvalidate/1 from snmpc_lib.erl