コード例 #1
0
ファイル: Connect.php プロジェクト: Lstt2005/phpMqttClient
 /**
  * @param Version $version
  * @param string|null $username
  * @param string|null $password
  * @param string|null $clientId
  * @param bool $cleanSession
  * @param string|null $willTopic
  * @param string|null $willMessage
  * @param bool|null $willQos
  * @param null $willRetain
  */
 public function __construct(Version $version, $username = null, $password = null, $clientId = null, $cleanSession = true, $willTopic = null, $willMessage = null, $willQos = null, $willRetain = null)
 {
     parent::__construct($version);
     $this->clientId = $clientId;
     $this->username = $username;
     $this->password = $password;
     $this->cleanSession = boolval($cleanSession);
     $this->willTopic = $willTopic;
     $this->willMessage = $willMessage;
     $this->willQos = boolval($willQos);
     $this->willRetain = $willRetain;
     $this->buildPayload();
 }
コード例 #2
0
ファイル: Publish.php プロジェクト: Lstt2005/phpMqttClient
 public static function parse(Version $version, $rawInput)
 {
     /** @var Publish $packet */
     $packet = parent::parse($version, $rawInput);
     $topic = static::getPayloadLengthPrefixFieldInRawInput(2, $rawInput);
     $packet->setTopic($topic);
     $packet->setReceiveTimestamp(new \DateTime());
     if (!empty($rawInput[0])) {
         $packet->setRetain(($rawInput[0] & 1) === 1);
         $packet->setDup(($rawInput[0] & 8) === 8);
         if (($rawInput[0] & 2) === 2) {
             $packet->setQos(1);
         } elseif (($rawInput[0] & 4) === 4) {
             $packet->setQos(2);
         }
     }
     $packet->setMessage(substr($rawInput, 4 + strlen($topic)));
     return $packet;
 }