From 36ffffb89b1dfeca0163b6ecd9c46239aca6465e Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 13:27:22 +0100 Subject: sync messages are bytes outside the session SyncPayload is now an opaque byte container in transport. SyncSession::generate returns the encoded payload, state::decode_sync(&payload) decodes it off the document lock (as before), and receive takes the decoded message, which is a type only the session can open. transport/mod.rs no longer imports Automerge. --- src/transport/mod.rs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'src/transport/mod.rs') diff --git a/src/transport/mod.rs b/src/transport/mod.rs index c10e0d8..cef31ff 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -1,6 +1,5 @@ use anyhow::Result; use async_trait::async_trait; -use automerge::sync::Message; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::boxed::Box; @@ -681,23 +680,13 @@ impl DeltaSpec { } } -/// An Automerge sync message in Automerge's own encoding. Decoded only where it is -/// applied (`decode`), after the sender proved to be a member and off the consumer: a -/// large message from anyone else costs nothing but its bytes. +/// A sync message as the document's engine encodes it (`state::session`): bytes to the +/// transports. Decoded only where it is applied (`state::decode_sync`), after the sender +/// proved to be a member and off the consumer: a large message from anyone else costs +/// nothing but its bytes. #[derive(Clone)] pub(crate) struct SyncPayload(pub(crate) bytes::Bytes); -impl SyncPayload { - pub(crate) fn encode(message: Message) -> Self { - Self(message.encode().into()) - } - - pub(crate) fn decode(&self) -> Result { - Message::decode(&self.0) - .map_err(|error| anyhow::anyhow!("Automerge decode failed: {error:?}")) - } -} - /// Sizes instead of contents: logged messages stay short. impl std::fmt::Debug for SyncPayload { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { -- cgit v1.3.1