Support new message format in frontend
authorunC0Rr
Thu, 22 Nov 2018 13:52:00 +0100
changeset 14274 0ae9885e1535
parent 14273 645e4591361f
child 14275 61bc44de2b4c
Support new message format in frontend
qmlfrontend/game_config.cpp
--- a/qmlfrontend/game_config.cpp	Thu Nov 22 13:40:58 2018 +0100
+++ b/qmlfrontend/game_config.cpp	Thu Nov 22 13:52:00 2018 +0100
@@ -1,5 +1,7 @@
 #include "game_config.h"
 
+#include <QtEndian>
+
 GameConfig::GameConfig() {}
 
 const char** GameConfig::argv() const {
@@ -54,9 +56,20 @@
 }
 
 void GameConfig::cfgAppend(const QByteArray& cmd) {
-  Q_ASSERT(cmd.size() < 256);
+  Q_ASSERT(cmd.size() <= 49215);
 
-  quint8 len = cmd.size();
-  m_cfg.append(QByteArray::fromRawData(reinterpret_cast<const char*>(&len), 1) +
-               cmd);
+  if (cmd.size() < 64) {
+    quint8 len = static_cast<quint8>(cmd.size());
+    m_cfg.append(
+        QByteArray::fromRawData(reinterpret_cast<const char*>(&len), 1));
+  } else {
+    quint16 size = static_cast<quint16>(cmd.size()) - 64;
+    size = (size / 256 + 64) * 256 + size & 0xff;
+    quint16 size_be = qToBigEndian(size);
+
+    m_cfg.append(
+        QByteArray::fromRawData(reinterpret_cast<const char*>(&size_be), 2));
+  }
+
+  m_cfg.append(cmd);
 }