Snappy fix receiving partial message

This commit is contained in:
2021-02-01 01:17:39 +03:00
parent 3d8f5be2d0
commit 801fdfe547

View File

@@ -84,44 +84,50 @@ final class SnappySocket implements Socket
$size = $chunkType >> 8;
$chunkType &= 0xff;
$this->logger->debug('Snappy receive chunk [{chunk}] with size [{size}]', [
$this->logger->debug('Snappy receive chunk [{chunk}], size [{size}]', [
'chunk' => $chunkType,
'size' => $size,
]);
do {
$input->append(
$this->socket->read($size),
);
$size -= $input->size();
} while ($input->size() < $size);
switch ($chunkType) {
case 0xff:
$this->logger->debug('Snappy identifier chunk');
$this->socket->read(6); // discard identifier body
$input->discard(6); // discard identifier body
break;
case 0x00: // 'compressed',
$this->logger->debug('Snappy compressed chunk');
$input->append(
$this->socket->read($size),
)
$data = $input
->discard(4) // discard checksum
->flush()
;
$output->append(
snappy_uncompress(
$input->flush(),
),
);
$this->logger->debug('Snappy compressed data [{data}]', ['data' => $data]);
$output->append(snappy_uncompress($data));
break;
case 0x01: // 'uncompressed',
$this->logger->debug('Snappy uncompressed chunk');
$input->append(
$this->socket->read($size),
)
$data = $input
->discard(4) // discard checksum
->flush()
;
$output->append($input->flush());
$this->logger->debug('Snappy uncompressed data [{data}]', ['data' => $data]);
$output->append($data);
break;
case 0xfe:// 'padding',