Skip to content

Commit 4652485

Browse files
committed
WIP: deserializing events
1 parent eef7977 commit 4652485

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ tokio-tungstenite = { verstion = "0.18.0", features = ["native-tls"] }
1515
url = "2.3.1"
1616
futures-util = "0.3.28"
1717
http = "0.2.9"
18+
chrono = { version = "0.4.24", features = ["serde"] }
19+
serde_json = "1.0.96"

examples/events.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
use chrono::serde::ts_milliseconds_option;
2+
use chrono::{DateTime, Utc};
13
use clap::Parser;
24
use futures_util::{SinkExt, StreamExt};
5+
use serde::{Deserialize, Serialize};
36
use tokio_tungstenite::{connect_async, tungstenite::protocol::Message};
47
use webex::{self};
58

9+
#[allow(dead_code)]
10+
#[derive(Deserialize, Default, Debug)]
11+
#[serde(rename_all = "camelCase")]
12+
pub struct Event {
13+
pub id: Option<String>,
14+
//pub data: Option<String>,
15+
pub filter_message: Option<bool>,
16+
//pub headers: Option<String>,
17+
pub sequence_number: Option<u32>,
18+
#[serde(with = "ts_milliseconds_option")]
19+
pub timestamp: Option<DateTime<Utc>>,
20+
pub tracking_id: Option<String>,
21+
}
22+
623
#[derive(Parser, Debug)]
724
#[command(author, version, about, long_about = None)]
825
struct Args {
@@ -60,7 +77,12 @@ async fn main() {
6077
Message::Ping(data) => {
6178
let _ = ws_stream.send(Message::Pong(data)).await;
6279
}
63-
Message::Binary(_) => println!("{}", message),
80+
Message::Binary(data) => {
81+
let e = serde_json::from_str::<Event>(
82+
&String::from_utf8(data).expect("Error decoding UT8"),
83+
);
84+
println!("{:#?}", e);
85+
}
6486
_ => (),
6587
}
6688
}

0 commit comments

Comments
 (0)