distribute/handshake/negotiation
Values
pub fn protocol_negotiate(
local_caps: List(capability.Capability),
remote_caps: List(capability.Capability),
protocol: String,
) -> option.Option(Int)
Find the highest compatible version for a protocol given local and remote capabilities. Returns Some(version) if a compatible version exists in the overlapping range, None if the protocol is not supported by both sides or ranges don’t overlap.
Algorithm
- Find capability for
protocolin local capabilities - Find capability for
protocolin remote capabilities - If both exist, compute overlap: max(local.min, remote.min) to min(local.max, remote.max)
- If overlap is valid (min <= max), return the max version of the overlap
- Otherwise return None
pub fn schema_decode_from_node(
registry: process.Subject(actor.RegistryCommand),
timeout_ms: Int,
node_id: String,
protocol: String,
schemas: List(codec.Schema(a)),
binary: BitArray,
) -> Result(a, String)
Decode a value from a specific node using the negotiated version.
Similar to schema_encode_for_node, but for decoding. Looks up the
negotiated version and uses the appropriate schema decoder.
pub fn schema_encode_for_node(
registry: process.Subject(actor.RegistryCommand),
timeout_ms: Int,
node_id: String,
protocol: String,
schemas: List(codec.Schema(a)),
value: a,
) -> Result(BitArray, String)
Encode a value for a specific node using the negotiated version.
This function looks up the negotiated version for the given protocol from the registry, selects the appropriate schema version, and encodes the value.
Parameters
registry: The registry actor subject to lookup negotiated versionstimeout_ms: Timeout for registry lookup in millisecondsnode_id: Target node identifierprotocol: Protocol name to use for version lookupschemas: List of available schemas for this protocol, ordered by versionvalue: The value to encode
Returns
Ok(binary)with encoded data using the negotiated schemaError(reason)if negotiation info not found or encoding fails
pub fn validate_capabilities(
caps: List(capability.Capability),
) -> Result(Nil, String)
Validate that a list of capabilities is well-formed. Returns Ok(Nil) if all capabilities have min <= max and non-empty protocol names. Returns Error(reason) if any capability is invalid.