def encode(operation, *args, **labels):
    """Encode a message so that it can be sent over the wire.

    Parameters:
      operation(str)
      \*args(tuple[str])
      \**labels(dict)

    Returns:
      bytes
    """
    if labels:
        args += (",".join(f'{name}="{labels[name]}"' for name in sorted(labels)),)

    message = operation
    for arg in args:
        message += b"\0"
        if arg:
            message += arg if isinstance(arg, bytes) else arg.encode("utf-8")

    message_len = str(len(message)).encode("ascii")
    return b"$" + message_len + b"\0" + message