SnmpKit.SnmpMgr.Types (snmpkit v0.6.6)

SNMP data type handling and conversion.

Handles encoding and decoding of SNMP values, including automatic type inference and explicit type specification.

Summary

Functions

Decodes an SNMP value to an Elixir term.

Encodes a value for SNMP with optional type specification.

Automatically infers the SNMP type from an Elixir value.

Functions

decode_value(value)

Decodes an SNMP value to an Elixir term.

Examples

iex> SnmpKit.SnmpMgr.Types.decode_value({:string, "Hello"})
"Hello"

iex> SnmpKit.SnmpMgr.Types.decode_value({:integer, 42})
42

encode_value(value, opts \\ [])

Encodes a value for SNMP with optional type specification.

Parameters

  • value - The value to encode
  • opts - Options including :type for explicit type specification

Examples

iex> SnmpKit.SnmpMgr.Types.encode_value("Hello World")
{:ok, {:string, "Hello World"}}

iex> SnmpKit.SnmpMgr.Types.encode_value(42)
{:ok, {:integer, 42}}

iex> SnmpKit.SnmpMgr.Types.encode_value("192.168.1.1", type: :ipAddress)
{:ok, {:ipAddress, {192, 168, 1, 1}}}

infer_type(value)

Automatically infers the SNMP type from an Elixir value.

Examples

iex> SnmpKit.SnmpMgr.Types.infer_type("hello")
:string

iex> SnmpKit.SnmpMgr.Types.infer_type(42)
:integer

iex> SnmpKit.SnmpMgr.Types.infer_type("192.168.1.1")
:string  # Would need explicit :ipAddress type