@@ -138,20 +138,33 @@ QVector<Event> I3Ipc::parseResponse(QByteArray rawEvent) {
138138 const int magicLen = 6 ;
139139 const int header = 8 + magicLen;
140140
141- while (rawEvent.startsWith (MAGIC)) {
141+ while (true ) {
142+ auto magicSeqInd = rawEvent.indexOf (MAGIC);
143+
144+ if (magicSeqInd < 0 ) {
145+ qCWarning (logI3Ipc) << " No magic sequence found in string." ;
146+ break ;
147+ };
148+
149+ if (magicSeqInd > 0 ) {
150+ rawEvent = rawEvent.sliced (magicSeqInd);
151+ }
152+
142153 auto eventLength = rawEvent.length ();
143154
144155 if (eventLength < header) {
145156 qCWarning (logI3Ipc) << " Event isn't long enough to hold the header data (14 bytes)." ;
146157 break ;
147158 };
148159
149- QDataStream ds (QByteArray (rawEvent.data () + magicLen, 8 )); // NOLINT
160+ rawEvent = rawEvent.sliced (magicLen);
161+
162+ QDataStream ds (rawEvent);
150163
151164 ds.setByteOrder (static_cast <QDataStream::ByteOrder>(QSysInfo::ByteOrder));
152165
153- quint32 size = 0 ;
154- quint32 type = 0 ;
166+ qint32 size = 0 ;
167+ qint32 type = EventCode::UNKNOWN ;
155168
156169 ds >> size;
157170 ds >> type;
@@ -169,19 +182,17 @@ QVector<Event> I3Ipc::parseResponse(QByteArray rawEvent) {
169182 break ;
170183 }
171184
172- auto byteData = QByteArray ( rawEvent.data () + header, size); // NOLINT
185+ rawEvent = rawEvent.sliced ( 8 );
173186
174187 QJsonParseError e;
175188
176- auto data = QJsonDocument::fromJson (byteData , &e);
189+ auto data = QJsonDocument::fromJson (rawEvent. sliced ( 0 , size) , &e);
177190
178191 if (e.error != QJsonParseError::NoError) {
179- qCWarning (logI3Ipc) << " Invalid JSON value:" << e.errorString () << " \n\t " << byteData ;
192+ qCWarning (logI3Ipc) << " Invalid JSON value:" << e.errorString () << " \n\t " << rawEvent ;
180193 } else {
181194 events.push_back (std::tuple (I3IpcEvent::intToEvent (type), data));
182195 }
183-
184- rawEvent = rawEvent.sliced (header + size);
185196 }
186197
187198 return events;
0 commit comments