Unsupported content

 

This version of the product is no longer supported. However, the documentation is available for your convenience. You will not be able to leave comments.

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. 

CharacterByte order
<little-endian
>big-endian
!network (= big-endian)

The remaining characters represent the Python types and sizes.

FormatPython typeStandard size
xno value 
cstring of length 11
B or binteger1
?bool1
H or hinteger2
I or iinteger4
L or linteger4
Q or qinteger8
ffloat4
dfloat8
sstring 
pstring 
Pinteger 

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.
The information in the tables above is taken from the Python documentation.

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");
Was this page helpful? Yes No Submitting... Thank you

Comments