import json
from collections.abc import Mapping


def encode_event(event: str, data: Mapping[str, object]) -> bytes:
    payload = json.dumps(data, ensure_ascii=False, separators=(",", ":"))
    return f"event: {event}\ndata: {payload}\n\n".encode()


def encode_ping() -> bytes:
    return b": ping\n\n"
