Class SnmpVariableParser
java.lang.Object
org.snmp4j.mcp.tool.snmp.SnmpVariableParser
Utility that converts a plain string value into the correct
Variable subclass
for a given SNMP OID.
Value syntax
The valueString parameter may carry an explicit type prefix separated by a
':' character:
string:hello → OctetString("hello")
hexstring:0102AABB → OctetString from hex bytes (colons/spaces stripped)
integer:42 → Integer32(42)
gauge32:4294967295 → Gauge32
counter32:100 → Counter32
counter64:1234567890 → Counter64
timeticks:100 → TimeTicks (hundredths of a second)
ipaddress:1.2.3.4 → IpAddress
oid:1.3.6.1 → OID
opaque:DEADBEEF → Opaque (hex bytes)
null: → Null
In addition to the short aliases above, the official SMIv2 type names recognised by
AbstractVariable.getSyntaxFromString(String) are also accepted (e.g.
"Integer32", "OctetString", "Counter64", …).
When no type prefix is present the SmiManager (if provided) is consulted to
resolve the OID's SMIv2 syntax and construct the correct Variable automatically.
If the SmiManager is null or the OID is not found, the value falls back to
OctetString.
-
Method Summary
-
Method Details
-
parse
public static org.snmp4j.smi.Variable parse(org.snmp4j.smi.OID oid, String valueString, com.snmp4j.smi.SmiManager smiManager) ParsesvalueStringinto the most appropriateVariablesubclass.- Parameters:
oid- the OID of the variable binding (used for SMIv2 type lookup only)valueString- value stringsmiManager- may benull; used only when no type prefix is present- Returns:
- the parsed
Variable, nevernull - Throws:
IllegalArgumentException- if the type prefix is unrecognised or the value cannot be converted to the requested type
-