Skip to main content

flow_abi/
lib.rs

1//! The value encoding at the host boundary (`docs/runtime/spec/abi.md`).
2//!
3//! Every Flow data value that crosses to a Tool process, and every value
4//! history stores, is written in one binary encoding, and both sides know the
5//! declared type, so the bytes carry no names and no type tags. Every data
6//! value also has a JSON form, the conversion at the edges: `json.encode`
7//! and `json.decode`, a run's input and output, a supplied reply, an
8//! adapter's exchange, and what a viewer shows. This crate is both:
9//!
10//! - [`encode_bytes`] and [`write_value`] write a value at its type in the
11//!   binary encoding, and [`decode_bytes`] and [`read_value`] read the one
12//!   value its bytes encode, refusing any other bytes, with where and why
13//!   ([`DecodeError`]), in a [`Mode`] and within [`Limits`];
14//! - [`primitives`] are the numbers, texts and instants every binary form
15//!   is built from, and the text forms of a few scalars, for a crate that
16//!   writes a form of its own on them, and [`crc32c`] is the check history's
17//!   commits carry;
18//! - [`form`] says what a value of a type is made of, declarations looked up
19//!   and arguments in place, for any walker of values by type, and
20//!   [`write_scalar`] and [`read_scalar`] write and read the [`Scalar`] parts
21//!   history keeps out of its slots;
22//! - [`encode`] writes a value's JSON form, and [`canonical`] gives the one
23//!   text every equal value shares ([`Digest`] hashes it);
24//! - [`decode`] and [`decode_text`] build a value of a declared type from
25//!   JSON by the decoding table;
26//! - [`rebuild_by_name`] rebuilds a value another program made as a value
27//!   of this one's type, its fields and constructors matched by name;
28//! - [`encode_naming_tasks`] writes a value's JSON form where a task is the
29//!   id of the call it is parked on, and [`encode_for_reading`] where bytes
30//!   holding UTF-8 are their text, for a person to read;
31//! - [`flow_types::normal_path`], [`Url`] and [`MediaType`] are the normal forms of std's
32//!   `path.Path`, `url.Url` and `media.MediaType`, which decoding holds a
33//!   value of each to ([`StdForm`]);
34//! - [`schema`] writes a type's JSON Schema;
35//! - [`wire!`] declares a binary message once, as its type, its
36//!   [`wire::Wire`] codec over [`primitives`] and its [`wire::Shape`],
37//!   whose projection is the message's Flow type;
38//! - [`description`] declares the type descriptions' own types that way;
39//!   [`TypeSpec`] is a Tool's description, read and validated in
40//!   first-reach order, which validates a generic call's `CallTypes` too;
41//!   [`call_views`] writes those, and [`write_listing`] and
42//!   [`read_listing`] the `--contract` file;
43//! - [`comparable`] is the bytes two signatures are compared by: an
44//!   implementation fits a declaration when they are equal;
45//! - [`Outcome`] and [`Ack`] are the answers the dispatch seam
46//!   passes, each with its binary form, which the Tool process protocol's
47//!   frames carry;
48//! - [`UnixMillis`] is a time on a host's wall clock, which host notes,
49//!   the daemon and a host's views keep, with the one rule from an offset
50//!   from the epoch, an `Instant` or text into it;
51//! - [`contract`] is a generated contract module as data, and the one
52//!   printer every generator writes it with;
53//! - [`DATA_VERSION`] is the [`DataVersion`] all of this is written in,
54//!   and [`Versioned`] is bytes written in one.
55//!
56//! # The types it reads
57//!
58//! The encoding is a function of declarations, not of checking, so this
59//! crate does not depend on the checker. It reads a [`flow_types::Type`] —
60//! the checker's types cut down to what crosses — whose declared records,
61//! enums and host types live in a [`Catalog`] that holds the same
62//! `flow-types` shapes the evaluator builds values with. Whoever holds a checked program builds the
63//! catalog from it once; a history reader or a host needs only the catalog.
64//!
65//! # JSON
66//!
67//! The JSON reader and writer are this crate's own ([`Json`], [`parse`]): numbers
68//! are exact at any size, an object naming a key twice and a lone surrogate
69//! escape are refused, nesting is bounded, and the writer is the canonical
70//! form. No dynamic tree from a general-purpose library stands beside the
71//! type-directed one.
72//!
73//! # Not here
74//!
75//! The Tool process protocol's frames are `flow-tool-protocol`'s, and the
76//! value notation, read and written, is `flow-notation`'s. What a host does with the
77//! protocol's messages — processes, binding, `flow.toml` and adapters — is
78//! the host's, and serving them from native functions is a toolkit's; all of
79//! them are built on this crate.
80
81#![cfg_attr(all(coverage, test), feature(coverage_attribute))]
82
83mod answer;
84mod binary;
85mod bridge;
86mod build;
87mod bytes;
88mod catalog;
89pub mod contract;
90mod crossing;
91mod decode;
92pub mod description;
93mod encode;
94mod error;
95mod form;
96mod json;
97mod limits;
98mod media;
99mod metadata;
100pub mod primitives;
101mod schema;
102mod signature;
103mod time;
104mod unix_millis;
105mod url;
106mod version;
107pub mod wire;
108mod work;
109
110pub use answer::{Ack, NoType, Outcome, OutcomeKind, Untyped};
111pub use binary::{decode_bytes, encode_bytes, read_scalar, read_value, write_scalar, write_value};
112pub use bridge::rebuild_by_name;
113pub use bytes::{Crc32c, crc32c};
114pub use catalog::{Catalog, Exact, Fixing, Params, StdForm, crossable, std_enum};
115pub use crossing::{of_shaped_value, read_shaped, shaped_value, write_shaped};
116pub use decode::{BINDING, CROSSING, INPUT, Mode, REBUILD, REPLY, decodable, decode, decode_text};
117pub use encode::{
118    Digest, canonical, canonical_within, encode, encode_for_reading, encode_naming_tasks,
119};
120pub use error::{DecodeError, DecodeErrorKind, EncodeError, EncodeErrorKind, Place, Step};
121pub use form::{EnumForm, Form, RecordForm, Scalar, form};
122pub use json::{Json, parse};
123pub use limits::Limits;
124pub use media::{MediaType, normal_media_type};
125pub use metadata::{
126    ListedProgram, ListingError, ResultType, TypeSpec, ValidatedTypes, call_bindings, call_views,
127    comparable, read_listing, write_listing,
128};
129pub use schema::{DIALECT, schema};
130pub use signature::{Signature, ToolDecl, parameter_key};
131pub use unix_millis::{Outside, TimeTextError, UnixMillis};
132pub use url::{Url, normal_url};
133pub use version::{DATA_VERSION, DataVersion, Versioned};