/**
  * @param string $method
  * @param mixed[] $args
  * @return mixed
  * @throws MessageException
  */
 function query($method, $args = array())
 {
     $this->assertConnected();
     $xml = Request::encode($method, $args);
     if (strlen($xml) > self::MAX_REQUEST_SIZE - 8) {
         if ($method != 'system.multicall' || count($args[0]) < 2) {
             throw new MessageException('Request too large', MessageException::REQUEST_TOO_LARGE);
         }
         $mid = count($args[0]) >> 1;
         $res1 = $this->query('system.multicall', array(array_slice($args[0], 0, $mid)));
         $res2 = $this->query('system.multicall', array(array_slice($args[0], $mid)));
         return array_merge($res1, $res2);
     }
     $this->writeMessage($xml);
     return $this->flush(true);
 }