> 2; if ($size >= 60) { $count = $size - 59; checkSnappy($position + $count <= strlen($encoded), 'truncated size'); $size = 0; for ($i = 0; $i < $count; ++$i) { $size |= ord($encoded[$position++]) << ($i * 8); } } ++$size; checkSnappy($position + $size <= strlen($encoded), 'truncated literal'); $output .= substr($encoded, $position, $size); $position += $size; } checkSnappy(strlen($output) === $length, 'uncompressed length mismatch'); return $output; } $cases = ['', 'a', "synthetic\0payload"]; foreach ([60, 61, 255, 256, 65535, 65536, 65537, 131073] as $length) { $cases[] = str_repeat('x', $length); } foreach ($cases as $plain) { $encoded = NiroRawSnappy::encodeLiteral($plain); checkSnappy(readLiteralSnappy($encoded) === $plain, 'round trip failed'); checkSnappy($encoded === NiroRawSnappy::encodeLiteral($plain), 'not deterministic'); } $rejected = false; try { NiroRawSnappy::encodeLiteral(str_repeat('x', 8 * 1024 * 1024 + 1)); } catch (InvalidArgumentException $expected) { $rejected = true; } checkSnappy($rejected, 'oversized input was accepted'); echo 'NiroRawSnappyTest passed cases=' . count($cases) . PHP_EOL;