Current section
Files
Jump to
Current section
Files
src/libero@wire.erl
-module(libero@wire).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/libero/wire.gleam").
-export([decode_call/1, encode/1]).
-export_type([decode_error/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(
" ETF (Erlang Term Format) wire codec for Libero RPC.\n"
"\n"
" Encoding walks any Gleam value through `erlang:term_to_binary/1`,\n"
" which preserves the full Erlang type structure - atoms, tuples,\n"
" maps, lists - natively. Decoding uses `erlang:binary_to_term/1`\n"
" to reconstruct the original terms. No manual walk or rebuild is\n"
" needed because ETF is the BEAM's native serialization format.\n"
"\n"
" **Wire shape:**\n"
" - The call envelope is `{fn_name_binary, args_list}` - a 2-tuple\n"
" where the first element is a UTF-8 binary (Gleam String) and the\n"
" second is a list of arbitrary terms.\n"
" - The response is the Gleam value directly (e.g. `Ok(value)` or\n"
" `Error(MalformedRequest)`), serialized as ETF.\n"
).
-type decode_error() :: {decode_error, binary()}.
-file("src/libero/wire.gleam", 35).
?DOC(
" Parse a `{<<\"fn_name\">>, [arg1, arg2, ...]}` tuple from an ETF binary.\n"
" Returns the function name and args list. Since `binary_to_term`\n"
" returns real Erlang terms, no rebuild step is needed - atoms are\n"
" atoms, tuples are tuples, maps are maps.\n"
).
-spec decode_call(bitstring()) -> {ok,
{binary(), list(gleam@dynamic:dynamic_())}} |
{error, decode_error()}.
decode_call(Data) ->
libero_wire_ffi:decode_call(Data).
-file("src/libero/wire.gleam", 21).
?DOC(" Encode any Gleam value to an ETF binary.\n").
-spec encode(any()) -> bitstring().
encode(Value) ->
libero_ffi:encode(gleam_stdlib:identity(Value)).