def internal_gate_arg_to_proto(
    value: InternalGate, *, out: v2.program_pb2.InternalGate | None = None
):
    """Writes an InternalGate object into an InternalGate proto.

    Args:
        value: The gate to encode.
        out: The proto to write the result into. Defaults to a new instance.

    Returns:
        The proto that was written into.
    """
    msg = v2.program_pb2.InternalGate() if out is None else out
    msg.name = value.gate_name
    msg.module = value.gate_module
    msg.num_qubits = value.num_qubits()

    for k, v in value.gate_args.items():
        arg_to_proto(value=v, out=msg.gate_args[k])

    for ck, cv in value.custom_args.items():
        msg.custom_args[ck].MergeFrom(cv)

    return msg
Writes an InternalGate object into an InternalGate proto.

    Args:
        value: The gate to encode.
        out: The proto to write the result into. Defaults to a new instance.

    Returns:
        The proto that was written into.
    
cirq-google/cirq_google/serialization/arg_func_langs.py