(ptype, plen, buf)
return result
Decodes a list of DS values in collectd network format
Decodes a list of DS values in collectd network format
Decodes a list of DS values in collectd network format
def decode_network_values(ptype, plen, buf):
    """Decodes a list of DS values in collectd network format
    """
    nvalues = short.unpack_from(buf, header.size)[0]
    off = header.size + short.size + nvalues
    valskip = double.size

    # Check whether our expected packet size is the reported one
    assert ((valskip + 1) * nvalues + short.size + header.size) == plen
    assert double.size == number.size

    result = []
    for dstype in [ord(x) for x in buf[header.size + short.size:off]]:
        if dstype == DS_TYPE_COUNTER:
            result.append((dstype, number.unpack_from(buf, off)[0]))
            off += valskip
        elif dstype == DS_TYPE_GAUGE:
            result.append((dstype, double.unpack_from(buf, off)[0]))
            off += valskip
        elif dstype == DS_TYPE_DERIVE:
            result.append((dstype, number.unpack_from(buf, off)[0]))
            off += valskip
        elif dstype == DS_TYPE_ABSOLUTE:
            result.append((dstype, number.unpack_from(buf, off)[0]))
            off += valskip
        else:
            raise ValueError("DS type %i unsupported" % dstype)

    return result
def decode_network_values ( ptype , plen , buf ) : nvalues = short . unpack_from ( buf , header . size ) [ 0 ] off = header . size + short . size + nvalues valskip = double . size # Check whether our expected packet size is the reported one assert ( ( valskip + 1 ) * nvalues + short . size + header . size ) == plen assert double . size == number . size result = [ ] for dstype in [ ord ( x ) for x in buf [ header . size + short . size : off ] ] : if dstype == DS_TYPE_COUNTER : result . append ( ( dstype , number . unpack_from ( buf , off ) [ 0 ] ) ) off += valskip elif dstype == DS_TYPE_GAUGE : result . append ( ( dstype , double . unpack_from ( buf , off ) [ 0 ] ) ) off += valskip elif dstype == DS_TYPE_DERIVE : result . append ( ( dstype , number . unpack_from ( buf , off ) [ 0 ] ) ) off += valskip elif dstype == DS_TYPE_ABSOLUTE : result . append ( ( dstype , number . unpack_from ( buf , off ) [ 0 ] ) ) off += valskip else : raise ValueError ( "DS type %i unsupported" % dstype ) return result