Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
[![Matrix](https://img.shields.io/matrix/drogue-iot:matrix.org)](https://matrix.to/#/#drogue-iot:matrix.org)

Rust mappings for APIs of *The Things Network*.

## Parsing Messages on CLI

There is an example application that can be used to test the parsing of TTN
messages:

cargo run --example parse-v3 -- <path-to-message.json>
24 changes: 24 additions & 0 deletions examples/parse-v3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::{env, fs};

use drogue_ttn::v3 as ttn;
use serde_json as json;

fn main() -> Result<(), String> {
// Args
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
return Err(format!("Usage: {} <jsonfile>", args[0]));
}

// Read from file
let buffer = fs::read(&args[1]).unwrap();

let ttn_msg = match json::from_slice::<ttn::Message>(&buffer) {
Ok(msg) => msg,
Err(e) => {
return Err(format!("Uplink message could not be parsed: {}", e));
}
};
println!("Parsed: {:#?}", ttn_msg);
Ok(())
}