binary.toValue
binary.toValue(data, format)
Converts the given binary value into the specified format.The binary value is typically a value retrieved via SNMP using the binary settings on discovery.snmpGet or discovery.snmpGetTable.
If the function fails, for example, if the value is invalid, or an unknown format is specified, it returns none.
Format specification
The format specification is a string of two or more characters. The first character specifies the byte order of the data.
Character | Byte order |
---|---|
< | little-endian |
> | big-endian |
! | network (= big-endian) |
The remaining characters represent the Python types and sizes.
Format | Python type | Standard size |
---|---|---|
x | no value | |
c | string of length 1 | 1 |
B or b | integer | 1 |
? | bool | 1 |
H or h | integer | 2 |
I or i | integer | 4 |
L or l | integer | 4 |
Q or q | integer | 8 |
f | float | 4 |
d | float | 8 |
s | string | |
p | string | |
P | integer |
For example:
"!HI"
means convert 6 bytes in network byte order into a 16 bit integer value and a 32 bit integer value."!4H"
or"!HHHH"
means convert 8 bytes in network byte order into four 16 bit integer values.
Example
The FCMGMT-MIB::connUnitPortTable
contains a value called connUnitPortFCClassCap
which is defined as a 2 octet string (2 bytes). Each bit in this string of bytes indicates the FC class capabilities of the port. To decode this in TPL, you convert the 2 bytes into a number and then use the TPL bit mask operators.
In the following example, the format specifier !H
means convert 2 bytes in network byte order into a 16 bit integer value:
value := binary.toValue(connUnitPortFCClassCap, "!H");
Comments
Log in or register to comment.