Packages

Typed distributed messaging for Gleam on the BEAM.

Retired package: Deprecated - The project needs to be redesigned around a much smaller and clearer core.

Current section

Files

Jump to
distribute src distribute@capability.erl
Raw

src/distribute@capability.erl

-module(distribute@capability).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/distribute/capability.gleam").
-export([new/3, make/3, protocol/1, min_version/1, max_version/1]).
-export_type([capability/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Protocol capability definitions for version negotiation.\n"
"\n"
" Capabilities are exchanged during handshake to ensure nodes can communicate\n"
" using compatible protocol versions. Each capability specifies a protocol name\n"
" and a version range (min to max) that the node supports.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" import distribute/capability\n"
"\n"
" let caps = [\n"
" capability.new(\"messaging\", 1, 3), // Supports messaging v1-v3\n"
" capability.new(\"crypto\", 2, 2), // Only supports crypto v2\n"
" ]\n"
" ```\n"
).
-type capability() :: {capability, binary(), integer(), integer()}.
-file("src/distribute/capability.gleam", 29).
?DOC(" Create a new capability with protocol name and version range.\n").
-spec new(binary(), integer(), integer()) -> capability().
new(Protocol, Min, Max) ->
{capability, Protocol, Min, Max}.
-file("src/distribute/capability.gleam", 35).
?DOC(" Create a new capability with protocol name and version range.\n").
-spec make(binary(), integer(), integer()) -> capability().
make(Protocol, Min, Max) ->
new(Protocol, Min, Max).
-file("src/distribute/capability.gleam", 40).
?DOC(" Get the protocol name from a capability.\n").
-spec protocol(capability()) -> binary().
protocol(C) ->
erlang:element(2, C).
-file("src/distribute/capability.gleam", 45).
?DOC(" Get the minimum supported version from a capability.\n").
-spec min_version(capability()) -> integer().
min_version(C) ->
erlang:element(3, C).
-file("src/distribute/capability.gleam", 50).
?DOC(" Get the maximum supported version from a capability.\n").
-spec max_version(capability()) -> integer().
max_version(C) ->
erlang:element(4, C).