def decode_network_packet(buf):
    off = 0
    blen = len(buf)

    while off < blen:
        ptype, plen = header.unpack_from(buf, off)

        if plen > blen - off:
            raise ValueError("Packet longer than amount of data in buffer")

        if ptype not in _decoders:
            raise ValueError("Message type %i not recognized" % ptype)

        yield ptype, _decoders[ptype](ptype, plen, buf[off:])
        off += plen
Decodes a network packet in collectd format.
dataset/ETHPy150Open python-diamond/Diamond/src/collectors/jcollectd/collectd_network.py/decode_network_packet