1use ogn_parser::ServerResponse;
2use pyo3::prelude::*;
3use pythonize::pythonize;
4use rayon::prelude::*;
5
6#[pyfunction]
8fn parse_to_json(s: &str) -> PyResult<Vec<String>> {
9 let lines = s.lines().collect::<Vec<_>>();
10 let json_strings = lines
11 .par_iter()
12 .map(|&aprs_string| {
13 serde_json::to_string(&aprs_string.parse::<ServerResponse>().unwrap()).unwrap()
14 })
15 .collect();
16 Ok(json_strings)
17}
18
19#[pyfunction]
21fn parse(py: Python, s: &str) -> PyResult<Py<PyAny>> {
22 let lines = s.lines().collect::<Vec<_>>();
23 Ok(pythonize(
24 py,
25 &lines
26 .par_iter()
27 .map(|&aprs_string| aprs_string.parse::<ServerResponse>().unwrap())
28 .collect::<Vec<_>>(),
29 )?
30 .into())
31}
32
33#[pymodule(name = "ogn_parser")]
35fn python_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
36 m.add_function(wrap_pyfunction!(parse_to_json, m)?)?;
37 m.add_function(wrap_pyfunction!(parse, m)?)?;
38 Ok(())
39}