import MessagePack for PHP

This commit is contained in:
Hideyuki TAKEI 2010-04-05 00:10:28 +09:00
parent 254ee80c16
commit 99a2d28592
16 changed files with 2321 additions and 0 deletions

34
php/test_streaming.php Executable file
View file

@ -0,0 +1,34 @@
<?php
// serialized data
$msgs = array(pack("C*", 0x93, 0x01, 0x02, 0x03, 0x92), pack("C*", 0x03, 0x09, 0x04));
// streaming deserialize
$unpacker = new MessagePack();
$unpacker->initialize();
$buffer = "";
$nread = 0;
foreach($msgs as $msg){
$buffer = $buffer . $msg;
while(true){
$nread = $unpacker->execute($buffer, $nread);
if($unpacker->finished()){
$msg = $unpacker->data();
var_dump($msg);
$unpacker->initialize();
$buffer = substr($buffer, $nread);
$nread = 0;
if(!empty($buffer)){
continue;
}
}
break;
}
}
?>