forked from foxglove/mcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconformance_reader_async.rs
34 lines (29 loc) · 1.07 KB
/
conformance_reader_async.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#[path = "common/serialization.rs"]
mod serialization;
use serde_json::{json, Value};
use serialization::as_json;
use std::env;
use std::process;
use tokio::fs::File;
use tokio;
#[tokio::main(flavor = "current_thread")]
async fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Please supply an MCAP file as argument");
process::exit(1);
}
let file = File::open(&args[1]).await.expect("couldn't open file");
let mut reader = mcap::tokio::RecordReader::new(file);
let mut json_records: Vec<Value> = vec![];
let mut buf: Vec<u8> = Vec::new();
while let Some(opcode) = reader.next_record(&mut buf).await {
let opcode = opcode.expect("failed to read next record");
if opcode != mcap::records::op::MESSAGE_INDEX {
let parsed = mcap::parse_record(opcode, &buf[..]).expect("failed to parse record");
json_records.push(as_json(&parsed));
}
}
let out = json!({ "records": json_records });
print!("{}", serde_json::to_string_pretty(&out).unwrap());
}