diff options
| author | tv <tv@krebsco.de> | 2026-10-31 18:07:07 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-31 18:07:07 +0100 |
| commit | 4a9f4507f3161791f80c8c25a6f0e9ccd3649c2c (patch) | |
| tree | 7de1e540b12879364105e275feb07a5b129251a5 /src/document/mod.rs | |
| parent | 4ea5867047d869ea6a33efd6a47a2adc2340114e (diff) | |
move all automerge references to document
Diffstat (limited to 'src/document/mod.rs')
| -rw-r--r-- | src/document/mod.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/document/mod.rs b/src/document/mod.rs index 1612145..2230e47 100644 --- a/src/document/mod.rs +++ b/src/document/mod.rs @@ -6,6 +6,30 @@ /// Only `document` and `remake` use Automerge itself (`architecture.md`, The document). pub(crate) use automerge::{ActorId, AutoCommit as Document, Change, ChangeHash}; +/// The whole document as bytes, as the engine saves it: a backup, the document +/// file's full save, the size a joining node downloads. +pub(crate) fn save(doc: &mut Document) -> Vec<u8> { + doc.save() +} + +/// The changes after `since` as bytes that, appended to a save, load with it (the +/// document file's appends). +pub(crate) fn save_since(doc: &mut Document, since: &[ChangeHash]) -> Vec<u8> { + doc.save_after(since) +} + +/// A saved document (`save`), loaded to write to under a writer ID of its own: one ID +/// must never write in two places, and a save may be loaded on several nodes, or again +/// after the node that saved it wrote on. +pub(crate) fn load(bytes: &[u8]) -> anyhow::Result<Document> { + Ok(Document::load(bytes)?.with_actor(ActorId::random())) +} + +/// The actor (writer ID) `doc` writes under. +pub(crate) fn actor(doc: &Document) -> ActorId { + doc.get_actor().clone() +} + pub(crate) mod changes; pub(crate) mod file; pub(crate) mod lock; |
