<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def encode_data(data: Data) -> bytes: """ Convert a string or byte-like object to bytes. This function is designed for ping and pon g frames. If ``data`` is a :class:`str`, return a :class:`bytes` object encoding ``data`` in UTF-8. If ``data`` is a bytes-like object, return a :class:`bytes` object. Raise :exc:`TypeError` for other inputs. """

    if isinstance(data, str):
        return data.encode("utf-8")
    elif isinstance(data, (bytes, bytearray)):
        return bytes(data)
    elif isinstance(data, memoryview):
        return data.tobytes()
    else:
        raise TypeError("data must be bytes-like or str")