code: def encode(char_data, encoding='utf-8'):
      
      if type(char_data) is str:
          return char_data.encode(encoding, errors='replace')
      elif type(char_data) is bytes:
          return char_data
      else:
          raise TypeError('message should be a string or bytes, found %s' % type(char_data))
docs: Encode the parameter as a byte string.
  
      :param char_data: the data to encode
  
      :rtype: bytes