                     return
                 }
 
-                if let message = MQTTMessage(rawValue: messageBuffer.pointee & 0xf0) {
+                if let message = PacketType(rawValue: messageBuffer.pointee & 0xf0) {
                     messageType = message
                     messageParserState = .decodingLength
                     messageLengthMultiplier = 1


    private func readStream(input: InputStream, output: OutputStream) {
        var messageParserState: MQTTMessageParserState = .decodingHeader
        var messageType: MQTTMessage = .connack

        var messageLengthMultiplier = 1
        var messageLength = 0

    }

    func disconnect() {
        mqttDisconnect()
        closeStreams()
    }

    func subscribe(to topic: String) {
        mqttSubscribe(to: topic)
    }

    func unsubscribe(from topic: String) {
        mqttUnsubscribe(from: topic)
    }

    func publish(to topic: String, message: Data?) {
        mqttPublish(to: topic, message: message ?? Data())
    }

    // MARK: - Keep alive timer

    private func delayedPing() {
        let interval = options.pingInterval
        let time = DispatchTime.now() + Double(interval / 2)
        DispatchQueue.main.asyncAfter(deadline: time) { [weak self] in
            if let output = self?.outputStream, output.streamStatus == .open {
                // pass, ok to keep going
            }
            else {
                return // recursion stopper
            } 

            self?.mqttPing()
            self?.delayedPing()
        }
    }

