Skip to content

Commit

Permalink
Add Auth Message
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Mar 8, 2021
1 parent b9d4365 commit 36f6a9d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/Message/Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* This file is part of Simps
*
* @link https://github.com/simps/mqtt
* @contact Lu Fei <[email protected]>
*
* 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\V5;

class Auth extends AbstractMessage
{
protected $code = ReasonCode::SUCCESS;

public function getCode(): int
{
return $this->code;
}

public function setCode(int $code): self
{
$this->code = $code;

return $this;
}

// AUTH type is only available in MQTT5
public function getContents(bool $getArray = false)
{
$buffer = [
'type' => Types::AUTH,
'code' => $this->getCode(),
'properties' => $this->getProperties(),
];

if ($getArray) {
return $buffer;
}

return V5::pack($buffer);
}
}

0 comments on commit 36f6a9d

Please sign in to comment.