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; }