-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DISCONNECT、PUBACK、PUBREC、PUBREL、UNSUBACK
- Loading branch information
1 parent
09f6334
commit 20a78c7
Showing
6 changed files
with
387 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* This file is part of Simps | ||
* | ||
* @link https://github.com/simps/mqtt | ||
* @contact Lu Fei <lufei@simps.io> | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Simps\MQTT\Message; | ||
|
||
use Simps\MQTT\Hex\ReasonCode; | ||
use Simps\MQTT\Protocol\Types; | ||
use Simps\MQTT\Protocol\V3; | ||
use Simps\MQTT\Protocol\V5; | ||
|
||
class DisConnect extends AbstractMessage | ||
{ | ||
protected $code = ReasonCode::NORMAL_DISCONNECTION; | ||
|
||
public function getCode(): int | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function setCode(int $code): self | ||
{ | ||
$this->code = $code; | ||
|
||
return $this; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
$buffer = [ | ||
'type' => Types::DISCONNECT, | ||
]; | ||
|
||
if ($this->isMQTT5()) { | ||
$buffer['code'] = $this->getCode(); | ||
$buffer['properties'] = $this->getProperties(); | ||
|
||
return V5::pack($buffer); | ||
} | ||
|
||
return V3::pack($buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* This file is part of Simps | ||
* | ||
* @link https://github.com/simps/mqtt | ||
* @contact Lu Fei <lufei@simps.io> | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Simps\MQTT\Message; | ||
|
||
use Simps\MQTT\Hex\ReasonCode; | ||
use Simps\MQTT\Protocol\Types; | ||
use Simps\MQTT\Protocol\V3; | ||
use Simps\MQTT\Protocol\V5; | ||
|
||
class PubAck extends AbstractMessage | ||
{ | ||
protected $messageId = 0; | ||
|
||
protected $code = ReasonCode::SUCCESS; | ||
|
||
public function getMessageId(): int | ||
{ | ||
return $this->messageId; | ||
} | ||
|
||
public function setMessageId(int $messageId): self | ||
{ | ||
$this->messageId = $messageId; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCode(): int | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function setCode(int $code): self | ||
{ | ||
$this->code = $code; | ||
|
||
return $this; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
$buffer = [ | ||
'type' => Types::PUBACK, | ||
'message_id' => $this->getMessageId(), | ||
]; | ||
|
||
if ($this->isMQTT5()) { | ||
$buffer['code'] = $this->getCode(); | ||
$buffer['properties'] = $this->getProperties(); | ||
|
||
return V5::pack($buffer); | ||
} | ||
|
||
return V3::pack($buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* This file is part of Simps | ||
* | ||
* @link https://github.com/simps/mqtt | ||
* @contact Lu Fei <lufei@simps.io> | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Simps\MQTT\Message; | ||
|
||
use Simps\MQTT\Hex\ReasonCode; | ||
use Simps\MQTT\Protocol\Types; | ||
use Simps\MQTT\Protocol\V3; | ||
use Simps\MQTT\Protocol\V5; | ||
|
||
class PubComp extends AbstractMessage | ||
{ | ||
protected $messageId = 0; | ||
|
||
protected $code = ReasonCode::SUCCESS; | ||
|
||
public function getMessageId(): int | ||
{ | ||
return $this->messageId; | ||
} | ||
|
||
public function setMessageId(int $messageId): self | ||
{ | ||
$this->messageId = $messageId; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCode(): int | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function setCode(int $code): self | ||
{ | ||
$this->code = $code; | ||
|
||
return $this; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
$buffer = [ | ||
'type' => Types::PUBCOMP, | ||
'message_id' => $this->getMessageId(), | ||
]; | ||
|
||
if ($this->isMQTT5()) { | ||
$buffer['code'] = $this->getCode(); | ||
$buffer['properties'] = $this->getProperties(); | ||
|
||
return V5::pack($buffer); | ||
} | ||
|
||
return V3::pack($buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* This file is part of Simps | ||
* | ||
* @link https://github.com/simps/mqtt | ||
* @contact Lu Fei <lufei@simps.io> | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Simps\MQTT\Message; | ||
|
||
use Simps\MQTT\Hex\ReasonCode; | ||
use Simps\MQTT\Protocol\Types; | ||
use Simps\MQTT\Protocol\V3; | ||
use Simps\MQTT\Protocol\V5; | ||
|
||
class PubRec extends AbstractMessage | ||
{ | ||
protected $messageId = 0; | ||
|
||
protected $code = ReasonCode::SUCCESS; | ||
|
||
public function getMessageId(): int | ||
{ | ||
return $this->messageId; | ||
} | ||
|
||
public function setMessageId(int $messageId): self | ||
{ | ||
$this->messageId = $messageId; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCode(): int | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function setCode(int $code): self | ||
{ | ||
$this->code = $code; | ||
|
||
return $this; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
$buffer = [ | ||
'type' => Types::PUBREC, | ||
'message_id' => $this->getMessageId(), | ||
]; | ||
|
||
if ($this->isMQTT5()) { | ||
$buffer['code'] = $this->getCode(); | ||
$buffer['properties'] = $this->getProperties(); | ||
|
||
return V5::pack($buffer); | ||
} | ||
|
||
return V3::pack($buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* This file is part of Simps | ||
* | ||
* @link https://github.com/simps/mqtt | ||
* @contact Lu Fei <lufei@simps.io> | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Simps\MQTT\Message; | ||
|
||
use Simps\MQTT\Hex\ReasonCode; | ||
use Simps\MQTT\Protocol\Types; | ||
use Simps\MQTT\Protocol\V3; | ||
use Simps\MQTT\Protocol\V5; | ||
|
||
class PubRel extends AbstractMessage | ||
{ | ||
protected $messageId = 0; | ||
|
||
protected $code = ReasonCode::SUCCESS; | ||
|
||
public function getMessageId(): int | ||
{ | ||
return $this->messageId; | ||
} | ||
|
||
public function setMessageId(int $messageId): self | ||
{ | ||
$this->messageId = $messageId; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCode(): int | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function setCode(int $code): self | ||
{ | ||
$this->code = $code; | ||
|
||
return $this; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
$buffer = [ | ||
'type' => Types::PUBREL, | ||
'message_id' => $this->getMessageId(), | ||
]; | ||
|
||
if ($this->isMQTT5()) { | ||
$buffer['code'] = $this->getCode(); | ||
$buffer['properties'] = $this->getProperties(); | ||
|
||
return V5::pack($buffer); | ||
} | ||
|
||
return V3::pack($buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* This file is part of Simps | ||
* | ||
* @link https://github.com/simps/mqtt | ||
* @contact Lu Fei <lufei@simps.io> | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Simps\MQTT\Message; | ||
|
||
use Simps\MQTT\Hex\ReasonCode; | ||
use Simps\MQTT\Protocol\Types; | ||
use Simps\MQTT\Protocol\V3; | ||
use Simps\MQTT\Protocol\V5; | ||
|
||
class UnSubAck extends AbstractMessage | ||
{ | ||
protected $messageId = 0; | ||
|
||
protected $code = ReasonCode::SUCCESS; | ||
|
||
public function getMessageId(): int | ||
{ | ||
return $this->messageId; | ||
} | ||
|
||
public function setMessageId(int $messageId): self | ||
{ | ||
$this->messageId = $messageId; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCode(): int | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function setCode(int $code): self | ||
{ | ||
$this->code = $code; | ||
|
||
return $this; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
$buffer = [ | ||
'type' => Types::UNSUBACK, | ||
'message_id' => $this->getMessageId(), | ||
]; | ||
|
||
if ($this->isMQTT5()) { | ||
$buffer['code'] = $this->getCode(); | ||
$buffer['properties'] = $this->getProperties(); | ||
|
||
return V5::pack($buffer); | ||
} | ||
|
||
return V3::pack($buffer); | ||
} | ||
} |