def fmt_msg(event, payload=None, serial=None):
    """
    Packs a message to be sent to the server.
    Serial is a function to call on the frame to serialize it, e.g:
    json.dumps.
    """
    frame = {
        'e': event,
        'p': payload,
    }
    return serial(frame) if serial else frame