/** * Decompress a message * * @param string $msg Message * @param integer $compression 0=none, 1=gzip, 2=snappy * * @return string * @throws \Kafka\Exception */ public static function decompress($msg, $compression) { switch ($compression) { case self::COMPRESSION_NONE: return $msg; case self::COMPRESSION_GZIP: // NB: this is really a MessageSet, not just a single message // although I'm not sure this is the best way to handle the inner offsets, // as the symmetry with the outer collection iteration is broken. // @see https://issues.apache.org/jira/browse/KAFKA-406 $stream = fopen('php://temp', 'w+b'); fwrite($stream, gzinflate(substr($msg, 10))); rewind($stream); $socket = Socket::createFromStream($stream); return new MessageSetInternalIterator($socket, 0, 0); case self::COMPRESSION_SNAPPY: throw new Exception\NotSupported('SNAPPY decompression not yet implemented'); default: throw new Exception\NotSupported('Unknown compression flag: ' . $compression); } }