Skip to content

Commit

Permalink
Add feature flag to set max payload size
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethKnudsen97 committed Jun 27, 2024
1 parent 3b18596 commit 08a6880
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
13 changes: 11 additions & 2 deletions mqttrust_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,17 @@ dns-lookup = "1.0.3"
env_logger = "0.9.0"

[features]
default = []
default = ["max_payload_size_4096"]
max_payload_size_2048 = []
max_payload_size_4096 = []
max_payload_size_8192 = []


std = []

defmt-impl = ["defmt", "mqttrust/defmt-impl", "heapless/defmt-impl", "fugit/defmt"]
defmt-impl = [
"defmt",
"mqttrust/defmt-impl",
"heapless/defmt-impl",
"fugit/defmt",
]
3 changes: 2 additions & 1 deletion mqttrust_core/src/eventloop.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::max_payload::MAX_PAYLOAD_SIZE;
use crate::options::Broker;
use crate::packet::SerializedPacket;
use crate::state::{MqttConnectionStatus, MqttState};
Expand Down Expand Up @@ -417,7 +418,7 @@ impl<S> NetworkHandle<S> {
#[derive(Debug)]
struct PacketBuffer {
range: RangeTo<usize>,
buffer: Vec<u8, 4096>,
buffer: Vec<u8, { MAX_PAYLOAD_SIZE }>,
}

impl PacketBuffer {
Expand Down
4 changes: 3 additions & 1 deletion mqttrust_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub(crate) mod fmt;

mod client;
mod eventloop;
mod max_payload;
mod options;
mod packet;
mod state;
Expand All @@ -18,6 +19,7 @@ pub use client::Client;
use core::convert::TryFrom;
pub use eventloop::EventLoop;
use heapless::{String, Vec};
use max_payload::MAX_PAYLOAD_SIZE;
pub use mqttrust::encoding::v4::{Pid, Publish, QoS, QosPid, Suback};
pub use mqttrust::*;
pub use options::{Broker, MqttOptions};
Expand All @@ -30,7 +32,7 @@ pub struct PublishNotification {
pub qospid: QoS,
pub retain: bool,
pub topic_name: String<256>,
pub payload: Vec<u8, 4096>,
pub payload: Vec<u8, MAX_PAYLOAD_SIZE>,
}

/// Includes incoming packets from the network and other interesting events
Expand Down
15 changes: 15 additions & 0 deletions mqttrust_core/src/max_payload.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#[cfg(not(any(
feature = "max_payload_size_2048",
feature = "max_payload_size_4096",
feature = "max_payload_size_8192"
)))]
pub const MAX_PAYLOAD_SIZE: usize = 4096;

#[cfg(feature = "max_payload_size_2048")]
pub const MAX_PAYLOAD_SIZE: usize = 2048;

#[cfg(feature = "max_payload_size_4096")]
pub const MAX_PAYLOAD_SIZE: usize = 4096;

#[cfg(feature = "max_payload_size_8192")]
pub const MAX_PAYLOAD_SIZE: usize = 8192;

0 comments on commit 08a6880

Please sign in to comment.