Current section
Files
Jump to
Current section
Files
src/plushie@protocol.erl
-module(plushie@protocol).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/plushie/protocol.gleam").
-export([encode_error_to_string/1, decode_error_to_string/1]).
-export_type([format/0, encode_error/0, 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(
" Wire protocol types and constants.\n"
"\n"
" The plushie wire protocol supports two serialization formats:\n"
" MessagePack (default, length-prefixed) and JSONL (newline-delimited,\n"
" for debugging). Protocol version is embedded in the settings message\n"
" sent to the Rust binary on startup.\n"
).
-type format() :: json | msgpack.
-type encode_error() :: {serialization_failed, binary()}.
-type decode_error() :: {deserialization_failed, binary()} |
{unknown_message_type, binary()} |
{unknown_event_family, binary()} |
{malformed_event, binary()} |
{protocol_mismatch, integer(), integer()}.
-file("src/plushie/protocol.gleam", 33).
?DOC(" Format an EncodeError as a human-readable string.\n").
-spec encode_error_to_string(encode_error()) -> binary().
encode_error_to_string(Err) ->
case Err of
{serialization_failed, Msg} ->
<<"serialization failed: "/utf8, Msg/binary>>
end.
-file("src/plushie/protocol.gleam", 40).
?DOC(" Format a DecodeError as a human-readable string.\n").
-spec decode_error_to_string(decode_error()) -> binary().
decode_error_to_string(Err) ->
case Err of
{deserialization_failed, Msg} ->
<<"deserialization failed: "/utf8, Msg/binary>>;
{unknown_message_type, T} ->
<<"unknown message type: "/utf8, T/binary>>;
{unknown_event_family, F} ->
<<"unknown event family: "/utf8, F/binary>>;
{malformed_event, Msg@1} ->
<<"malformed event: "/utf8, Msg@1/binary>>;
{protocol_mismatch, Expected, Got} ->
<<<<<<"protocol mismatch: expected "/utf8,
(erlang:integer_to_binary(Expected))/binary>>/binary,
" got "/utf8>>/binary,
(erlang:integer_to_binary(Got))/binary>>
end.