private function createVariableHeaderFlags(): string
    {
        if ($this->isRedelivery) {
            // DUP flag: if the message is a re-delivery, mark it as such
            $this->specialFlags |= 8;
            $this->logger->debug('Activating redelivery bit');
        }

        if ($this->message->isRetained()) {
            // RETAIN flag: should the server retain the message?
            $this->specialFlags |= 1;
            $this->logger->debug('Activating retain flag');
        }

        // Check QoS level and perform the corresponding actions
        if ($this->message->getQoSLevel() !== 0) {
            // 0 for QoS lvl2 for QoS lvl1 and 4 for QoS lvl2
            $this->specialFlags |= ($this->message->getQoSLevel() * 2);
            $this->logger->debug(sprintf('Activating QoS level %d bit', $this->message->getQoSLevel()));
            return $this->getPacketIdentifierBinaryRepresentation();
        }

        return '';
    }