Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilevrv authored Mar 22, 2018
1 parent a301674 commit 6093773
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,92 @@
# tproto

### How to use.

Create Transmitter. For example, use transmitter with unbuffered PDO query and symfony:

```
return new \Symfony\Component\HttpFoundation\StreamedResponse(function() use ($pdo) {
$pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
$res = $pdo->query("SELECT id, status FROM tblclients");
while (false !== ($row = $res->fetch(\PDO::FETCH_ASSOC))) {
$tm->send($row);
}
});
```

Create receiver. For example (now there is only guzzle adapter, you can use your own adapters):

```
$stream = $client->get('https://test.com/stream')->getBody();
$update = new \RV\TProto\Proto\Receiver\Receiver($stream, function($data) {
print_r($data);
});
$update->run();
```

If you need to receive objects not one at a time, but a batch, then you can use BatchReceiver (200 in batch, for example):

```
$stream = $client->get('https://test.com/stream')->getBody();
$update = new \RV\TProto\Proto\Receiver\BatchReceiver($stream, function($data) {
print count($data);
}, null, 200);
$update->run();
```

---

Also, you can use customize serializer and DTO:

```
class Client
{
public $id;
public $status;
public function __construct($id, $status)
{
$this->id = $id;
$this->status = $status;
}
}
```

```
class CustomSerializer implements \RV\TProto\Serializer\SerializerInterface
{
public function serialize($data)
{
return $data['id'].";".$data['status'];
}
public function deserialize($data)
{
return new Client($data['id'], $data['status']);
}
public function getDelimiter()
{
return ":";
}
}
```

And use it on transmitter and receiver, for example receiver:

```
$update = new \RV\TProto\Proto\Receiver\Receiver($stream, function($data) {
var_dump($data);
}, new CustomSerializer());
```

It print object:

```
object(Client)#1 (2) {
["id"]=>
int(123)
["status"]=>
int(0)
}
```

0 comments on commit 6093773

Please sign in to comment.