Move DecodedServiceEnvelope into its own file (#5715)

pull/5714/head
Eric Severance 2025-01-01 16:40:14 -08:00 zatwierdzone przez GitHub
rodzic 9abd07bb05
commit c2c06ed0ad
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
3 zmienionych plików z 37 dodań i 18 usunięć

Wyświetl plik

@ -2,6 +2,7 @@
#include "MeshService.h"
#include "NodeDB.h"
#include "PowerFSM.h"
#include "ServiceEnvelope.h"
#include "configuration.h"
#include "main.h"
#include "mesh/Channels.h"
@ -25,7 +26,6 @@
#endif
#include <Throttle.h>
#include <assert.h>
#include <pb_decode.h>
#include <utility>
#include <IPAddress.h>
@ -47,23 +47,6 @@ static uint8_t bytes[meshtastic_MqttClientProxyMessage_size + 30]; // 12 for cha
static bool isMqttServerAddressPrivate = false;
// meshtastic_ServiceEnvelope that automatically releases dynamically allocated memory when it goes out of scope.
struct DecodedServiceEnvelope : public meshtastic_ServiceEnvelope {
DecodedServiceEnvelope() = delete;
DecodedServiceEnvelope(const uint8_t *payload, size_t length)
: meshtastic_ServiceEnvelope(meshtastic_ServiceEnvelope_init_default),
validDecode(pb_decode_from_bytes(payload, length, &meshtastic_ServiceEnvelope_msg, this))
{
}
~DecodedServiceEnvelope()
{
if (validDecode)
pb_release(&meshtastic_ServiceEnvelope_msg, this);
}
// Clients must check that this is true before using.
const bool validDecode;
};
inline void onReceiveProto(char *topic, byte *payload, size_t length)
{
const DecodedServiceEnvelope e(payload, length);

Wyświetl plik

@ -0,0 +1,23 @@
#include "ServiceEnvelope.h"
#include "mesh-pb-constants.h"
#include <pb_decode.h>
DecodedServiceEnvelope::DecodedServiceEnvelope(const uint8_t *payload, size_t length)
: meshtastic_ServiceEnvelope(meshtastic_ServiceEnvelope_init_default),
validDecode(pb_decode_from_bytes(payload, length, &meshtastic_ServiceEnvelope_msg, this))
{
}
DecodedServiceEnvelope::DecodedServiceEnvelope(DecodedServiceEnvelope &&other)
: meshtastic_ServiceEnvelope(meshtastic_ServiceEnvelope_init_zero), validDecode(other.validDecode)
{
std::swap(packet, other.packet);
std::swap(channel_id, other.channel_id);
std::swap(gateway_id, other.gateway_id);
}
DecodedServiceEnvelope::~DecodedServiceEnvelope()
{
if (validDecode)
pb_release(&meshtastic_ServiceEnvelope_msg, this);
}

Wyświetl plik

@ -0,0 +1,13 @@
#pragma once
#include "mesh/generated/meshtastic/mqtt.pb.h"
// meshtastic_ServiceEnvelope that automatically releases dynamically allocated memory when it goes out of scope.
struct DecodedServiceEnvelope : public meshtastic_ServiceEnvelope {
DecodedServiceEnvelope(const uint8_t *payload, size_t length);
DecodedServiceEnvelope(DecodedServiceEnvelope &) = delete;
DecodedServiceEnvelope(DecodedServiceEnvelope &&);
~DecodedServiceEnvelope();
// Clients must check that this is true before using.
const bool validDecode;
};