Skip to content

Commit

Permalink
Add Message docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Feb 24, 2021
1 parent a7ba577 commit bab2297
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/en/_sidebar.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
* MQTT Coroutine Client
* [Client API](en/client)

* MQTT Server
* [Message API](en/message)

* MQTT Protocol Analysis
* [Protocol API](en/protocol)

Expand Down
32 changes: 32 additions & 0 deletions docs/en/message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Message API

It is mainly convenient for replying to the ACK on the other side in the Server.

## Usage examples

```php
use Simps\MQTT\Message\SubAck;
use Simps\MQTT\Protocol\ProtocolInterface;

$codes = [0];
$message_id = 8520;

$ack = new SubAck();
$ack->setCodes($codes)
->setMessageId($message_id);

$ack_data = $ack->getContents();
$ack_data = (string) $ack;

// MQTT5
$ack->setProtocolLevel(ProtocolInterface::MQTT_PROTOCOL_LEVEL_5_0)
->setCodes($codes)
->setMessageId($message_id)
->setProperties([
'will_delay_interval' => 60,
'message_expiry_interval' => 60,
]);

$ack_data = $ack->getContents();
$ack_data = (string) $ack;
```
3 changes: 3 additions & 0 deletions docs/zh-cn/_sidebar.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
* MQTT 协程客户端
* [Client API](zh-cn/client)

* MQTT Server
* [Message API](zh-cn/message)

* MQTT 协议解析
* [Protocol API](zh-cn/protocol)

Expand Down
32 changes: 32 additions & 0 deletions docs/zh-cn/message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Message API

主要方便用于在 Server 中回复对端 ACK。

## 使用示例

```php
use Simps\MQTT\Message\SubAck;
use Simps\MQTT\Protocol\ProtocolInterface;

$codes = [0];
$message_id = 8520;

$ack = new SubAck();
$ack->setCodes($codes)
->setMessageId($message_id);

$ack_data = $ack->getContents();
$ack_data = (string) $ack;

// MQTT5
$ack->setProtocolLevel(ProtocolInterface::MQTT_PROTOCOL_LEVEL_5_0)
->setCodes($codes)
->setMessageId($message_id)
->setProperties([
'will_delay_interval' => 60,
'message_expiry_interval' => 60,
]);

$ack_data = $ack->getContents();
$ack_data = (string) $ack;
```

0 comments on commit bab2297

Please sign in to comment.