-module(ewe@internal@decoder). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/ewe/internal/decoder.gleam"). -export([decode_packet/3, decode_method/1]). -export_type([packet_type/0, abs_path/0, http_packet/0, packet/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(false). -type packet_type() :: http_bin | httph_bin. -type abs_path() :: {abs_path, bitstring()}. -type http_packet() :: {http_request, gleam@erlang@atom:atom_(), abs_path(), {integer(), integer()}} | {http_header, integer(), gleam@erlang@atom:atom_(), bitstring(), bitstring()} | http_eoh. -type packet() :: {packet, http_packet(), bitstring()} | {more, gleam@option:option(integer())}. -file("src/ewe/internal/decoder.gleam", 35). ?DOC(false). -spec decode_packet(packet_type(), bitstring(), list(any())) -> {ok, packet()} | {error, gleam@dynamic:dynamic_()}. decode_packet(Type_, Packet, Options) -> ewe_ffi:decode_packet(Type_, Packet, Options). -file("src/ewe/internal/decoder.gleam", 41). ?DOC(false). -spec decode_method(gleam@erlang@atom:atom_()) -> {ok, gleam@http:method()} | {error, nil}. decode_method(Method) -> Get = erlang:binary_to_atom(<<"GET"/utf8>>), Post = erlang:binary_to_atom(<<"POST"/utf8>>), Head = erlang:binary_to_atom(<<"HEAD"/utf8>>), Put = erlang:binary_to_atom(<<"PUT"/utf8>>), Delete = erlang:binary_to_atom(<<"DELETE"/utf8>>), Trace = erlang:binary_to_atom(<<"TRACE"/utf8>>), Connect = erlang:binary_to_atom(<<"CONNECT"/utf8>>), Options = erlang:binary_to_atom(<<"OPTIONS"/utf8>>), Patch = erlang:binary_to_atom(<<"PATCH"/utf8>>), case Method of _ when Method =:= Get -> {ok, get}; _ when Method =:= Post -> {ok, post}; _ when Method =:= Head -> {ok, head}; _ when Method =:= Put -> {ok, put}; _ when Method =:= Delete -> {ok, delete}; _ when Method =:= Trace -> {ok, trace}; _ when Method =:= Connect -> {ok, connect}; _ when Method =:= Options -> {ok, options}; _ when Method =:= Patch -> {ok, patch}; _ -> {error, nil} end.