How to use the netflow.ipfix.IPFIXDataTypes.is_float function in netflow

To help you get started, we’ve selected a few netflow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitkeks / python-netflow-v9-softflowd / netflow / ipfix.py View on Github external
if not field_type and type(field) is not TemplateFieldEnterprise:
                # This should break, since the exporter seems to use a field identifier
                # which is not standardized by IANA.
                raise NotImplementedError("Field type with ID {} is not implemented".format(field_type_id))

            datatype = field_type.type  # type: str
            discovered_fields.append((field_type.name, field_type_id))

            # Catch fields which are meant to be raw bytes and skip the rest
            if IPFIXDataTypes.is_bytes(datatype):
                unpacker += "{}s".format(field_length)
                continue

            # Go into int, uint, float types
            issigned = IPFIXDataTypes.is_signed(datatype)
            isfloat = IPFIXDataTypes.is_float(datatype)
            assert not (all([issigned, isfloat]))  # signed int and float are exclusive

            if field_length == 1:
                unpacker += "b" if issigned else "B"
            elif field_length == 2:
                unpacker += "h" if issigned else "H"
            elif field_length == 4:
                unpacker += "i" if issigned else "f" if isfloat else "I"
            elif field_length == 8:
                unpacker += "q" if issigned else "d" if isfloat else "Q"
            else:
                raise IPFIXTemplateError("Template field_length {} not handled in unpacker".format(field_length))

        # Finally, unpack the data byte stream according to format defined in iteration above
        pack = struct.unpack(unpacker, data[0:offset])