(function)
return obj
:return :
:return :
: return :
def serialize(function):
        """
        :return :
        """
        # delayed import
        from .function import Function  # pylint:disable=import-outside-toplevel

        obj = Function._get_cmsg()
        obj.ea = function.addr
        obj.is_entrypoint = False  # TODO: Set this up accordingly
        obj.name = function.name
        obj.is_plt = function.is_plt
        obj.is_syscall = function.is_syscall
        obj.is_simprocedure = function.is_simprocedure
        obj.returning = function.returning
        obj.alignment = function.alignment
        obj.binary_name = function.binary_name
        obj.normalized = function.normalized

        # signature matched?
        if not function.from_signature:
            obj.matched_from = function_pb2.Function.UNMATCHED
        else:
            if function.from_signature == "flirt":
                obj.matched_from = function_pb2.Function.FLIRT
            else:
                raise ValueError(f"Cannot convert from_signature {function.from_signature} into a SignatureSource "
                                 f"enum.")

        # blocks
        blocks_list = [ b.serialize_to_cmessage() for b in function.blocks ]
        obj.blocks.extend(blocks_list)  # pylint:disable=no-member

        block_addrs_set = function.block_addrs_set
        # graph
        edges = []
        external_addrs = set()
        TRANSITION_JK = func_edge_type_to_pb('transition')  # default edge type
        for src, dst, data in function.transition_graph.edges(data=True):
            edge = primitives_pb2.Edge()
            edge.src_ea = src.addr
            edge.dst_ea = dst.addr
            if src.addr not in block_addrs_set:
                # this is a Block in another function, or just another Function instance.
                external_addrs.add(src.addr)
            if dst.addr not in block_addrs_set:
                external_addrs.add(dst.addr)
            edge.jumpkind = TRANSITION_JK
            for key, value in data.items():
                if key == "type":
                    edge.jumpkind = func_edge_type_to_pb(value)
                elif key == "ins_addr":
                    if value is not None:
                        edge.ins_addr = value
                elif key == "stmt_idx":
                    if value is not None:
                        edge.stmt_idx = value
                elif key == "outside":
                    edge.is_outside = value
                else:
                    edge.data[key] = pickle.dumps(value)  # pylint:disable=no-member
            edges.append(edge)
        obj.graph.edges.extend(edges)  # pylint:disable=no-member
        # referenced functions
        obj.external_functions.extend(external_addrs)  # pylint:disable=no-member

        return obj
def serialize ( function ) : # delayed import from . function import Function # pylint:disable=import-outside-toplevel obj = Function . _get_cmsg ( ) obj . ea = function . addr obj . is_entrypoint = False # TODO: Set this up accordingly obj . name = function . name obj . is_plt = function . is_plt obj . is_syscall = function . is_syscall obj . is_simprocedure = function . is_simprocedure obj . returning = function . returning obj . alignment = function . alignment obj . binary_name = function . binary_name obj . normalized = function . normalized # signature matched? if not function . from_signature : obj . matched_from = function_pb2 . Function . UNMATCHED else : if function . from_signature == "flirt" : obj . matched_from = function_pb2 . Function . FLIRT else : raise ValueError ( f"Cannot convert from_signature {function.from_signature} into a SignatureSource " f"enum." ) # blocks blocks_list = [ b . serialize_to_cmessage ( ) for b in function . blocks ] obj . blocks . extend ( blocks_list ) # pylint:disable=no-member block_addrs_set = function . block_addrs_set # graph edges = [ ] external_addrs = set ( ) TRANSITION_JK = func_edge_type_to_pb ( 'transition' ) # default edge type for src , dst , data in function . transition_graph . edges ( data = True ) : edge = primitives_pb2 . Edge ( ) edge . src_ea = src . addr edge . dst_ea = dst . addr if src . addr not in block_addrs_set : # this is a Block in another function, or just another Function instance. external_addrs . add ( src . addr ) if dst . addr not in block_addrs_set : external_addrs . add ( dst . addr ) edge . jumpkind = TRANSITION_JK for key , value in data . items ( ) : if key == "type" : edge . jumpkind = func_edge_type_to_pb ( value ) elif key == "ins_addr" : if value is not None : edge . ins_addr = value elif key == "stmt_idx" : if value is not None : edge . stmt_idx = value elif key == "outside" : edge . is_outside = value else : edge . data [ key ] = pickle . dumps ( value ) # pylint:disable=no-member edges . append ( edge ) obj . graph . edges . extend ( edges ) # pylint:disable=no-member # referenced functions obj . external_functions . extend ( external_addrs ) # pylint:disable=no-member return obj