mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-10 23:22:05 +00:00
Move DecodedServiceEnvelope into its own file (#5715)
This commit is contained in:
parent
9abd07bb05
commit
c2c06ed0ad
@ -2,6 +2,7 @@
|
|||||||
#include "MeshService.h"
|
#include "MeshService.h"
|
||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
#include "PowerFSM.h"
|
#include "PowerFSM.h"
|
||||||
|
#include "ServiceEnvelope.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "mesh/Channels.h"
|
#include "mesh/Channels.h"
|
||||||
@ -25,7 +26,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <Throttle.h>
|
#include <Throttle.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <pb_decode.h>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <IPAddress.h>
|
#include <IPAddress.h>
|
||||||
@ -47,23 +47,6 @@ static uint8_t bytes[meshtastic_MqttClientProxyMessage_size + 30]; // 12 for cha
|
|||||||
|
|
||||||
static bool isMqttServerAddressPrivate = false;
|
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)
|
inline void onReceiveProto(char *topic, byte *payload, size_t length)
|
||||||
{
|
{
|
||||||
const DecodedServiceEnvelope e(payload, length);
|
const DecodedServiceEnvelope e(payload, length);
|
||||||
|
23
src/mqtt/ServiceEnvelope.cpp
Normal file
23
src/mqtt/ServiceEnvelope.cpp
Normal file
@ -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);
|
||||||
|
}
|
13
src/mqtt/ServiceEnvelope.h
Normal file
13
src/mqtt/ServiceEnvelope.h
Normal file
@ -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;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user