Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,10 +27,61 @@ $make && make install
### Example
```php
<?php
$data = array(0=>1,1=>2,2=>3);
$data = array(0 => 1, 1 => 2, 2 => 3);
$msg = msgpack_pack($data);
$data = msgpack_unpack($msg);
?>
```

### Example Advanced
```php
<?php
$data = array(0 => 1, 1 => 2, 2 => 3);
$packer = new \MessagePack(false); //same as $packer->setOption(\MessagePack::OPT_PHPONLY, false);
$packed = $packer->pack($data);

$unpacker = new \MessagePackUnpacker(false); //same as $unpacker->setOption(\MessagePack::OPT_PHPONLY, false);
$unpacker->feed($packed);
$unpacker->execute();
$unpacked = $unpacker->data();
$unpacker->reset();

```

### Example Advanced Streaming
```php
<?php
$data1 = array(0 => 1, 1 => 2, 2 => 3);
$data2 = array("a" => 1, "b" => 2, "c" => 3);

$packer = new \MessagePack(false);
$packed1 = $packer->pack($data1);
$packed2 = $packer->pack($data2);

$unpacker = new \MessagePackUnpacker(false);
$buffer = ""
$nread = 0;

//Simulating streaming data :)
$buffer .= $packed1;
$buffer .= $packed2;

while(true){
if($unpacker->execute($buffer, $nread)){
$msg = $unpacker->data();

var_dump($msg);

$unpacker->reset();
$buffer = substr($buffer, $nread);
$nread = 0;
if(!empty($buffer)){
continue;
}
}
break;
}

```

# Resources
* [msgpack](http://msgpack.org/)