MCPcopy Create free account
hub / github.com/dannagle/PacketSender / ImportJSON

Method ImportJSON

src/packet.cpp:220–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218}
219
220QList<Packet> Packet::ImportJSON(QByteArray data)
221{
222 QList<Packet> returnList;
223
224 QJsonDocument doc = QJsonDocument::fromJson(data);
225
226
227 if (!doc.isNull()) {
228 //valid json
229 if (doc.isArray()) {
230 //valid array
231 QJsonArray jsonArray = doc.array();
232 if (!jsonArray.isEmpty()) {
233 QDEBUG() << "Found" << jsonArray.size() << "packets";
234
235 for (int i = 0; i < jsonArray.size(); i++) {
236 Packet pkt;
237 pkt.clear();
238 QJsonObject json = jsonArray[i].toObject();
239
240 pkt.name = json["name"].toString();
241 pkt.errorString = json["errorstring"].toString();
242 pkt.fromIP = json["fromip"].toString();
243 pkt.fromPort = json["fromport"].toString().toUInt();
244 pkt.hexString = json["hexstring"].toString();
245 if(json.contains("requestpath")) {
246 pkt.requestPath = json["requestpath"].toString();
247 }
248 pkt.toIP = json["toip"].toString();
249 pkt.port = json["port"].toString().toUInt();
250 pkt.repeat = json["repeat"].toString().toFloat();
251 pkt.sendResponse = json["sendresponse"].toString().toUInt();
252 pkt.tcpOrUdp = json["tcporudp"].toString();
253
254 returnList.append(pkt);
255
256 }
257
258
259 }
260
261 }
262 }
263
264
265 return returnList;
266}
267
268#ifndef CONSOLE_BUILD
269

Callers

nothing calls this directly

Calls 4

sizeMethod · 0.80
toStringMethod · 0.80
appendMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected