flow-abi 0.1.0-rc.5

The host boundary's value encoding: the binary encoding and the JSON form, the canonical form and its hash, JSON Schemas, Tool signatures, and the answers a Tool call passes.
Documentation
//! The value encoding at the host boundary (`docs/runtime/spec/abi.md`).
//!
//! Every Flow data value that crosses to a Tool process, and every value
//! history stores, is written in one binary encoding, and both sides know the
//! declared type, so the bytes carry no names and no type tags. Every data
//! value also has a JSON form, the conversion at the edges: `json.encode`
//! and `json.decode`, a run's input and output, a supplied reply, an
//! adapter's exchange, and what a viewer shows. This crate is both:
//!
//! - [`encode_bytes`] and [`write_value`] write a value at its type in the
//!   binary encoding, and [`decode_bytes`] and [`read_value`] read the one
//!   value its bytes encode, refusing any other bytes, with where and why
//!   ([`DecodeError`]), in a [`Mode`] and within [`Limits`];
//! - [`primitives`] are the numbers, texts and instants every binary form
//!   is built from, and the text forms of a few scalars, for a crate that
//!   writes a form of its own on them, and [`crc32c`] is the check history's
//!   commits carry;
//! - [`form`] says what a value of a type is made of, declarations looked up
//!   and arguments in place, for any walker of values by type, and
//!   [`write_scalar`] and [`read_scalar`] write and read the [`Scalar`] parts
//!   history keeps out of its slots;
//! - [`encode`] writes a value's JSON form, and [`canonical`] gives the one
//!   text every equal value shares ([`Digest`] hashes it);
//! - [`decode`] and [`decode_text`] build a value of a declared type from
//!   JSON by the decoding table;
//! - [`rebuild_by_name`] rebuilds a value another program made as a value
//!   of this one's type, its fields and constructors matched by name;
//! - [`encode_naming_tasks`] writes a value's JSON form where a task is the
//!   id of the call it is parked on, and [`encode_for_reading`] where bytes
//!   holding UTF-8 are their text, for a person to read;
//! - [`flow_types::normal_path`], [`Url`] and [`MediaType`] are the normal forms of std's
//!   `path.Path`, `url.Url` and `media.MediaType`, which decoding holds a
//!   value of each to ([`StdForm`]);
//! - [`schema`] writes a type's JSON Schema;
//! - [`wire!`] declares a binary message once, as its type, its
//!   [`wire::Wire`] codec over [`primitives`] and its [`wire::Shape`],
//!   whose projection is the message's Flow type;
//! - [`description`] declares the type descriptions' own types that way;
//!   [`TypeSpec`] is a Tool's description, read and validated in
//!   first-reach order, which validates a generic call's `CallTypes` too;
//!   [`call_views`] writes those, and [`write_listing`] and
//!   [`read_listing`] the `--contract` file;
//! - [`comparable`] is the bytes two signatures are compared by: an
//!   implementation fits a declaration when they are equal;
//! - [`Outcome`] and [`Ack`] are the answers the dispatch seam
//!   passes, each with its binary form, which the Tool process protocol's
//!   frames carry;
//! - [`UnixMillis`] is a time on a host's wall clock, which host notes,
//!   the daemon and a host's views keep, with the one rule from an offset
//!   from the epoch, an `Instant` or text into it;
//! - [`contract`] is a generated contract module as data, and the one
//!   printer every generator writes it with;
//! - [`DATA_VERSION`] is the [`DataVersion`] all of this is written in,
//!   and [`Versioned`] is bytes written in one.
//!
//! # The types it reads
//!
//! The encoding is a function of declarations, not of checking, so this
//! crate does not depend on the checker. It reads a [`flow_types::Type`] —
//! the checker's types cut down to what crosses — whose declared records,
//! enums and host types live in a [`Catalog`] that holds the same
//! `flow-types` shapes the evaluator builds values with. Whoever holds a checked program builds the
//! catalog from it once; a history reader or a host needs only the catalog.
//!
//! # JSON
//!
//! The JSON reader and writer are this crate's own ([`Json`], [`parse`]): numbers
//! are exact at any size, an object naming a key twice and a lone surrogate
//! escape are refused, nesting is bounded, and the writer is the canonical
//! form. No dynamic tree from a general-purpose library stands beside the
//! type-directed one.
//!
//! # Not here
//!
//! The Tool process protocol's frames are `flow-tool-protocol`'s, and the
//! value notation, read and written, is `flow-notation`'s. What a host does with the
//! protocol's messages — processes, binding, `flow.toml` and adapters — is
//! the host's, and serving them from native functions is a toolkit's; all of
//! them are built on this crate.

#![cfg_attr(all(coverage, test), feature(coverage_attribute))]

mod answer;
mod binary;
mod bridge;
mod build;
mod bytes;
mod catalog;
pub mod contract;
mod crossing;
mod decode;
pub mod description;
mod encode;
mod error;
mod form;
mod json;
mod limits;
mod media;
mod metadata;
pub mod primitives;
mod schema;
mod signature;
mod time;
mod unix_millis;
mod url;
mod version;
pub mod wire;
mod work;

pub use answer::{Ack, NoType, Outcome, OutcomeKind, Untyped};
pub use binary::{decode_bytes, encode_bytes, read_scalar, read_value, write_scalar, write_value};
pub use bridge::rebuild_by_name;
pub use bytes::{Crc32c, crc32c};
pub use catalog::{Catalog, Exact, Fixing, Params, StdForm, crossable, std_enum};
pub use crossing::{of_shaped_value, read_shaped, shaped_value, write_shaped};
pub use decode::{BINDING, CROSSING, INPUT, Mode, REBUILD, REPLY, decodable, decode, decode_text};
pub use encode::{
    Digest, canonical, canonical_within, encode, encode_for_reading, encode_naming_tasks,
};
pub use error::{DecodeError, DecodeErrorKind, EncodeError, EncodeErrorKind, Place, Step};
pub use form::{EnumForm, Form, RecordForm, Scalar, form};
pub use json::{Json, parse};
pub use limits::Limits;
pub use media::{MediaType, normal_media_type};
pub use metadata::{
    ListedProgram, ListingError, ResultType, TypeSpec, ValidatedTypes, call_bindings, call_views,
    comparable, read_listing, write_listing,
};
pub use schema::{DIALECT, schema};
pub use signature::{Signature, ToolDecl, parameter_key};
pub use unix_millis::{Outside, TimeTextError, UnixMillis};
pub use url::{Url, normal_url};
pub use version::{DATA_VERSION, DataVersion, Versioned};