Skip to main content

Crate flow_abi

Crate flow_abi 

Source
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_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.

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 its Wire codec, and the Flow type history stores one as, through Shape::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, Instant and Duration literals by these text forms.
wire
Messages declared once: wire! takes a record or enum definition and gives the type, its Wire codec and its Shape.

Macros§

wire
Declares a record or an enum once: the type itself, its Wire codec and its Shape. Doc comments and attributes pass through.
wire_impl
Gives a record, an enum or a newtype defined elsewhere its Shape and its Shaped mapping, 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 after where; 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 is Empty, Positional or Named. Fields of PhantomData are listed after phantom, and what the declaration’s text says beside its shape after notes.

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, so crc32c(b"123456789") is 0xE3069283.
DataVersion
A data version: one version for the value encoding, the Tool protocol and the history format together, written "major.minor".
DecodeError
Why decoding refused. path and kind are json.DecodeError’s path and problem (stdlib.md); problem says 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.
EncodeError
Why a value could not be encoded at a type, or a type has no schema.
EnumForm
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.
ListedProgram
One program’s Tools as the --contract file lists them (abi.md, Binding).
MediaType
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), one Step at a time from the whole value, which is the empty path.
RecordForm
A record type: its shape, and its fields’ types in declaration order with the record’s arguments in place.
ResultType
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::Param counts generic.
ToolDecl
A Tool declaration, as the host binds it.
TypeSpec
A Tool’s type description: its roots and the templates they reach, in first-reach order, validated.
UnixMillis
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 type when 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.
ValidatedTypes
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).
DecodeErrorKind
Which refusal decoding made: the cases of json.Problem (stdlib.md).
EncodeErrorKind
Which refusal encoding made.
Form
What a value of a type is made of.
Json
A JSON value.
ListingError
Why a --contract file 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 type asks 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).
OutcomeKind
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 Text whose values are held to a form of their own.
Step
One step of a Place, as json.Step names it.
TimeTextError
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 $schema this crate writes.
INPUT
A run’s input, and what json.decode builds: 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::matches matches 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 signature carries at arguments, whose types catalog names: its CallTypes.
canonical
Returns the canonical text of value, of type ty: the one text every equal value’s JSON form shares, which json.encode and 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 type ty, when it takes at most max_bytes bytes, and None otherwise.
comparable
The comparable form of a declaration’s signature, identity and spec: 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 ty may be built or carried where settings judge it, such as a mode’s (Mode::settings) or CROSSING (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 json as a value of ty.
decode_bytes
Decodes bytes as the one value of ty they encode, in mode and within limits. Bytes left over after the value are refused.
decode_text
Decodes text as a value of ty.
encode
Returns value, of type ty, as JSON.
encode_bytes
Returns the encoding of value, of type ty.
encode_for_reading
Returns value, of type ty, as encode writes 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 type ty, as encode writes it, except that a task is the id of the call it is parked on, which tasks gives for the task and the type of its result: how a viewer writes a value that holds tasks.
form
What a value of ty is made of, its declaration looked up in catalog and its arguments put in place.
normal_media_type
The normal text of the media type text spells, or None when it spells none.
normal_url
The normal text of the URL text spells, or None when it spells none.
of_shaped_value
The T that value, a runtime value of ty in catalog, 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 --contract file 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 scalar from reader, within limits, as history reads a part that takes no slot.
read_shaped
Reads one T at ty in catalog from reader, in mode and within limits, leaving the reader just past it.
read_value
Reads one value of ty from reader, in mode and within limits, 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 of ty in catalog, matching each record field, named payload part and constructor by its declared name.
schema
The schema of ty, with each named type in $defs and every doc comment as a description.
shaped_value
The runtime’s value of value, a value of ty in catalog: for a caller that holds runtime values, such as a run’s history.
std_enum
The shape std declares the enum that plays role with, as the bundled std’s sources give it (Role::shape).
write_listing
The --contract file listing tools of the program formed from root, whose types catalog names: 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 type scalar, to out, as history writes a part that takes no slot.
write_shaped
Appends value’s encoding at ty in catalog to out.
write_value
Appends the encoding of value, of type ty, to out.