function subscriptionHandler(node, datatype ,topic, payload, packet) {
        const msg = {topic:topic, payload:null, qos:packet.qos, retain:packet.retain};
        const v5 = (node && node.brokerConn)
            ? node.brokerConn.v5()
            : Object.prototype.hasOwnProperty.call(packet, "properties");
        if(v5 && packet.properties) {
            setStrProp(packet.properties, msg, "responseTopic");
            setBufferProp(packet.properties, msg, "correlationData");
            setStrProp(packet.properties, msg, "contentType");
            setIntProp(packet.properties, msg, "messageExpiryInterval", 0);
            setBoolProp(packet.properties, msg, "payloadFormatIndicator");
            setStrProp(packet.properties, msg, "reasonString");
            setUserProperties(packet.properties.userProperties, msg);
        }
        const v5isUtf8 = v5 ? msg.payloadFormatIndicator === true : null;
        const v5HasMediaType = v5 ? !!msg.contentType : null;
        const v5MediaTypeLC = v5 ? (msg.contentType + "").toLowerCase() : null;

        if (datatype === "buffer") {
            // payload = payload;
        } else if (datatype === "base64") {
            payload = payload.toString('base64');
        } else if (datatype === "utf8") {
            payload = payload.toString('utf8');
        } else if (datatype === "json") {
            if (v5isUtf8 || isUtf8(payload)) {
                try {
                    payload = JSON.parse(payload.toString());
                } catch (e) {
                    node.error(RED._("mqtt.errors.invalid-json-parse"), { payload: payload, topic: topic, qos: packet.qos, retain: packet.retain }); return;
                }
            } else {
                node.error((RED._("mqtt.errors.invalid-json-string")), { payload: payload, topic: topic, qos: packet.qos, retain: packet.retain }); return;
            }
        } else {
            //"auto" (legacy) or "auto-detect" (new default)
            if (v5isUtf8 || v5HasMediaType) {
                const outputType = knownMediaTypes[v5MediaTypeLC]
                switch (outputType) {
                    case "string":
                        payload = payload.toString();
                        break;
                    case "buffer":
                        //no change
                        break;
                    case "json":
                        try {
                            //since v5 type states this should be JSON, parse it & error out if NOT JSON
                            payload = payload.toString()
                            const obj = JSON.parse(payload);
                            if (datatype === "auto-detect") {
                                payload = obj; //as mode is "auto-detect", return the parsed JSON
                            }
                        } catch (e) {
                            node.error(RED._("mqtt.errors.invalid-json-parse"), { payload: payload, topic: topic, qos: packet.qos, retain: packet.retain }); return;
                        }
                        break;
                    default:
                        if (v5isUtf8 || isUtf8(payload)) {
                            payload = payload.toString(); //auto String
                            if (datatype === "auto-detect") {
                                try {
                                    payload = JSON.parse(payload); //auto to parsed object (attempt)
                                } catch (e) {
                                    /* mute error - it simply isnt JSON, just leave payload as a string */
                                }
                            }
                        }
                        break;
                }
            } else if (isUtf8(payload)) {
                payload = payload.toString(); //auto String
                if (datatype === "auto-detect") {
                    try {
                        payload = JSON.parse(payload);
                    } catch (e) {
                        /* mute error - it simply isnt JSON, just leave payload as a string */
                    }
                }
            } //else {
                //leave as buffer
            //}
        }
        msg.payload = payload;
        if (node.brokerConn && (node.brokerConn.broker === "localhost" || node.brokerConn.broker === "127.0.0.1")) {
            msg._topic = topic;
        }
        node.send(msg);
    }
Handle the payload / packet recieved in MQTT In and MQTT Sub nodes