code: def encode_data(data: Data) -> bytes:
      
      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")
docs: 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.