From 8709c7fdb9d18e30e6bb776f536aa230389fa527 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sun, 18 Oct 2026 18:52:48 +0100 Subject: Bytes in a record field (Pure 027's 4b-1): body: bytes (= "..." its default's bytes), x.body.bytes its length (LEN), a text going there only as bytes(t); no list keyed by bytes or by a list; examples/documents.aup: keyed byte documents as a keyed list of records, each edit checked against the revision it was made on; documents_model: random shows and edits (stale revisions, past the end, any bytes, up to 5,000 at once) against a model, in memory and on a store restarting six times (half of the runs in bursts), four seeds alike (1,280 steps); four diagnostics --- examples/documents.aup | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 examples/documents.aup (limited to 'examples') diff --git a/examples/documents.aup b/examples/documents.aup new file mode 100644 index 0000000..4671464 --- /dev/null +++ b/examples/documents.aup @@ -0,0 +1,39 @@ +# Revision-checked byte edits of keyed documents. A document is an item of a +# keyed list; an edit names the revision it was made against and commits only +# if that is still the document's (0 for one not there yet), and a failed +# event leaves everything as it was. +record Doc { + id: text + body: bytes + revision: i64 +} +state docs: list of Doc by id + +input show = message { + id: text +} +input edit = message { + id: text + base: i64 + start: u32 + remove: u32 + insert: bytes +} + +on show { + reply docs[show.id].body +} + +on edit { + if docs.has(edit.id) { + let d = docs[edit.id] + require d.revision == edit.base + require edit.start + edit.remove <= d.body.bytes + docs[edit.id].body = d.body[0 .. edit.start] + edit.insert + d.body[edit.start + edit.remove .. d.body.bytes] + docs[edit.id].revision = d.revision + 1 + } else { + require edit.base == 0 && edit.start == 0 && edit.remove == 0 + docs.add(Doc { id: edit.id, body: edit.insert, revision: 1 }) + } + reply edit.insert +} -- cgit v1.2.3