def _parse_tlv(buff):
    lldp_info = []
    while buff:
        # TLV structure: type (7 bits), length (9 bits), val (0-511 bytes)
        tlvhdr = struct.unpack('!H', buff[:2])[0]
        tlvtype = (tlvhdr & 0xfe00) >> 9
        tlvlen = (tlvhdr & 0x01ff)
        tlvdata = buff[2:tlvlen + 2]
        buff = buff[tlvlen + 2:]
        lldp_info.append((tlvtype, tlvdata))
    return lldp_info
Iterate over a buffer and generate structured TLV data.
dataset/ETHPy150Open openstack/ironic-python-agent/ironic_python_agent/netutils.py/_parse_tlv