am_sync_encode: Generate a sync message

View source: R/sync.R

am_sync_encodeR Documentation

Generate a sync message

Description

Generates a synchronization message to send to a peer. This message contains the changes that the peer needs to bring their document up to date with yours.

Usage

am_sync_encode(doc, sync_state)

Arguments

doc

An Automerge document

sync_state

A sync state object (created with am_sync_state_new())

Details

If the function returns NULL, it means there are no more messages to send (synchronization is complete from this side).

Value

A raw vector containing the encoded sync message, or NULL if no message needs to be sent.

Examples

doc <- am_create()
sync_state <- am_sync_state_new()

# Generate first sync message
msg <- am_sync_encode(doc, sync_state)
if (!is.null(msg)) {
  # Send msg to peer...
}

am_close(doc)


automerge documentation built on Feb. 5, 2026, 5:08 p.m.