Expand description
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_bytesandwrite_valuewrite a value at its type in the binary encoding, anddecode_bytesandread_valueread the one value its bytes encode, refusing any other bytes, with where and why (DecodeError), in aModeand withinLimits;primitivesare 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, andcrc32cis the check history’s commits carry;formsays what a value of a type is made of, declarations looked up and arguments in place, for any walker of values by type, andwrite_scalarandread_scalarwrite and read theScalarparts history keeps out of its slots;encodewrites a value’s JSON form, andcanonicalgives the one text every equal value shares (Digesthashes it);decodeanddecode_textbuild a value of a declared type from JSON by the decoding table;rebuild_by_namerebuilds a value another program made as a value of this one’s type, its fields and constructors matched by name;encode_naming_taskswrites a value’s JSON form where a task is the id of the call it is parked on, andencode_for_readingwhere bytes holding UTF-8 are their text, for a person to read;flow_types::normal_path,UrlandMediaTypeare the normal forms of std’spath.Path,url.Urlandmedia.MediaType, which decoding holds a value of each to (StdForm);schemawrites a type’s JSON Schema;wire!declares a binary message once, as its type, itswire::Wirecodec overprimitivesand itswire::Shape, whose projection is the message’s Flow type;descriptiondeclares the type descriptions’ own types that way;TypeSpecis a Tool’s description, read and validated in first-reach order, which validates a generic call’sCallTypestoo;call_viewswrites those, andwrite_listingandread_listingthe--contractfile;comparableis the bytes two signatures are compared by: an implementation fits a declaration when they are equal;OutcomeandAckare the answers the dispatch seam passes, each with its binary form, which the Tool process protocol’s frames carry;UnixMillisis 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, anInstantor text into it;contractis a generated contract module as data, and the one printer every generator writes it with;DATA_VERSIONis theDataVersionall of this is written in, andVersionedis 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.
Modules§
- contract
- A generated contract module as data, and the one printer that writes it
(
abi.md, Generated contracts). - description
- The type descriptions’ own types (
abi.md, Type descriptions), declared once: each is the bytes a description is written in, through itsWirecodec, and the Flow type history stores one as, throughShape::project. - primitives
- The parts 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: the Tool
process protocol’s frames are written in these, and the value notation
reads
Bytes,InstantandDurationliterals by these text forms. - wire
- Messages declared once:
wire!takes a record or enum definition and gives the type, itsWirecodec and itsShape.
Macros§
- wire
- Declares a record or an enum once: the type itself, its
Wirecodec and itsShape. Doc comments and attributes pass through. - wire_
impl - Gives a record, an enum or a newtype defined elsewhere its
Shapeand itsShapedmapping, from its field list:#[derive(Flow)]expands to it. The type’s parameters come with their positions, and any bounds its definition puts on them in brackets afterwhere; each field, constructor part and constructor field with its Flow name, and each part with the name its value is bound to; and a constructor with its number, which is its position, and whether its payload isEmpty,PositionalorNamed. Fields ofPhantomDataare listed afterphantom, and what the declaration’s text says beside its shape afternotes.
Structs§
- Catalog
- The declarations a set of types names, with the std enums whose values the encoding builds itself.
- Crc32c
- A CRC-32C (Castagnoli) taken over bytes given a piece at a time: the
reflected polynomial
0x82F63B78, starting from all ones and ending with them flipped, socrc32c(b"123456789")is0xE3069283. - Data
Version - A data version: one version for the value encoding, the Tool protocol
and the history format together, written
"major.minor". - Decode
Error - Why decoding refused.
pathandkindarejson.DecodeError’spathandproblem(stdlib.md);problemsays the same for a person. A Tool reply that fails decoding is no answer, and this explains why (abi.md, Decoding). - Digest
- A SHA-256 hash, written
sha256:followed by lowercase hex. - Encode
Error - Why a value could not be encoded at a type, or a type has no schema.
- Enum
Form - An enum type: its shape, and each constructor’s payload types.
- Exact
- A type parameter matches only the same type parameter, as it does between two declarations of one generic signature.
- Fixing
- Each type parameter is fixed to one type of the other catalog wherever
it appears, as a call to a generic declaration fixes it
(
types.md, Generics). - Limits
- How large a decoded value may be.
- Listed
Program - One program’s Tools as the
--contractfile lists them (abi.md, Binding). - Media
Type - A media type in its normal form: the type, subtype and parameter names in
lowercase, and each parameter’s value as written once unquoted. Its text
is
fmt::Display. - Place
- A place inside a value:
json.DecodeError’s path (stdlib.md,json), oneStepat a time from the whole value, which is the empty path. - Record
Form - A record type: its shape, and its fields’ types in declaration order with the record’s arguments in place.
- Result
Type - The concrete result type of one call, for a client that answers it from
outside the call (
abi.md, Type descriptions and Replies from outside a call): the type and the templates it reaches, validated. - Signature
- A Tool declaration’s signature, for a declaration returning
result.Type::Paramcountsgeneric. - Tool
Decl - A Tool declaration, as the host binds it.
- Type
Spec - A Tool’s type description: its roots and the templates they reach, in first-reach order, validated.
- Unix
Millis - A time on a host’s wall clock, in whole milliseconds since the Unix epoch: when a run started or ended, when a held call is asked again, when a daemon started. A host reads it for its own records, and a run never sees it as a value.
- Untyped
- A host’s answer to
typewhen it has no result type to give: why, for a program to branch on, and what it says, for a person. - Url
- A URI by RFC 3986 in its normal form. Its text is
fmt::Display. - Validated
Types - A concrete generic call’s description after complete validation.
- Versioned
- Bytes written in a data version: the version, then what follows, which only a reader of that version reads.
Enums§
- Ack
- What a host did with a
reply: the three results every route that offers an answer returns (history.md, Open calls). - Decode
Error Kind - Which refusal decoding made: the cases of
json.Problem(stdlib.md). - Encode
Error Kind - Which refusal encoding made.
- Form
- What a value of a type is made of.
- Json
- A JSON value.
- Listing
Error - Why a
--contractfile lists nothing. - Mode
- What is being decoded, which decides what a field the type does not
declare means and which types decoding may build (
Mode::settings). - NoType
- Why a host has no result type to give for a call a
typeasks about (abi.md, Replies from outside a call). - Outcome
- A reply’s answer: a number and what follows it (
errors.md, Tool problems, says what each claims). - Outcome
Kind - Which outcome one is.
- Outside
- Which end of
UnixMillis’s range a time falls beyond. - Scalar
- The types written as their encoding and nothing more, never in a slot of
their own (
trace.md, Slots). - StdForm
- A std type over
Textwhose values are held to a form of their own. - Step
- One step of a
Place, asjson.Stepnames it. - Time
Text Error - Why text is no
UnixMillis.
Constants§
- BINDING
- A generic Tool’s type argument, which the call’s types bind: data with
no opaque part, as a run’s input is, but which crosses no boundary
unless the Tool’s parameters or result carry it (
tools.md, Generic Tools). - CROSSING
- An existing value carried across a Tool boundary, which may be opaque or hold the host’s tokens.
- DATA_
VERSION - This implementation’s data version. No data version is stable before the first public release.
- DIALECT
- The
$schemathis crate writes. - INPUT
- A run’s input, and what
json.decodebuilds: data with no opaque part, which carries no host token either, since only a Tool’s answer may. - REBUILD
- A value the program made, rebuilt from its canonical text: no type is refused, but one whose type parameter is unbound has no encoding.
- REPLY
- A Tool’s reply: data that crosses the boundary, with no opaque part, which may carry the host’s tokens.
Traits§
- Params
- How a type parameter on the left of
Catalog::matchesmatches a type of the other catalog.
Functions§
- call_
bindings - The concrete bindings a
CallTypes,types, gives, by name, and the catalog they are named in. - call_
views - The views a generic call to
signaturecarries atarguments, whose typescatalognames: itsCallTypes. - canonical
- Returns the canonical text of
value, of typety: the one text every equal value’s JSON form shares, whichjson.encodeand a run’s output write (abi.md, The canonical text). History stores values in the binary encoding, not in this text. - canonical_
within - Returns the canonical text of
value, of typety, when it takes at mostmax_bytesbytes, andNoneotherwise. - comparable
- The comparable form of a declaration’s signature,
identityandspec: what binding compares by its bytes (abi.md, Identity and signatures). - crc32c
- The CRC-32C (Castagnoli) of
bytes. - crossable
- Whether an existing value can cross a Tool boundary. Opaque values and
host tokens may be sent; functions, tasks, nondata and ambiguous
Option<json.Value>parts may not. Nominal arguments unused by fields are descriptions rather than value parts. - decodable
- Whether a value of
tymay be built or carried wheresettingsjudge it, such as a mode’s (Mode::settings) orCROSSING(tools.md, Decoding). This is judged of the type, before any text is read, so an absent part refuses as surely as a present one, and a type parameter left unbound refuses every judgment. - decode
- Decodes
jsonas a value ofty. - decode_
bytes - Decodes
bytesas the one value oftythey encode, inmodeand withinlimits. Bytes left over after the value are refused. - decode_
text - Decodes
textas a value ofty. - encode
- Returns
value, of typety, as JSON. - encode_
bytes - Returns the encoding of
value, of typety. - encode_
for_ reading - Returns
value, of typety, asencodewrites it, except that bytes holding valid UTF-8 are written as that text: the form a person reads, which no decoder takes back. - encode_
naming_ tasks - Returns
value, of typety, asencodewrites it, except that a task is the id of the call it is parked on, whichtasksgives for the task and the type of its result: how a viewer writes a value that holds tasks. - form
- What a value of
tyis made of, its declaration looked up incatalogand its arguments put in place. - normal_
media_ type - The normal text of the media type
textspells, orNonewhen it spells none. - normal_
url - The normal text of the URL
textspells, orNonewhen it spells none. - of_
shaped_ value - The
Tthatvalue, a runtime value oftyincatalog, is. - parameter_
key - The key a parameter crosses the boundary by: its name, or
#at, its position, for one that binds no single name. - parse
- Reads one JSON value from
text, refusing anything after it but whitespace. - read_
listing - The programs a
--contractfile lists, each Tool with its own description: its templates taken from the program’s type map and numbered in its own first-reach order. - read_
scalar - Reads one value of the scalar type
scalarfromreader, withinlimits, as history reads a part that takes no slot. - read_
shaped - Reads one
Tattyincatalogfromreader, inmodeand withinlimits, leaving the reader just past it. - read_
value - Reads one value of
tyfromreader, inmodeand withinlimits, leaving the reader just past it: for a value inside a larger message. - rebuild_
by_ name - Rebuilds
value, which another program made, as a value oftyincatalog, matching each record field, named payload part and constructor by its declared name. - schema
- The schema of
ty, with each named type in$defsand every doc comment as adescription. - shaped_
value - The runtime’s value of
value, a value oftyincatalog: for a caller that holds runtime values, such as a run’s history. - std_
enum - The shape std declares the enum that plays
rolewith, as the bundled std’s sources give it (Role::shape). - write_
listing - The
--contractfile listingtoolsof the program formed fromroot, whose typescatalognames: the data version, one program, each Tool’s identity and description without templates, and the program’s type map in first-reach order over the Tools in this order. - write_
scalar - Appends the encoding of
value, a value of the scalar typescalar, toout, as history writes a part that takes no slot. - write_
shaped - Appends
value’s encoding attyincatalogtoout. - write_
value - Appends the encoding of
value, of typety, toout.