Expand description
C ABI bindings for the Reflow runtime.
§Design conventions
§Handles
All objects exposed to C are opaque pointers created by *_new /
*_load functions and destroyed by the matching *_free function.
Passing NULL to a *_free function is a no-op (idempotent).
§Return values
Functions that can fail return an rfl_status enum. Output values are
written through out-parameters. On error, out-parameters are left
untouched and the last error message is available via
rfl_last_error_message (thread-local).
§Strings
- C → Rust: null-terminated UTF-8
const char *. - Rust → C:
char *allocated by this library; caller frees withrfl_string_free. Never pass a Rust-allocated string tofree(3).
§Threading
Handles are Send + Sync and may be used from any thread once created.
The runtime owns a single multi-thread tokio executor that is spun up
on the first call that needs async work. rfl_runtime_shutdown tears
it down (called implicitly by the library destructor).
Structs§
- Capi
Actor - rfl_
actor - Opaque handle to an actor template. Produced by
rfl_actor_new(callback-driven actor),rfl_template_actor_new(bundled component), orrfl_subgraph_actor_new_from_json(embedded subgraph). Hand torfl_network_register_actorto publish under a template id, or torfl_actor_freeto release without registering. - rfl_
actor_ ctx - Opaque per-call context handed to a callback actor.
- rfl_
events - Opaque handle to a subscriber on the network’s event stream. One subscriber per handle — create as many as you need.
- rfl_
graph - Opaque handle to a
reflow_graph::Graph. - rfl_
message - Opaque Reflow message handle.
- rfl_
network - Opaque handle to a
reflow_network::Network, wrapped so the C side can share it across threads without touching its internalArc<Mutex<_>>. - rfl_
stream - Opaque producer handle to a stream. Create with
rfl_stream_new, hand chunks in viarfl_stream_send_bytes, terminate withrfl_stream_end/rfl_stream_error. Free withrfl_stream_free. - rfl_
stream_ recv - Opaque receiver for a stream’s data channel.
- rfl_
subgraph_ builder - Builder for a
SubgraphActorwith an explicit actor map.
Enums§
- rfl_
message_ kind - Variant tag — matches the
Messageenum inreflow_actor. - rfl_
status - rfl_
stream_ frame_ kind - Variant tag returned by
rfl_stream_recv_next.
Functions§
- rfl_
actor_ ⚠free - Free an actor handle that was never registered. NULL-safe.
- rfl_
actor_ ⚠new - Create a callback-driven actor.
- rfl_
compose_ ⚠graphs - Compose N graph exports into a single
GraphExportJSON document. - rfl_
ctx_ ⚠config_ json - Return the current config as a JSON object string. Caller frees via
rfl_string_free. Returns NULL on error. - rfl_
ctx_ ⚠emit - Emit a packet on
port.message_jsonmust parse as a ReflowMessage(e.g.{"type":"Flow"},{"type":"Integer","data":1}). Preferrfl_ctx_emit_messagefor hot-path emits — this variant serializes JSON per call. - rfl_
ctx_ ⚠emit_ message - Emit a typed message on
port. Transfers ownership of the message — do not callrfl_message_freeafterwards. Prefer this over the JSON variant for hot-path emits. - rfl_
ctx_ ⚠has_ input - 1 if a packet is available on
port, 0 otherwise. Does not consume. - rfl_
ctx_ ⚠input_ json - Return the input packet on
portas a JSON-encodedMessage, or NULL if no packet is available. Caller frees viarfl_string_free. - rfl_
ctx_ ⚠state_ get - Fetch a state entry as JSON. Returns NULL if absent.
Caller frees via
rfl_string_free. - rfl_
ctx_ ⚠state_ set - Set a state entry.
value_jsonis a JSON value (any shape). - rfl_
ctx_ ⚠take_ input_ message - Take the input packet on
portas a typed message handle, removing it from the context. Returns NULL if no packet is available. Caller frees viarfl_message_free(or transfers ownership viarfl_ctx_emit_message). - rfl_
events_ ⚠free - Free an events handle. Safe on NULL.
- rfl_
events_ ⚠recv - Poll for the next event, blocking up to
timeout_msmilliseconds. - rfl_
graph_ ⚠add_ connection - rfl_
graph_ ⚠add_ graph_ initial - Push a packet into one of the graph’s exposed inports.
- rfl_
graph_ ⚠add_ graph_ initial_ index - Indexed variant of
rfl_graph_add_graph_initial. - rfl_
graph_ ⚠add_ group - Create a group containing the given node ids.
nodes_jsonmust be a JSON array of strings, e.g.["a","b"]. - rfl_
graph_ ⚠add_ initial - Add an initial packet.
data_jsonis the JSON representation of the value (not aMessage) — matchesGraph::add_initial. - rfl_
graph_ ⚠add_ initial_ index add_initialwith an explicit slot index for arrays/streams. MirrorsGraph::add_initial_index.- rfl_
graph_ ⚠add_ inport - Expose an inport on the graph (used when this graph is embedded as a
subgraph).
port_type_jsonis optional; pass NULL forPortType::Anyor"\"All\""/"\"Flow\""etc. - rfl_
graph_ ⚠add_ node - Add a node.
metadata_jsonmay be NULL or a JSON object string ({"key": ...}). - rfl_
graph_ ⚠add_ outport - rfl_
graph_ ⚠add_ to_ group - rfl_
graph_ ⚠free - Free a graph handle. Safe on NULL.
- rfl_
graph_ ⚠get_ connection_ json - Look up a connection by both endpoints. NULL if no such edge.
- rfl_
graph_ ⚠get_ node_ json - Look up a node by id. Returns the JSON of the GraphNode, or NULL if the id is unknown (last error explains).
- rfl_
graph_ ⚠get_ properties_ json - rfl_
graph_ ⚠import - Merge a
GraphExportJSON document into the existing graph (additive — does not clear). - rfl_
graph_ ⚠list_ connections_ json - rfl_
graph_ ⚠list_ groups_ json - rfl_
graph_ ⚠list_ initializers_ json - rfl_
graph_ ⚠list_ inports_ json - rfl_
graph_ ⚠list_ nodes_ json - JSON array of every node in the graph.
- rfl_
graph_ ⚠list_ outports_ json - rfl_
graph_ ⚠load_ json - Load a graph from a
GraphExportJSON document. - rfl_
graph_ ⚠new - Create a new empty graph.
- rfl_
graph_ ⚠remove_ connection - rfl_
graph_ ⚠remove_ from_ group - rfl_
graph_ ⚠remove_ graph_ initial - Remove an initial packet attached to a graph-level inport.
- rfl_
graph_ ⚠remove_ group - rfl_
graph_ ⚠remove_ initial - rfl_
graph_ ⚠remove_ inport - rfl_
graph_ ⚠remove_ node - rfl_
graph_ ⚠remove_ outport - rfl_
graph_ ⚠rename_ inport - Rename an exposed inport (subgraph boundary).
- rfl_
graph_ ⚠rename_ node - Rename a node. Updates every connection that referenced the old id.
- rfl_
graph_ ⚠rename_ outport - Rename an exposed outport (subgraph boundary).
- rfl_
graph_ ⚠set_ connection_ metadata - Replace the metadata on a connection. NULL
metadata_jsonclears it. - rfl_
graph_ ⚠set_ group_ metadata - rfl_
graph_ ⚠set_ inport_ metadata - rfl_
graph_ ⚠set_ node_ metadata - Replace the metadata for an existing node.
- rfl_
graph_ ⚠set_ outport_ metadata - rfl_
graph_ ⚠set_ properties - Replace the graph’s properties dict. NULL clears it.
- rfl_
graph_ ⚠to_ json - Serialize a graph back to its
GraphExportJSON form. Caller frees viarfl_string_free. - rfl_
last_ error_ message - Returns the last thread-local error message as a newly allocated C string.
Caller frees with
rfl_string_free. Returns NULL if there is no error. - rfl_
message_ ⚠array_ from_ json - Array from a JSON array string.
- rfl_
message_ ⚠as_ boolean - If the message is a Boolean, writes its value into
*outand returns 1. Returns 0 otherwise. - rfl_
message_ ⚠as_ float - rfl_
message_ ⚠as_ integer - rfl_
message_ ⚠as_ json - Full message serialized as JSON. Always succeeds for representable
variants. Caller frees via
rfl_string_free. - rfl_
message_ ⚠as_ string - String access — returns a newly allocated C string on String/Error
variants, else NULL. Caller frees via
rfl_string_free. - rfl_
message_ boolean - rfl_
message_ ⚠bytes - Binary payload; the buffer is copied into a refcounted allocation.
- rfl_
message_ ⚠bytes_ borrow - Zero-copy borrow of a
Bytespayload. Writes a pointer into the Arc’d buffer and its length. The pointer is valid until the message handle is freed (or ownership transferred). Returns 1 on success, 0 if the message is not a Bytes variant. - rfl_
message_ ⚠error - rfl_
message_ float - rfl_
message_ flow - rfl_
message_ ⚠free - Free a message handle. Safe on NULL.
- rfl_
message_ ⚠from_ json - Fallback: parse a fully-tagged
MessageJSON (i.e. the same shape the legacyrfl_ctx_emit-by-JSON path consumes). Useful for tests / debugging — prefer the typed constructors in production. - rfl_
message_ ⚠get_ kind - rfl_
message_ integer - rfl_
message_ ⚠object_ from_ json - Object from JSON. The JSON must parse as any valid serde value.
- rfl_
message_ ⚠stream_ take - Take the receiver for a
StreamHandlemessage. Transfers ownership — only one call succeeds per stream. Returns NULL if the message is not a StreamHandle or the receiver has already been taken. - rfl_
message_ ⚠string - UTF-8 string; copied.
- rfl_
network_ ⚠add_ connection - rfl_
network_ ⚠add_ initial - Seed an initial packet.
message_jsonmust parse as aMessage(e.g."\"Flow\"",{"Integer": 3},{"String": "hi"}). - rfl_
network_ ⚠add_ node - Add a node to a running or pending network. The
template_id’s actor must have been registered first (via the component catalog or a customrfl_actor_registeronce available). - rfl_
network_ ⚠events - Subscribe to the network’s event stream. Call before
rfl_network_startfor full coverage. - rfl_
network_ ⚠free - Free a network handle. Safe on NULL. Implies shutdown.
- rfl_
network_ ⚠from_ graph - Create a network from an already-loaded graph. The graph is consumed.
- rfl_
network_ new - Create a new network with
NetworkConfig::default(). - rfl_
network_ ⚠new_ with_ config - Create a new network from a serialized
NetworkConfigJSON. Returns NULL on parse error. Unknown fields are rejected. - rfl_
network_ ⚠register_ actor - Register a callback actor as a template on the network. The network takes ownership; the caller must not continue to use the handle afterwards (treat it as freed).
- rfl_
network_ ⚠shutdown - Signal the network to shut down. Non-blocking.
- rfl_
network_ ⚠start - Start the network. Non-blocking; returns immediately after scheduling the actors.
- rfl_
pack_ abi_ version - The pack ABI version this host was compiled with. Pack authors can
stamp the same number into their
.rflpackmanifests viareflow-pack build(which reads theREFLOW_PACK_ABI_VERSIONenv var or[abi]section). - rfl_
pack_ ⚠inspect_ json - Read a
.rflpackmanifest without loading the pack. Fails for raw dylibs (they have no manifest). Caller frees the returned JSON viarfl_string_free. - rfl_
pack_ list_ json - Return a JSON array describing every loaded pack:
[{ "name": ..., "version": ..., "source_path": ..., "templates": [...] }]. Caller frees viarfl_string_free. - rfl_
pack_ ⚠load - Load an actor pack from
path.pathcan point at either: - rfl_
runtime_ shutdown - Explicitly tear down the shared tokio runtime.
- rfl_
stream_ ⚠end - Terminate the stream with success.
- rfl_
stream_ ⚠error - Terminate the stream with an error.
- rfl_
stream_ ⚠free - Free a producer handle without emitting it as a message. If the stream
has live consumers, they will see an
Endframe when the sender is dropped. - rfl_
stream_ ⚠into_ message - Convert this stream producer into a
Message::StreamHandlethat can be emitted on an output port. The producer is consumed — free is not necessary after this call. - rfl_
stream_ ⚠new - Allocate a new stream.
buffer_size == 0creates an unbounded channel; any positive value sets a bounded buffer (backpressure). - rfl_
stream_ ⚠recv_ free - Free a stream receiver. Safe on NULL.
- rfl_
stream_ ⚠recv_ next - Block up to
timeout_msfor the next frame. - rfl_
stream_ ⚠send_ begin - Send a Begin frame (stream metadata). Optional — use before the first
send_bytesif you want consumers to seecontent_type/size_hint/metadata_jsonbefore any data. - rfl_
stream_ ⚠send_ bytes - Send a Data frame. The buffer is copied into a refcounted allocation.
- rfl_
string_ ⚠free - Free a string returned by this library. Passing NULL is a no-op.
- rfl_
subgraph_ ⚠actor_ new_ from_ json - Build a SubgraphActor from a
GraphExportJSON document. Each component referenced inside the export is resolved against the pack registry first, then the bundledreflow_componentscatalog. Returns NULL on parse error or on unknown component references. - rfl_
subgraph_ ⚠builder_ build - Build the subgraph into an actor handle. Consumes the builder.
- rfl_
subgraph_ ⚠builder_ fill_ from_ catalog - Resolve any still-unregistered components: packs first, then the
bundled catalog (if the
componentsfeature is on). Components still missing after both lookups cause the call to fail. - rfl_
subgraph_ ⚠builder_ free - Abandon a builder without building. Safe on NULL.
- rfl_
subgraph_ ⚠builder_ new - Start a subgraph builder over a
GraphExportJSON document. Returns NULL on parse error. - rfl_
subgraph_ ⚠builder_ register_ actor - Register an actor under
component_name. The builder takes ownership of the actor handle — do not free it afterwards. Replacing an existing registration silently overwrites it. - rfl_
template_ ⚠actor_ new - Instantiate an actor from a template id.
- rfl_
template_ list_ json - Return a JSON array of every template id reachable through this
runtime — loaded packs plus (when compiled) the bundled catalog.
Caller frees via
rfl_string_free. - rfl_
version - Runtime version string (newly allocated; free with
rfl_string_free).
Type Aliases§
- rfl_
actor_ drop_ fn - Function pointer: released when the runtime drops the last reference to the actor. Use it to decrement a Node/Python/JVM GC root.
- rfl_
actor_ fn - Function pointer: the body of a callback actor.