ron_crdt/
lib.rs

1//! This is documentation for the `ron-crdt` crate.
2//!
3//! RON is the Replicated Object Notation, a distributed live data format
4//! by [Victor Grishchenko](https://github.com/gritzko).
5//!
6//! RON is the language in which object states and mutations, as well
7//! as all other parts of the Swarm protocol, are expressed in
8//! Swarm. RON consists (solely!) of a series of UUIDs (128-bit
9//! numbers), but the order of UUIDs matter, and there are many
10//! different kinds of UUIDs, depending on the context.
11//!
12//! UUIDs provide sufficient metadata to object and their mutations to
13//! allow the implementation of CRDTs in a network of peers.
14//!
15//! RON features two different wire formats: text and binary. Both
16//! offer several ways of compression, adding to the complexity. We
17//! will handle compression later, but note here that efficient
18//! compression is what makes RON and Swarm practical. Compression
19//! reduces the metadata overhead.
20//!
21//! One particular combination of four UUIDs makes up an operation
22//! (short: ops) with one UUID each for the type, object, event and
23//! value. Several operations make up the state or mutation of an
24//! object, we call this a frame.
25//!
26//! Special kinds of RON ops are used for protocol handshakes and
27//! frame headers (metadata for frames). These operations have special
28//! meaning, and often omit some of the metadata that is usually
29//! included in an operation (for example, a handshake query does not
30//! have a timestamp).
31
32#![warn(missing_docs)]
33
34extern crate ron_uuid as uuid;
35extern crate smallvec;
36#[macro_use]
37extern crate log;
38#[cfg(test)]
39extern crate simple_logger;
40
41pub mod atom;
42pub mod batch;
43pub mod crdt;
44pub mod frame;
45pub mod heap;
46pub mod op;
47
48pub use uuid::UUID;
49
50pub use crate::atom::Atom;
51pub use crate::batch::Batch;
52pub use crate::crdt::{Set, CRDT, LWW};
53pub use crate::frame::Frame;
54pub use crate::heap::{FrameOrd, Heap};
55pub use crate::op::{Op, Terminator};
56
57fn scan_for_integer<'a>(input: &'a str) -> Option<usize> {
58    input.chars().position(|c| !c.is_ascii_digit() && c != '-' && c != '+')
59}
60
61fn scan_for_float<'a>(input: &'a str) -> Option<usize> {
62    input.chars().position(|c| {
63        !c.is_ascii_digit()
64            && c != 'e'
65            && c != 'E'
66            && c != '.'
67            && c != '-'
68            && c != '+'
69    })
70}
71
72fn scan_for_string<'a>(input: &'a str) -> Option<usize> {
73    let mut escaped = false;
74    for (off, ch) in input.char_indices() {
75        escaped = match (ch, escaped) {
76            ('\'', false) => return Some(off),
77            ('\'', true) => false,
78
79            ('\\', false) => true,
80            ('\\', true) => false,
81
82            ('n', true) => false,
83            ('t', true) => false,
84
85            (_, false) => false,
86            (_, true) => false,
87        };
88    }
89
90    None
91}