diff --git a/Cargo.lock b/Cargo.lock index 944aed91..ea1b6178 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5329,6 +5329,7 @@ dependencies = [ "indexmap", "loro", "p2panda-core", + "postcard", "rand 0.10.1", "reflection-node", "serde", diff --git a/reflection-doc/Cargo.toml b/reflection-doc/Cargo.toml index 6a1ec204..c54f520a 100644 --- a/reflection-doc/Cargo.toml +++ b/reflection-doc/Cargo.toml @@ -15,6 +15,7 @@ hex = "0.4.3" indexmap = "2.13.0" loro = "1.13.9" p2panda-core = "0.7.1" +postcard = { version = "1.1.3", features = ["alloc"] } rand = "0.10.1" reflection-node = { path = "../reflection-node" } serde = { version = "1.0.228", features = ["derive"] } diff --git a/reflection-doc/src/document.rs b/reflection-doc/src/document.rs index 57262d33..0477e4dc 100644 --- a/reflection-doc/src/document.rs +++ b/reflection-doc/src/document.rs @@ -8,7 +8,6 @@ use glib::subclass::{Signal, prelude::*}; use glib::{Properties, clone}; pub use hex::FromHexError; use loro::{ExportMode, LoroDoc, LoroText, event::Diff}; -use p2panda_core::cbor::{decode_cbor, encode_cbor}; use p2panda_core::{self, Topic}; use reflection_node::{TopicStream, TopicSubscription, TopicSubscriptionError}; use tracing::error; @@ -98,14 +97,9 @@ impl DocumentId { } #[derive(Debug, serde::Serialize, serde::Deserialize)] -#[serde(tag = "t", content = "d")] enum EphemeralData { - #[serde(rename = "cursor")] Cursor { - #[serde(rename = "i")] insert_cursor: Option, - - #[serde(rename = "s")] selection_bound: Option, }, } @@ -290,17 +284,17 @@ mod imp { *self.insert_cursor.write().unwrap() = insert_cursor; if send { - self.brodcast_ephemeral(); + self.broadcast_ephemeral(); } } - pub fn brodcast_ephemeral(&self) { + pub fn broadcast_ephemeral(&self) { let cursor_data = EphemeralData::Cursor { insert_cursor: self.insert_cursor.read().unwrap().clone(), selection_bound: self.selection_bound.read().unwrap().clone(), }; - let cursor_bytes = match encode_cbor(&cursor_data) { + let cursor_bytes = match postcard::to_allocvec(&cursor_data) { Ok(data) => data, Err(error) => { error!("Failed to serialize cursor: {}", error); @@ -943,7 +937,7 @@ impl TopicSubscription for DocumentHandle { let author = document.authors().add(VerifyingKey(author)); author.set_online(true); // When a new author joins we need to send ephemeral messages again - document.imp().brodcast_ephemeral(); + document.imp().broadcast_ephemeral(); }); } } @@ -967,7 +961,7 @@ impl TopicSubscription for DocumentHandle { ) { if let Some(document) = self.0.upgrade() { document.main_context().invoke(move || { - if let Ok(data) = decode_cbor(&data[..]) + if let Ok(data) = postcard::from_bytes(&data[..]) && let Some(author) = document.authors().author(&VerifyingKey(author)) { document