Files
microReticulum/src/LXMFMessage.h
T
DeFiDude 6f3c08de93 Add LXMFMessage codec to microReticulum library
Moves the LXMF message packing/unpacking/signing code from Ratdeck
into microReticulum as a shared library module. This enables:
- Native platform LXMF tests (pio test -e native17)
- Cross-implementation fixture validation
- Single source of truth for C++ LXMF wire format

The codec is adapted from Ratdeck's LXMFMessage.h/cpp with Arduino.h
dependency removed (replaced with cstdint for native platform support).

Wire format matches Python LXMF (LXMessage.py) and Rust (lxmf-core):
- Opportunistic: [src:16][sig:64][msgpack(ts, title, content, fields)]
- Direct: [dest:16][src:16][sig:64][msgpack(ts, title, content, fields)]
- Title/content encoded as MsgPack bin (0xC4/0xC5), not str

Note: Ratdeck will be updated to #include <LXMFMessage.h> from the
library (removing its local copy) after this change is pushed.
2026-03-24 15:31:05 -06:00

34 lines
893 B
C++

#pragma once
#include "Bytes.h"
#include "Identity.h"
#include <string>
#include <vector>
#include <cstdint>
enum class LXMFStatus : uint8_t {
DRAFT = 0, QUEUED, SENDING, SENT, DELIVERED, FAILED
};
struct LXMFMessage {
RNS::Bytes sourceHash;
RNS::Bytes destHash;
double timestamp = 0;
std::string content;
std::string title;
RNS::Bytes signature;
LXMFStatus status = LXMFStatus::DRAFT;
bool incoming = false;
bool read = false;
int retries = 0;
unsigned long lastRetryMs = 0;
uint32_t savedCounter = 0;
RNS::Bytes messageId;
static std::vector<uint8_t> packContent(double timestamp, const std::string& content, const std::string& title);
std::vector<uint8_t> packFull(const RNS::Identity& signingIdentity);
static bool unpackFull(const uint8_t* data, size_t len, LXMFMessage& msg);
const char* statusStr() const;
};