]> git.zarvox.org Git - imoo.git/commitdiff
ribbon: send packets sans null-terminator
authorDrew Fisher <drew.m.fisher@gmail.com>
Wed, 7 May 2014 07:23:08 +0000 (00:23 -0700)
committerDrew Fisher <drew.m.fisher@gmail.com>
Wed, 7 May 2014 07:23:08 +0000 (00:23 -0700)
ribbon/ribbonserver.cpp

index ba8889e34b50f40cba1054e35df260fb1bdfd864..04ef9ffd180d69b4fd0f1eb14bd8c0efd1daecce 100644 (file)
@@ -96,10 +96,12 @@ void RibbonServer::sendEventToClient(QString sender, QString method, QVariantMap
        msg["params"] = ctx;
        QJsonObject obj = QJsonObject::fromVariantMap(msg);
        QJsonDocument doc(obj);
-       QByteArray msg_bytes = doc.toJson();
+       QByteArray msg_bytes = doc.toJson(QJsonDocument::Compact);
        QByteArray packet;
        QDataStream stream(&packet, QIODevice::WriteOnly);
-       stream << msg_bytes.constData();
+       // Use writeBytes rather than << to avoid putting the null terminator from
+       // msg_bytes in the packet.
+       stream.writeBytes(msg_bytes.constData(), msg_bytes.length());
        //qDebug() << "Would send" << packet.toHex();
        // No queueing, no blocking, no reliable delivery, no frills.
        foreach (RibbonSocket* s , sockets) {