From ab271cfdc219fe274fb1dd8c8b53883c97f43974 Mon Sep 17 00:00:00 2001 From: sevenrats Date: Sat, 12 Oct 2024 05:50:15 -0400 Subject: [PATCH] update to latest rust crate and expose SyncState encode decode Signed-off-by: sevenrats --- rust/Cargo.lock | 6 +++--- rust/Cargo.toml | 2 +- rust/src/lib.rs | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 36aece4..4544b64 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "automerge" -version = "0.5.7" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c059747d9ef133802da22926ea54039de90f85b349a920f16a6d1573da0f2580" +checksum = "b0b670b68c38e4042ea4826415f0f8101428810bce821d215e271966b24abac4" dependencies = [ "flate2", "fxhash", @@ -40,7 +40,7 @@ dependencies = [ name = "automerge" version = "1.0.0-rc1" dependencies = [ - "automerge 0.5.7", + "automerge 0.5.11", "hex", "pyo3", "thiserror", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 4d4ac10..8761bbc 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -10,6 +10,6 @@ crate-type = ["cdylib"] [dependencies] pyo3 = "0.19.0" -automerge = "0.5.7" +automerge = "0.5.11" hex = "^0.4.3" thiserror = "^1.0.16" diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 4d71a5a..158b91c 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -742,6 +742,16 @@ impl PySyncState { pub fn new() -> PySyncState { PySyncState(am::sync::State::new()) } + pub fn encode<'py>(&self, py: Python<'py>) -> &'py PyBytes { + PyBytes::new(py, &self.0.clone().encode()) + } + + #[staticmethod] + pub fn decode(bytes: &[u8]) -> PyResult { + Ok(PySyncState( + am::sync::State::decode(bytes).map_err(|e| PyException::new_err(e.to_string()))?, + )) + } } #[pyclass(name = "Message")]