code: def __point_data_to_bytes(self, data, mime=None):  # pylint: disable=too-many-branches
          
          if mime is None:
              if self.__auto_encode_decode:
                  if isinstance(data, bytes):
                      return None, data
                  elif isinstance(data, dict):
                      # check top level dictionary keys
                      if all(isinstance(key, unicode_type) for key in data):
                          return 'idx/1', ubjdumpb(data)  # application/ubjson
                      else:
                          raise ValueError('At least one key in dict not real (unicode) string')
                  elif isinstance(data, unicode_type):
                      return 'idx/2', data.encode('utf8')  # text/plain; charset=utf8
                  else:
                      raise ValueError('cannot auto-encode data of type %s' % type(data))
              elif isinstance(data, bytes):
                  return None, data
              else:
                  raise ValueError('No mime type specified and not bytes object (auto-encode disabled)')
          elif valid_mimetype(mime):
              if isinstance(data, bytes):
                  return mime, data
              else:
                  raise ValueError('mime specified but data not bytes object')
          else:
              raise ValueError('invalid mime type %s' % mime)
docs: Returns tuple of mime type & data. Auto encodes unicode strings (to utf8) and
             dictionaries (to ubjson) depending on client setting.