diff --git a/docs/en/_sidebar.md b/docs/en/_sidebar.md index 5e22d08..168c37b 100644 --- a/docs/en/_sidebar.md +++ b/docs/en/_sidebar.md @@ -1,12 +1,15 @@ -* MQTT Coroutine Client - * [Client API](en/client) - * [WebSocket Client API](en/websocket) +- MQTT Coroutine Client + - [Client API](en/client) + - [WebSocket Client API](en/websocket) -* MQTT Protocol Analysis - * [Protocol API](en/protocol) +- MQTT Protocol Analysis + - [Protocol API](en/protocol) -* MQTT Message - * [Message API](en/message) +- MQTT Message + - [Message API](en/message) -* Upgrade Guide - * [1.2 Upgrade Guide](en/upgrade/1.2.md) \ No newline at end of file +- Upgrade Guide + - [1.2 Upgrade Guide](en/upgrade/1.2) + +- Tools + - [Debug Tools](en/debug) diff --git a/docs/en/client.md b/docs/en/client.md index 222a941..b776cf8 100644 --- a/docs/en/client.md +++ b/docs/en/client.md @@ -157,14 +157,6 @@ New AUTH type added in MQTT5. Authentication exchange. Simps\MQTT\Client->auth(int $code = ReasonCode::SUCCESS, array $properties = []) ``` -## recv() - -Receive messages - -```php -Simps\MQTT\Client->recv(): bool|arary|string -``` - ## send() Send messages @@ -181,6 +173,14 @@ Simps\MQTT\Client->send(array $data, $response = true) Are acknowledgements required. If `true`, `recv()` is called once +## recv() + +Receive messages + +```php +Simps\MQTT\Client->recv(): bool|arary|string +``` + ## ping() Send a heartbeat diff --git a/docs/en/debug.md b/docs/en/debug.md new file mode 100644 index 0000000..797edb1 --- /dev/null +++ b/docs/en/debug.md @@ -0,0 +1,52 @@ +# Debug Tools + +The tool provides 5 methods for debugging binary data, essentially functioning as a binary data viewer. + +It primarily converts binary data into ASCII or hexadecimal formats for viewing, useful for debugging TCP, WebSocket, UDP, and other protocols. + +```php +public function hexDump(): string // Display in hexadecimal +public function hexDumpAscii(): string // Display in both hexadecimal and corresponding ASCII characters +public function printableText(): string // Printable characters +public function hexStream(): string // Hexadecimal stream +public function ascii(): string // Display in ASCII characters +``` + +You can call these methods statically or instantiate `Simps\MQTT\Tools\Debug` or `Simps\MQTT\Tools\Common`/`Simps\MQTT\Tools\UnPackTool`: + +- Instantiation + +```php +use Simps\MQTT\Tools\Debug; + +$debug = new Debug('0:simps-mqtt/user001/update{ + "msg": "hello, mqtt" +}'); + +//$debug = (new Debug())->setEncode('0:simps-mqtt/user001/update{ +// "msg": "hello, mqtt" +//}'); + +echo $debug->hexDump(), PHP_EOL; +echo $debug->hexDumpAscii(), PHP_EOL; +echo $debug->printableText(), PHP_EOL; +echo $debug->hexStream(), PHP_EOL; +echo $debug->ascii(); +``` + +- Static call + +```php +use Simps\MQTT\Tools\UnPackTool; + +echo UnPackTool::hexDumpAscii('0:simps-mqtt/user001/update{ + "msg": "hello, mqtt" +}'); +``` + +```text +00000000 30 3a 73 69 6d 70 73 2d 6d 71 74 74 2f 75 73 65 0:simps-mqtt/use +00000010 72 30 30 31 2f 75 70 64 61 74 65 7b 0a 20 20 22 r001/update{. " +00000020 6d 73 67 22 3a 20 22 68 65 6c 6c 6f 2c 20 6d 71 msg": "hello, mq +00000030 74 74 22 0a 7d tt".} +``` diff --git a/docs/en/websocket.md b/docs/en/websocket.md index 04edd56..40846de 100644 --- a/docs/en/websocket.md +++ b/docs/en/websocket.md @@ -157,14 +157,6 @@ New AUTH type added in MQTT5. Authentication exchange. Simps\MQTT\WebSocketClient->auth(int $code = ReasonCode::SUCCESS, array $properties = []) ``` -## recv() - -Receive messages - -```php -Simps\MQTT\WebSocketClient->recv(): bool|arary|string -``` - ## send() Send messages @@ -181,6 +173,14 @@ Simps\MQTT\WebSocketClient->send(array $data, $response = true) Are acknowledgements required. If `true`, `recv()` is called once +## recv() + +Receive messages + +```php +Simps\MQTT\WebSocketClient->recv(): bool|arary|string +``` + ## ping() Send a heartbeat diff --git a/docs/zh-cn/_sidebar.md b/docs/zh-cn/_sidebar.md index d7c7742..87b2a42 100644 --- a/docs/zh-cn/_sidebar.md +++ b/docs/zh-cn/_sidebar.md @@ -1,17 +1,16 @@ -* MQTT 协程客户端 - * [Client API](zh-cn/client) - * [WebSocket Client API](zh-cn/websocket) +- MQTT 协程客户端 + - [Client API](zh-cn/client) + - [WebSocket Client API](zh-cn/websocket) -* MQTT 协议解析 - * [Protocol API](zh-cn/protocol) +- MQTT 协议解析 + - [Protocol API](zh-cn/protocol) -* MQTT Message - * [Message API](zh-cn/message) +- MQTT Message + - [Message API](zh-cn/message) -* 版本升级指南 - * [1.2 升级指南](zh-cn/upgrade/1.2.md) +- 版本升级指南 + - [1.2 升级指南](zh-cn/upgrade/1.2) -* Tools - - - [Debug Tools](zh-cn/debug.md) - - [自适应协议等级](zh-cn/level.md) +- Tools + - [Debug Tools](zh-cn/debug) + - [自适应协议等级](zh-cn/level) diff --git a/docs/zh-cn/client.md b/docs/zh-cn/client.md index 6c4c400..76c015a 100644 --- a/docs/zh-cn/client.md +++ b/docs/zh-cn/client.md @@ -176,14 +176,6 @@ MQTT5 中新增的认证交换机制。 Simps\MQTT\Client->auth(int $code = ReasonCode::SUCCESS, array $properties = []) ``` -## recv() - -接收消息 - -```php -Simps\MQTT\Client->recv(): bool|arary|string -``` - ## send() 发送消息 @@ -200,6 +192,14 @@ Simps\MQTT\Client->send(array $data, $response = true) 是否需要回执。如果为`true`,会调用一次`recv()` +## recv() + +接收消息 + +```php +Simps\MQTT\Client->recv(): bool|arary|string +``` + ## ping() 发送心跳包 diff --git a/docs/zh-cn/websocket.md b/docs/zh-cn/websocket.md index d4bb7f1..36c0bd1 100644 --- a/docs/zh-cn/websocket.md +++ b/docs/zh-cn/websocket.md @@ -176,14 +176,6 @@ MQTT5 中新增的认证交换机制。 Simps\MQTT\WebSocketClient->auth(int $code = ReasonCode::SUCCESS, array $properties = []) ``` -## recv() - -接收消息 - -```php -Simps\MQTT\WebSocketClient->recv(): bool|arary|string -``` - ## send() 发送消息 @@ -200,6 +192,14 @@ Simps\MQTT\WebSocketClient->send(array $data, $response = true) 是否需要回执。如果为`true`,会调用一次`recv()` +## recv() + +接收消息 + +```php +Simps\MQTT\WebSocketClient->recv(): bool|arary|string +``` + ## ping() 发送心跳包