Current section

Files

Jump to
discord_gleam src discord_gleam@ws@packets@hello.erl
Raw

src/discord_gleam@ws@packets@hello.erl

-module(discord_gleam@ws@packets@hello).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([string_to_data/1]).
-export_type([hello_packet_data/0, hello_packet/0]).
-type hello_packet_data() :: {hello_packet_data, integer()}.
-type hello_packet() :: {hello_packet, integer(), hello_packet_data()}.
-spec string_to_data(binary()) -> integer().
string_to_data(Encoded) ->
Decoder = gleam@dynamic:decode2(
fun(Field@0, Field@1) -> {hello_packet, Field@0, Field@1} end,
gleam@dynamic:field(<<"op"/utf8>>, fun gleam@dynamic:int/1),
gleam@dynamic:field(
<<"d"/utf8>>,
gleam@dynamic:decode1(
fun(Field@0) -> {hello_packet_data, Field@0} end,
gleam@dynamic:field(
<<"heartbeat_interval"/utf8>>,
fun gleam@dynamic:int/1
)
)
)
),
Data = gleam@json:decode(Encoded, Decoder),
case Data of
{ok, Decoded} ->
erlang:element(2, erlang:element(3, Decoded));
{error, _} ->
0
end.