|
1 | 1 | #include "include/DuckNet.h" |
2 | 2 | #include <cstring> |
| 3 | +#include <ArduinoJson.h> |
3 | 4 |
|
4 | 5 | DuckNet::DuckNet(BloomFilter *filter): bloomFilter(filter) { |
5 | 6 | } |
@@ -407,7 +408,28 @@ uint8_t* DuckNet::serializeAtakHistoryToBytes(CircularBuffer* buffer, size_t* to |
407 | 408 | while(tail != buffer->getHead()){ |
408 | 409 | CdpPacket packet = buffer->getMessage(tail); |
409 | 410 | packetArr.insert(packetArr.end(), packet.muid.begin(), packet.muid.end()); |
410 | | - packetArr.insert(packetArr.end(), packet.data.begin(), packet.data.end()); |
| 411 | + // packetArr.insert(packetArr.end(), packet.data.begin(), packet.data.end()); |
| 412 | + |
| 413 | + // Decode JSON from packet.data |
| 414 | + DynamicJsonDocument doc(256); |
| 415 | + DeserializationError err = deserializeJson(doc, packet.data.data(), packet.data.size()); |
| 416 | + if (err) { |
| 417 | + logerr_ln("JSON parse error in packet.data"); |
| 418 | + } else { |
| 419 | + // Extract fields |
| 420 | + const char* body = doc["body"] | ""; |
| 421 | + const char* username = doc["username"] | ""; |
| 422 | + |
| 423 | + // Manually encode: [len][data] |
| 424 | + uint8_t bodyLen = strlen(body); |
| 425 | + packetArr.push_back(bodyLen); |
| 426 | + packetArr.insert(packetArr.end(), body, body + bodyLen); |
| 427 | + |
| 428 | + uint8_t usernameLen = strlen(username); |
| 429 | + packetArr.push_back(usernameLen); |
| 430 | + packetArr.insert(packetArr.end(), username, username + usernameLen); |
| 431 | + } |
| 432 | + |
411 | 433 | tail++; |
412 | 434 | if(tail == buffer->getBufferEnd()){ |
413 | 435 | tail = 0; |
|
0 commit comments