Reorganize the Predis\Protocols namespace.

This commit is contained in:
Daniele Alessandri
2011-04-06 17:52:39 +02:00
parent 80f1cedf79
commit db95350c37
15 changed files with 42 additions and 30 deletions
@@ -0,0 +1,25 @@
<?php
namespace Predis\Protocols\Text;
use Predis\Commands\ICommand;
use Predis\Protocols\ICommandSerializer;
class TextCommandSerializer implements ICommandSerializer {
public function serialize(ICommand $command) {
$commandId = $command->getId();
$arguments = $command->getArguments();
$cmdlen = strlen($commandId);
$reqlen = count($arguments) + 1;
$buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandId}\r\n";
for ($i = 0; $i < $reqlen - 1; $i++) {
$argument = $arguments[$i];
$arglen = strlen($argument);
$buffer .= "\${$arglen}\r\n{$argument}\r\n";
}
return $buffer;
}
}