diff options
| author | tv <tv@krebsco.de> | 2026-10-31 13:27:22 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-31 13:27:22 +0100 |
| commit | 7ef7e393fa811eb7dd73d025394d21cadc3a2e3a (patch) | |
| tree | dcdeebb26af7459e837e7a1f33cce600bc369101 /src/transport | |
| parent | 0c5e612550e399c3aad458d5c1d70e5cc4267a15 (diff) | |
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.
Diffstat (limited to 'src/transport')
| -rw-r--r-- | src/transport/mod.rs | 19 |
1 files changed, 4 insertions, 15 deletions
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> { - 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 { |
