Skip to content

Commit

Permalink
Update MQTT3 pack connect
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Jan 14, 2021
1 parent 9d908b7 commit e669288
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Hex/ReasonCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static function getReasonPhrases(bool $isQos = false): array
public static function getReasonPhrase(int $value, bool $isQos = false): string
{
if ($isQos) {
return static::$qosReasonPhrases[$value] ?? 'Wrong QoS';
return static::$qosReasonPhrases[$value] ?? 'QoS not supported';
}

return static::$reasonPhrases[$value] ?? 'Unknown';
Expand Down
5 changes: 5 additions & 0 deletions src/Packet/Pack.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Simps\MQTT\Packet;

use Simps\MQTT\Exception\ProtocolException;
use Simps\MQTT\ProtocolInterface;
use Simps\MQTT\Tools\PackTool;
use Simps\MQTT\Types;

Expand All @@ -28,6 +30,9 @@ public static function connect(array $array): string
if (!empty($array['will'])) {
$connectFlags |= 1 << 2;
if (isset($array['will']['qos'])) {
if ($array['will']['qos'] > ProtocolInterface::MQTT_QOS_2) {
throw new ProtocolException("QoS {$array['will']['qos']} not supported");
}
$connectFlags |= $array['will']['qos'] << 3;
}
if (!empty($array['will']['retain'])) {
Expand Down
6 changes: 6 additions & 0 deletions src/ProtocolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ interface ProtocolInterface

const MQTT_PROTOCOL_NAME = 'MQTT';

const MQTT_QOS_0 = 0;

const MQTT_QOS_1 = 1;

const MQTT_QOS_2 = 2;

public static function pack(array $array): string;

public static function unpack(string $data): array;
Expand Down

0 comments on commit e669288

Please sign in to comment.