def _graph_encode(graph, coding=None):
    """Encode graph parameters."""
    from flib.base import binary
    if not isinstance(coding, str) or coding.lower() == 'none':
        return graph._graph.copy()
    if coding.lower() == 'base64':
        graph.graph['params'] = binary.pack(graph.graph['params'], encoding
            ='base64')
        for node in graph.nodes():
            graph.node[node]['params'] = binary.pack(graph.node[node][
                'params'], encoding='base64')
        for edge in graph.edges():
            graph.edges[edge]['params'] = binary.pack(graph.edges[edge][
                'params'], encoding='base64')
        graph.graph['coding'] = 'base64'
        return graph
    raise ValueError(
        """could not encode graph parameters:
        unsupported coding '%s'."""
         % coding)
