Skip to content

Commit 60ce2af

Browse files
committed
Merge commit 'refs/pull/106/head' of github.com:msgpack/msgpack-php
2 parents 90598a3 + ad1c3b6 commit 60ce2af

1 file changed

Lines changed: 53 additions & 2 deletions

File tree

README.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,61 @@ $make && make install
2727
### Example
2828
```php
2929
<?php
30-
$data = array(0=>1,1=>2,2=>3);
30+
$data = array(0 => 1, 1 => 2, 2 => 3);
3131
$msg = msgpack_pack($data);
3232
$data = msgpack_unpack($msg);
33-
?>
3433
```
34+
35+
### Example Advanced
36+
```php
37+
<?php
38+
$data = array(0 => 1, 1 => 2, 2 => 3);
39+
$packer = new \MessagePack(false); //same as $packer->setOption(\MessagePack::OPT_PHPONLY, false);
40+
$packed = $packer->pack($data);
41+
42+
$unpacker = new \MessagePackUnpacker(false); //same as $unpacker->setOption(\MessagePack::OPT_PHPONLY, false);
43+
$unpacker->feed($packed);
44+
$unpacker->execute();
45+
$unpacked = $unpacker->data();
46+
$unpacker->reset();
47+
48+
```
49+
50+
### Example Advanced Streaming
51+
```php
52+
<?php
53+
$data1 = array(0 => 1, 1 => 2, 2 => 3);
54+
$data2 = array("a" => 1, "b" => 2, "c" => 3);
55+
56+
$packer = new \MessagePack(false);
57+
$packed1 = $packer->pack($data1);
58+
$packed2 = $packer->pack($data2);
59+
60+
$unpacker = new \MessagePackUnpacker(false);
61+
$buffer = "";
62+
$nread = 0;
63+
64+
//Simulating streaming data :)
65+
$buffer .= $packed1;
66+
$buffer .= $packed2;
67+
68+
while(true) {
69+
if($unpacker->execute($buffer, $nread)) {
70+
$msg = $unpacker->data();
71+
72+
var_dump($msg);
73+
74+
$unpacker->reset();
75+
$buffer = substr($buffer, $nread);
76+
$nread = 0;
77+
if(!empty($buffer)) {
78+
continue;
79+
}
80+
}
81+
break;
82+
}
83+
84+
```
85+
3586
# Resources
3687
* [msgpack](http://msgpack.org/)

0 commit comments

Comments
 (0)