diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2023-01-02 14:21:15 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2023-01-02 15:20:14 +0100 |
commit | 56f791159fd86923f1db3e990dbb51d59abef0ae (patch) | |
tree | 6386e9930ef94c17ae84e84e76e8fde4b52bf98d | |
parent | b96c889014ff4c7ed50058648c63710126805908 (diff) |
Add utility to write packet to byte vec
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | mqtt-tester/src/main.rs | 1 | ||||
-rw-r--r-- | mqtt-tester/src/util.rs | 22 |
2 files changed, 23 insertions, 0 deletions
diff --git a/mqtt-tester/src/main.rs b/mqtt-tester/src/main.rs index aec2d08..9562931 100644 --- a/mqtt-tester/src/main.rs +++ b/mqtt-tester/src/main.rs @@ -7,6 +7,7 @@ mod client_report; mod command; mod report; +mod util; use std::{path::PathBuf, process::exit}; diff --git a/mqtt-tester/src/util.rs b/mqtt-tester/src/util.rs new file mode 100644 index 0000000..b4e19ec --- /dev/null +++ b/mqtt-tester/src/util.rs @@ -0,0 +1,22 @@ +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// + +use std::pin::Pin; + +use miette::IntoDiagnostic; +use mqtt_format::v3::packet::MPacket; + +pub async fn packet_to_vec<'m>(mpacket: MPacket<'m>) -> miette::Result<Vec<u8>> { + let mut buf = vec![]; + { + let mut cursor = futures::io::Cursor::new(&mut buf); + mpacket + .write_to(Pin::new(&mut cursor)) + .await + .into_diagnostic()?; + } + Ok(buf) +} |