Python google.protobuf.descriptor.FieldDescriptor.TYPE_INT32() Examples

The following are code examples for showing how to use google.protobuf.descriptor.FieldDescriptor.TYPE_INT32(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: felix   Author: axbaretto   File:    Apache License 2.0 5 votes vote down vote up
def convert_pb_rules(pb_rules):
    dict_rules = []
    for pb_rule in pb_rules:
        _log.debug("Converting protobuf rule: %r type: %s",
                   pb_rule, pb_rule.__class__)
        d_rule = {}
        for fd, value in pb_rule.ListFields():
            if value is None:
            if fd.type == FieldDescriptor.TYPE_STRING and value == "":
            if fd.type in (FieldDescriptor.TYPE_INT32,
                           FieldDescriptor.TYPE_INT64) and value == 0:
            _log.debug("Field %s = %s",, value)
            negated ="not_")
            stem = if not negated else[4:]
            dict_name = "!" + stem if negated else stem

            if stem.endswith("_ports"):
                value = convert_pb_ports(value)
            elif stem.endswith("protocol"):
                value = convert_pb_protocol(value)
            elif stem.endswith("ip_set_ids"):
                value = list(value)

            if stem == "icmp_type_code":
                # Special case: ICMP is represented by an object, unpack it.
                d_rule[("!" if negated else "") + "icmp_type"] = value.type
                d_rule[("!" if negated else "") + "icmp_code"] = value.code
                d_rule[dict_name] = value

    return dict_rules