diff options
| author | Hideyuki TAKEI <takehide22@gmail.com> | 2010-04-05 00:10:28 +0900 |
|---|---|---|
| committer | Hideyuki TAKEI <takehide22@gmail.com> | 2010-04-05 00:10:28 +0900 |
| commit | 99a2d2859269ddf803a802c043babcd977260faf (patch) | |
| tree | 5d0a89a77fab9f3c81dbcf49ef5696ef6d3b1f26 /php/test_streaming.php | |
| parent | 254ee80c16b3b0ce12b461d189aa1e6302debea0 (diff) | |
| download | msgpack-python-99a2d2859269ddf803a802c043babcd977260faf.tar.gz | |
import MessagePack for PHP
Diffstat (limited to 'php/test_streaming.php')
| -rwxr-xr-x | php/test_streaming.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/php/test_streaming.php b/php/test_streaming.php new file mode 100755 index 0000000..8f89f4c --- /dev/null +++ b/php/test_streaming.php @@ -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; + } + } +?> + |
