/** * Decompresses the given content * * @param string $content * @return string * @throws Exception\RuntimeException on memory, output length or data warning */ public function decompress($content) { $compressed = snappy_uncompress($content); if ($compressed === false) { throw new Exception\RuntimeException('Error while decompressing.'); } return $compressed; }
public function _decodeData($data) { switch (substr($data, 0, 4)) { // asking the data which library it uses allows for transparent changes of libraries case ':sn:': return snappy_uncompress(substr($data, 4)); case ':lz:': return lzf_decompress(substr($data, 4)); case ':gz:': return gzuncompress(substr($data, 4)); } return $data; }
/** * Public for testing purposes only. * * @param string $data * @return string */ public function _decodeData($data) { $this->profilerStart(__METHOD__); switch (substr($data, 0, 4)) { // asking the data which library it uses allows for transparent changes of libraries case ':sn:': $data = snappy_uncompress(substr($data, 4)); break; case ':lz:': $data = lzf_decompress(substr($data, 4)); break; case ':l4:': $data = lz4_uncompress(substr($data, 4)); break; case ':gz:': $data = gzuncompress(substr($data, 4)); break; } $this->profilerStop(__METHOD__); return $data; }
/** * @param bool|string $data * @return string */ protected function _decodeData($data) { if (substr($data, 2, 3) == self::COMPRESS_PREFIX) { switch (substr($data, 0, 2)) { case 'sn': return snappy_uncompress(substr($data, 5)); case 'lz': return lzf_decompress(substr($data, 5)); case 'gz': case 'zc': return gzuncompress(substr($data, 5)); } } return $data; }
/** * @param array $data * @return array */ public function UnCompress($data) { if (!empty($this->_currentCompressFields)) { foreach ($this->_currentCompressFields as $field) { if (!empty($data[$field])) { $data[$field] = $data[$field]->bin; $data[$field] = snappy_uncompress($data[$field]); } } } return $data; }
/** * Decode data * * @param string $data * @return string */ protected function _decodeData($data) { switch (substr($data, 0, 4)) { // asking the data which library it uses allows for transparent changes of libraries case ':sn:': $data = snappy_uncompress(substr($data, 4)); break; case ':lz:': $data = lzf_decompress(substr($data, 4)); break; case ':l4:': $data = lz4_uncompress(substr($data, 4)); break; case ':gz:': $data = gzuncompress(substr($data, 4)); break; } return $data; }
/** * Decompress data * * @param string $data * @return string * @throws Exception */ protected function decompress($data) { switch ($this->compression) { case self::COMPRESSION_LZ4: $decompressedData = @lz4_uncompress($data); if (false === $decompressedData) { throw new Exception('Error decompressing with lz4_uncompress.'); } break; case self::COMPRESSION_SNAPPY: $decompressedData = @snappy_uncompress($data); if (false === $decompressedData) { throw new Exception('Error decompressing with snappy_uncompress.'); } break; case self::COMPRESSION_LZF: $decompressedData = @lzf_decompress($data); if (false === $decompressedData) { throw new Exception('Error decompressing with lzf_decompress.'); } break; case self::COMPRESSION_GZ: $decompressedData = @gzuncompress($data); if (false === $decompressedData) { throw new Exception('Error decompressing with gzuncompress.'); } break; case self::COMPRESSION_NONE: default: $decompressedData = $data; } return $decompressedData; }
/** * (non-PHPdoc) * @see Zend\Filter\Compress.CompressionAlgorithmInterface::decompress() */ public function decompress($value) { return \snappy_uncompress($value); }
} $stat['decode']['snappy/json'] = 1000 * (microtime(1) - $start); //$stat['mem_usage']['snappy/json'] = memory_get_usage() - $mem_start; $start = microtime(1); //$mem_start = memory_get_usage(); for ($i = 0; $i < $iterationsCount; ++$i) { //$tmp = $compress($serialize($data))); $tmp = snappy_compress(igbinary_serialize($data)); } $stat['encode']['snappy/igbinary'] = 1000 * (microtime(1) - $start); $tmp = snappy_compress(igbinary_serialize($data)); $stat['length']['snappy/igbinary'] = strlen($tmp); $start = microtime(1); for ($i = 0; $i < $iterationsCount; ++$i) { //$tmp2 = $unserialize($decompress($tmp)); $tmp2 = igbinary_unserialize(snappy_uncompress($tmp)); } $stat['decode']['snappy/igbinary'] = 1000 * (microtime(1) - $start); //$stat['mem_usage']['snappy/igbinary'] = memory_get_usage() - $mem_start; $start = microtime(1); //$mem_start = memory_get_usage(); for ($i = 0; $i < $iterationsCount; ++$i) { //$tmp = $compress($serialize($data))); $tmp = gzcompress(serialize($data), 9); } $stat['encode']['gzip-9/serialize'] = 1000 * (microtime(1) - $start); $tmp = gzcompress(serialize($data), 9); $stat['length']['gzip-9/serialize'] = strlen($tmp); $start = microtime(1); for ($i = 0; $i < $iterationsCount; ++$i) { //$tmp2 = $unserialize($decompress($tmp));
<?php $str = "Holy f**k. Are they actually going to get there?"; $ret = snappy_compress($str); $ret = snappy_compress($ret); $ret = snappy_compress($ret); $ret = snappy_uncompress($ret); $ret = snappy_uncompress($ret); $ret = snappy_uncompress($ret); var_dump($ret === $str); $str = str_repeat("x", 1000); $ret = snappy_compress($str); $ret = snappy_uncompress($ret); var_dump($ret === $str);
/** * Parse binary frame. * * @param unknown $frame * @return stdClass | array | */ public function parseBinaryFrame($frame) { $data = NULL; $frameBody = NULL; $traceId = NULL; // check frame flags $flagStatus = $this->_checkFrameFlags($frame->getFlag()); // do we need to decompress // @TODO need to add check to see which compression has been used, can't assume snappy // all the time... if ($flagStatus->compression) { $frameBody = snappy_uncompress($frame->getBody()); } else { $frameBody = $frame->getBody(); } // do we need to grab a tracing id if ($flagStatus->tracing) { $traceId = $this->parseUuid($frameBody); } switch ($frame->getOpcode()) { case \McFrazier\PhpBinaryCql\CqlConstants::FRAME_OPCODE_ERROR: $data = $this->parseError($frameBody); break; case \McFrazier\PhpBinaryCql\CqlConstants::FRAME_OPCODE_SUPPORTED: $data = $this->parseStringMultimap($frameBody); break; case \McFrazier\PhpBinaryCql\CqlConstants::FRAME_OPCODE_RESULT: $data = $this->parseResult($frameBody); break; case \McFrazier\PhpBinaryCql\CqlConstants::FRAME_OPCODE_AUTHENTICATE: $data = $this->parseString($frameBody); break; } // add the tracing id... if present if ($traceId) { $data->traceId = $traceId; } return $data; }