mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 10:19:51 +00:00
import MessagePack for PHP
This commit is contained in:
parent
254ee80c16
commit
99a2d28592
16 changed files with 2321 additions and 0 deletions
34
php/test_streaming.php
Executable file
34
php/test_streaming.php
Executable 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue