From: Drew Fisher Date: Wed, 7 May 2014 07:23:08 +0000 (-0700) Subject: ribbon: send packets sans null-terminator X-Git-Url: http://git.zarvox.org/shortlog?a=commitdiff_plain;h=d3ec49ba83effc04ba99b3111971d7d64c7485a2;p=imoo.git ribbon: send packets sans null-terminator --- diff --git a/ribbon/ribbonserver.cpp b/ribbon/ribbonserver.cpp index ba8889e..04ef9ff 100644 --- a/ribbon/ribbonserver.cpp +++ b/ribbon/ribbonserver.cpp @@ -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) {