Struct automerge::sync::Message

source ·
pub struct Message {
    pub heads: Vec<ChangeHash>,
    pub need: Vec<ChangeHash>,
    pub have: Vec<Have>,
    pub changes: ChunkList,
    pub supported_capabilities: Option<Vec<Capability>>,
    pub version: MessageVersion,
}
Expand description

The sync message to be sent.

Notes about encoding

There are two versions of the sync message, V1 and V2. The V1 message is the original message which automerge shipped with and V2 is an extension which allows for encoding the changes as either a list of changes or as a compressed document format. This makes syncing up for the first time faster.

Encoding this in a backwards compatible way is a bit tricky. The wire format of the v1 message didn’t allow for any forwards compatible changes. In order to accomodate this the first message a peer sends is a V1 message with a length previxed Vec<Capability> appended to it. For old implementations this appended data is just ignored but new implementations read it and store the advertised capabilities on the sync state. This allows new implementations to discover if the remote peer supports the V2 message format (the Capability::MessageV2 capability) and if so send a V2 message.

Fields§

§heads: Vec<ChangeHash>

The heads of the sender.

§need: Vec<ChangeHash>

The hashes of any changes that are being explicitly requested from the recipient.

§have: Vec<Have>

A summary of the changes that the sender already has.

§changes: ChunkList

The changes for the recipient to apply.

This is a Vec of bytes which should be passed to Automerge::load_incremental. The reason it is a Vec<Vec<u8>> and not a Vec<u8> is that the V1 message format is a sequence of change chunks, each of which is length delimited. The V2 message format is a single length delimited chunk but we nest it inside a Vec for backwards compatibility.

§supported_capabilities: Option<Vec<Capability>>

The capabilities the sender supports

§version: MessageVersion

What version to encode this message as

Implementations§

source§

impl Message

source

pub fn decode(input: &[u8]) -> Result<Self, ReadMessageError>

source

pub fn encode(self) -> Vec<u8>

Trait Implementations§

source§

impl Clone for Message

source§

fn clone(&self) -> Message

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Message

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq<Message> for Message

source§

fn eq(&self, other: &Message) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Message

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more