protected function buildVariableHeader()
    {
        $header = '';

        $topic = $this->message->getTopic();
        # Topic
        $header .= Utility::PackStringWithLength($topic);
        Debug::Log(Debug::DEBUG, 'Message PUBLISH: topic='.$topic);

        Debug::Log(Debug::DEBUG, 'Message PUBLISH: QoS='.$this->getQos());
        Debug::Log(Debug::DEBUG, 'Message PUBLISH: DUP='.$this->getDup());
        Debug::Log(Debug::DEBUG, 'Message PUBLISH: RETAIN='.$this->getRetain());

        # Message ID if QoS > 0
        if ($this->getQos()) {
            if (!$this->msgid) {
                throw new Exception('MsgID MUST be set if QoS is not 0.');
            }

            $header .= $this->packPacketIdentifer();
        }

        return $header;
    }