1use pyo3::prelude::*;
2
3#[pymodule]
4mod aoe2rec_py {
5 use pyo3::{pyclass, pyfunction, pymethods, Bound, PyAny, PyResult, Python};
6 use pythonize::pythonize;
7
8 #[pyfunction]
9 fn parse_rec(py: Python<'_>, data: Vec<u8>) -> PyResult<Bound<'_, PyAny>> {
10 let rec = aoe2rec::Savegame::from_bytes(data.try_into().unwrap()).unwrap();
11 let pyrec = pythonize(py, &rec).unwrap();
12 Ok(pyrec)
13 }
14
15 #[pyclass]
16 struct Savegame(aoe2rec::Savegame);
17 #[pymethods]
18 impl Savegame {
19 #[new]
20 fn from_bytes(data: Vec<u8>) -> PyResult<Self> {
21 let savegame = aoe2rec::Savegame::from_bytes(data.try_into().unwrap()).unwrap();
22 Ok(Savegame(savegame))
23 }
24 }
25}