Exemplo n.º 1
0
 /**
  * Read the next message 
  *
  * @return string Message (raw)
  * @throws Kafka_Exception when the message cannot be read from the stream buffer
  */
 protected function getMessage()
 {
     try {
         $size = $this->getMessageSize();
         $msg = $this->socket->read($size, true);
     } catch (Kafka_Exception_Socket_EOF $e) {
         $size = isset($size) ? $size : 'enough';
         $logMsg = 'Cannot read ' . $size . ' bytes, the message is likely bigger than the buffer';
         throw new Kafka_Exception_OutOfRange($logMsg);
     }
     $this->validByteCount += 4 + $size;
     return $msg;
 }
Exemplo n.º 2
0
 /**
  * Read the response error code
  *
  * @return integer Error code
  */
 protected function getResponseCode()
 {
     $this->connect();
     $data = $this->socket->read(2, true);
     $unpack = unpack('n', $data);
     return array_shift($unpack);
 }
Exemplo n.º 3
0
 /**
  * Parse the response and return the array of offsets
  *
  * @param Kafka_Socket $socket Socket handle
  *
  * @return array
  */
 public static function deserializeOffsetArray(Kafka_Socket $socket)
 {
     $nOffsets = array_shift(unpack('N', $socket->read(4)));
     if ($nOffsets < 0) {
         throw new Kafka_Exception_OutOfRange($nOffsets . ' is not a valid number of offsets');
     }
     $offsets = array();
     for ($i = 0; $i < $nOffsets; ++$i) {
         $offsets[] = self::unpackLong64bigendian($socket->read(8));
     }
     return $offsets;
 }
Exemplo n.º 4
0
 /**
  * Read the response error code
  *
  * @return integer Error code
  */
 protected function getResponseCode()
 {
     $this->connect();
     return array_shift(unpack('n', $this->socket->read(2, true)));
 }