def prepare(message, max_bytes=None):
    """
    Prepares a message for being sent through a socket. Unless otherwise
    specified, the maximum number of bytes that can be sent at once through
    a socket is 1024, and therefore the maximum length a message can be is
    1024-4 = 1020.

    Message architecture:
    [Length of message][Message]

    Examples:

    >>> prepare("Hello")
    b'5   Hello'

    >>> prepare("REQUEST_CLOSE")
    b'13  REQUEST_CLOSE'

    >>> prepare("Hi there", max_bytes=36)
    b'8   Hi there'

    >>> prepare("Very very very very very long message", max_bytes=36)
    Traceback (most recent call last):
    ...
    AssertionError: Message length exceeded 32
    """

    # Handle defaults
    if max_bytes is None:
        max_bytes = 1024

    message = str(message)
    msg_len = len(message)

    # assertions
    assert msg_len <= (max_bytes - 4), "Message length exceeded " + str(max_bytes - 4)
    
    return (str(msg_len).ljust(4) + message).encode()