mirror of
https://github.com/agessaman/MeshCore.git
synced 2026-07-20 20:01:03 +00:00
Refactor Packet handling in MQTTMessageBuilder to support multibyte paths. Update path length handling in Packet::writeTo and Packet::readFrom methods, ensuring correct byte length calculations. Modify path string formatting in MQTTMessageBuilder for improved clarity on path details.
This commit is contained in:
+9
-5
@@ -56,8 +56,9 @@ uint8_t Packet::writeTo(uint8_t dest[]) const {
|
||||
memcpy(&dest[i], &transport_codes[0], 2); i += 2;
|
||||
memcpy(&dest[i], &transport_codes[1], 2); i += 2;
|
||||
}
|
||||
dest[i++] = path_len;
|
||||
memcpy(&dest[i], path, path_len); i += path_len;
|
||||
dest[i++] = (uint8_t)path_len;
|
||||
size_t path_byte_len = getPathByteLen();
|
||||
memcpy(&dest[i], path, path_byte_len); i += path_byte_len;
|
||||
memcpy(&dest[i], payload, payload_len); i += payload_len;
|
||||
return i;
|
||||
}
|
||||
@@ -71,9 +72,12 @@ bool Packet::readFrom(const uint8_t src[], uint8_t len) {
|
||||
} else {
|
||||
transport_codes[0] = transport_codes[1] = 0;
|
||||
}
|
||||
path_len = src[i++];
|
||||
if (path_len > sizeof(path)) return false; // bad encoding
|
||||
memcpy(path, &src[i], path_len); i += path_len;
|
||||
uint8_t pl = src[i++];
|
||||
path_len = pl;
|
||||
if ((pl >> 6) == 3) return false; // reserved path mode
|
||||
uint8_t path_byte_len = (pl & 63) * ((pl >> 6) + 1);
|
||||
if (path_byte_len > sizeof(path) || i + path_byte_len > len) return false; // bad encoding
|
||||
memcpy(path, &src[i], path_byte_len); i += path_byte_len;
|
||||
if (i >= len) return false; // bad encoding
|
||||
payload_len = len - i;
|
||||
if (payload_len > sizeof(payload)) return false; // bad encoding
|
||||
|
||||
@@ -211,18 +211,18 @@ int MQTTMessageBuilder::buildPacketJSON(
|
||||
packet->calculatePacketHash(packet_hash);
|
||||
bytesToHex(packet_hash, MAX_HASH_SIZE, hash_str, sizeof(hash_str));
|
||||
|
||||
// Build path string for direct packets
|
||||
// Build path string for direct packets (multibyte-path: show hash count, hash size, byte length)
|
||||
char path_str[128] = "";
|
||||
if (packet->isRouteDirect() && packet->path_len > 0) {
|
||||
// Simplified path representation
|
||||
snprintf(path_str, sizeof(path_str), "path_len_%d", packet->path_len);
|
||||
snprintf(path_str, sizeof(path_str), "path_%dx%d_%db",
|
||||
(int)packet->getPathHashCount(), (int)packet->getPathHashSize(), (int)packet->getPathByteLen());
|
||||
}
|
||||
|
||||
return buildPacketMessage(
|
||||
origin, origin_id, timestamp,
|
||||
is_tx ? "tx" : "rx",
|
||||
time_str, date_str,
|
||||
packet->path_len + packet->payload_len + 2,
|
||||
packet->getRawLength(),
|
||||
packet_type, route_str,
|
||||
packet->payload_len,
|
||||
raw_hex,
|
||||
@@ -293,11 +293,11 @@ int MQTTMessageBuilder::buildPacketJSONFromRaw(
|
||||
packet->calculatePacketHash(packet_hash);
|
||||
bytesToHex(packet_hash, MAX_HASH_SIZE, hash_str, sizeof(hash_str));
|
||||
|
||||
// Build path string for direct packets
|
||||
// Build path string for direct packets (multibyte-path: show hash count, hash size, byte length)
|
||||
char path_str[128] = "";
|
||||
if (packet->isRouteDirect() && packet->path_len > 0) {
|
||||
// Simplified path representation
|
||||
snprintf(path_str, sizeof(path_str), "path_len_%d", packet->path_len);
|
||||
snprintf(path_str, sizeof(path_str), "path_%dx%d_%db",
|
||||
(int)packet->getPathHashCount(), (int)packet->getPathHashSize(), (int)packet->getPathByteLen());
|
||||
}
|
||||
|
||||
return buildPacketMessage(
|
||||
|
||||
Reference in New Issue
Block a user