Struct optra::Engine
[−]
[src]
pub struct Engine { // some fields omitted }
Process file change operations in such a way that they can be synchronized across sites
The engine keeps track of all transactions that have occurred so far, and makes sure that any operations that happen locally or remotely will result in a consistent file on every site.
To use, simply pass through any local edits via process_diffs()
(if they are recorded in a Diff
)
or process_transaction()
(If the operations are already stored in a TransactionSequence
) and pass any remote edits received into integrate_remote()
.
See the module level documentation for an example.
Methods
impl Engine
[src]
fn new(site_id: u32) -> Engine
Creates a new engine for the given site id. The id should be unique across all clients, and probably generated by the server
fn process_diffs(&mut self, diff: Diff, stamper: &mut TimeStamper) -> (TransactionSequence, BTreeMap<u32, (u32, u32)>)
Convert the diffs we got from analyzing a file into a TransactionSequence we can send to another site for synchronization.
fn integrate_remote(&mut self, remote_sequence: &mut TransactionSequence, lookup: &BTreeMap<u32, (u32, u32)>, stamper: &mut TimeStamper) -> Result<(), OTError>
Integrates the sequence of operations given by remote_sequence
into the local history. The ordering
properties of the local history will be maintained, and a sequence of operations that
can be applied to the local state will be returned.
fn process_transaction(&mut self, outgoing_sequence: &mut TransactionSequence)
Processes a series of operations prior to being sent out to remote sites. The operations must have been performed on the data after every operation in the local history, but no others. The operations in the transaction must also be effect order, with the inserts preceding the deletes.
fn get_operations_since(&self, remote_state: Option<(u32, u32)>, stamper: &TimeStamper) -> Result<TransactionSequence, OTError>
Get all the operations since, but not including the given state
fn compress_to<W: Write>(&self, writer: &mut W) -> Result<()>
Compress this engine and write to writer
. The output can then be expanded
back into an equivilent Engine using expand_from()
fn expand_from<R: Read>(reader: &mut R, site_id: u32) -> Result<Engine>
Expand this engine from previously compressed data in reader
. The data in reader
should have been written using compress_to()
Trait Implementations
impl Clone for Engine
[src]
fn clone(&self) -> Engine
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more