diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2025-06-27 19:57:00 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2025-06-27 21:46:51 +0100 |
commit | 00b2e9bb80e7fcd310fa0b0a719726665d2fcbe2 (patch) | |
tree | 3a303c5b05f784b08d9799124e0e64811fb49948 /src/main.rs | |
parent | b440529967d5585d95a33c8f14c2436d54908db5 (diff) | |
download | mqttr-00b2e9bb80e7fcd310fa0b0a719726665d2fcbe2.tar.gz mqttr-00b2e9bb80e7fcd310fa0b0a719726665d2fcbe2.tar.xz mqttr-00b2e9bb80e7fcd310fa0b0a719726665d2fcbe2.zip |
Pass packet metadata as arguments
DUP, QoS, RETAIN and the packet identifier
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index cf451dd..bc59b0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,12 +14,17 @@ mod config; const PROGRAM: &str = "mqttr"; async fn run(program: &[String], message: &Publish) -> anyhow::Result<()> { - // TODO: Set environment variables - let mut proc = Command::new(&program[0]) + let mut command = Command::new(&program[0]); + command .args(&program[1..]) .arg(&message.topic) - .stdin(Stdio::piped()) - .spawn()?; + .arg(format!("{}", message.dup as u8)) + .arg(format!("{}", message.qos as u8)) + .arg(format!("{}", message.retain as u8)); + if message.qos == QoS::AtLeastOnce || message.qos == QoS::ExactlyOnce { + command.arg(format!("{}", message.pkid)); + } + let mut proc = command.stdin(Stdio::piped()).spawn()?; let mut stdin = proc.stdin.take().context("No stdin")?; stdin.write(&message.payload).await?; drop(stdin); @@ -88,7 +93,9 @@ async fn main() -> anyhow::Result<()> { let p = p.clone(); tokio::spawn(async move { match timeout(Duration::from_secs(60), run(&program, &p)).await { - Err(_) => eprintln!("error: Execution of {program:?} for message {p:?} timed out"), + Err(_) => eprintln!( + "error: Execution of {program:?} for message {p:?} timed out" + ), Ok(Err(e)) => eprintln!("error: Failed to run {program:?}: {e:?}"), _ => (), } |