link_cli/protocol/mod.rs
1//! LiNo substitution operations over TCP/IP (issue #105).
2//!
3//! Two interchangeable protocols carry LiNo documents between a client and a
4//! server:
5//!
6//! - [`TextLinoProtocol`]: UTF-8 LiNo text, each message ended by a line
7//! holding only `.` (SMTP-style dot-stuffing keeps the framing unambiguous).
8//! - [`BinaryLinoProtocol`]: a self-delimiting [`LinksPacket`] of binary links
9//! notation, made of
10//! sections of links that share one reference width (1, 2, 4 or 8 bytes)
11//! and one [arity range](ArityRange). By default every link is a doublet
12//! and the whole packet uses the narrowest width that fits; the options
13//! [external references](BinaryLinoOptions::external_references),
14//! [arity](BinaryLinoOptions::arity) (for example `2..3` or `1..`) and
15//! [packed widths](BinaryLinoOptions::packed_widths) can be switched on
16//! one by one.
17//!
18//! The binary links notation itself (packets, the LiNo mapping, the canonical
19//! text form) comes from [`links_notation::binary`]; this module re-exports
20//! it and adds the transport: message framing, the server, the client and the
21//! store archive.
22//!
23//! Both implement [`LinoProtocol`], so a [`LinoConnection`] or a
24//! [`LinksClient`] switches protocol by swapping one value. A
25//! [`LinksServer`] detects the protocol of every message and answers in kind.
26//!
27//! A request is a substitution query, so it covers create, read, update and
28//! delete; the reply lists the `(before) (after)` changes, exactly like
29//! `clink --changes`. The empty request reads the whole store.
30//!
31//! ```
32//! use link_cli::protocol::{format_document, parse_document, BinaryLinoOptions, BinaryLinoProtocol};
33//!
34//! let document = parse_document("() ((1 1))").unwrap();
35//! let binary = BinaryLinoProtocol::with_options(
36//! BinaryLinoOptions::default().with_external_references(true),
37//! );
38//! let bytes = binary.encode(&document).unwrap();
39//! assert_eq!(binary.decode(&bytes).unwrap(), document);
40//! assert_eq!(format_document(&document), "() ((1 1))");
41//! ```
42
43pub mod archive;
44mod client;
45mod error;
46pub mod ipc;
47pub mod links_operations;
48mod protocols;
49mod remote_links;
50mod remote_triplets;
51mod server;
52mod sessions;
53pub mod triplets_operations;
54
55pub use archive::{export_store, export_store_file, import_store, import_store_file};
56pub use client::LinksClient;
57pub use error::{ProtocolError, ProtocolResult};
58pub use links_notation::binary::packet;
59pub use links_notation::binary::{
60 decode_document, encode_document, encode_document_with_limits, format_document, format_link,
61 format_reference, parse_document, ArityRange, BinaryError, BinaryLinoOptions, DecodeLimits,
62 LinksPacket, LinoDocument, Reference, Section,
63};
64pub use links_operations::{GenericLinksOperation, LinksNotification, LinksOperation};
65pub use protocols::{
66 is_binary_start, read_any_document, BinaryLinoProtocol, LinoConnection, LinoProtocol,
67 MessageFormat, ProtocolLimits, TextLinoProtocol, TimedStream, DEFAULT_MAX_TEXT_BYTES,
68};
69pub use remote_links::RemoteLinks;
70pub use server::{
71 error_document, error_message, execute_request, execute_request_for,
72 parse_document_with_limits, query_document, AcceptedProtocols, LinksServer, Readable,
73 ServerOptions, ShutdownHandle, DEFAULT_MAX_PENDING_NOTIFICATIONS,
74};
75pub use sessions::{Authenticator, LinksSessions, SessionId};
76pub use triplets_operations::{execute_triplets_request, TripletsNotification, TripletsOperation};