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 links_operations;
47mod protocols;
48mod remote_links;
49mod server;
50
51pub use archive::{export_store, export_store_file, import_store, import_store_file};
52pub use client::LinksClient;
53pub use error::{ProtocolError, ProtocolResult};
54pub use links_notation::binary::packet;
55pub use links_notation::binary::{
56 decode_document, encode_document, encode_document_with_limits, format_document, format_link,
57 format_reference, parse_document, ArityRange, BinaryError, BinaryLinoOptions, DecodeLimits,
58 LinksPacket, LinoDocument, Reference, Section,
59};
60pub use links_operations::LinksOperation;
61pub use protocols::{
62 is_binary_start, read_any_document, BinaryLinoProtocol, LinoConnection, LinoProtocol,
63 MessageFormat, ProtocolLimits, TextLinoProtocol, DEFAULT_MAX_TEXT_BYTES,
64};
65pub use remote_links::RemoteLinks;
66pub use server::{
67 error_document, error_message, execute_request, AcceptedProtocols, LinksServer, ServerOptions,
68 ShutdownHandle,
69};