docs: def _encode(msg, head=False, binary=False):
      """Convert a Message to a raw string.
      """
      rawstr = str(_MAGICK) + u"{0:s} {1:s} {2:s} {3:s} {4:s}".format(
          msg.subject, msg.type, msg.sender, msg.time.isoformat(), msg.version)
  
      if not head and msg.data:
          if not binary and isinstance(msg.data, six.string_types):
              return (rawstr + ' ' +
                      'text/ascii' + ' ' + msg.data)
          elif not binary:
              return (rawstr + ' ' +
                      'application/json' + ' ' +
                      json.dumps(msg.data, default=datetime_encoder))
          else:
              return (rawstr + ' ' +
                      'binary/octet-stream' + ' ' + msg.data)
      return rawstr