Skip to content

Commit 75aca0b

Browse files
committed
Update pack n
1 parent 60922be commit 75aca0b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

examples/v5/server.php

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
try {
3434
Common::printf($data);
3535
$data = ProtocolV5::unpack($data);
36+
var_dump($data);
3637
if (is_array($data) && isset($data['type'])) {
3738
switch ($data['type']) {
3839
case Types::CONNECT:

src/Packet/Pack.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function connect(array $array): string
4141
$body .= chr($connect_flags);
4242

4343
$keepAlive = !empty($array['keep_alive']) && (int) $array['keep_alive'] >= 0 ? (int) $array['keep_alive'] : 0;
44-
$body .= pack('n', $keepAlive);
44+
$body .= PackTool::shortInt($keepAlive);
4545

4646
$body .= PackTool::string($array['client_id']);
4747
if (!empty($array['will'])) {
@@ -74,7 +74,7 @@ public static function publish(array $array): string
7474
$body = PackTool::string($array['topic']);
7575
$qos = $array['qos'] ?? 0;
7676
if ($qos) {
77-
$body .= pack('n', $array['message_id']);
77+
$body .= PackTool::shortInt($array['message_id']);
7878
}
7979
$body .= $array['message'];
8080
$dup = $array['dup'] ?? 0;
@@ -87,7 +87,7 @@ public static function publish(array $array): string
8787
public static function subscribe(array $array): string
8888
{
8989
$id = $array['message_id'];
90-
$body = pack('n', $id);
90+
$body = PackTool::shortInt($id);
9191
foreach ($array['topics'] as $topic => $qos) {
9292
$body .= PackTool::string($topic);
9393
$body .= chr($qos);
@@ -100,7 +100,7 @@ public static function subscribe(array $array): string
100100
public static function subAck(array $array): string
101101
{
102102
$payload = $array['payload'];
103-
$body = pack('n', $array['message_id']) . call_user_func_array(
103+
$body = PackTool::shortInt($array['message_id']) . call_user_func_array(
104104
'pack',
105105
array_merge(['C*'], $payload)
106106
);
@@ -111,7 +111,7 @@ public static function subAck(array $array): string
111111

112112
public static function unSubscribe(array $array): string
113113
{
114-
$body = pack('n', $array['message_id']);
114+
$body = PackTool::shortInt($array['message_id']);
115115
foreach ($array['topics'] as $topic) {
116116
$body .= PackTool::string($topic);
117117
}

0 commit comments

Comments
 (0)