Current section
Files
Jump to
Current section
Files
src/atproto_codegen@plugins@decode_json.erl
-module(atproto_codegen@plugins@decode_json).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/atproto_codegen/plugins/decode_json.gleam").
-export([plugin/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(
" The `decode-json` plugin: for each codec unit (a def or a synthesized\n"
" union field type), emits the `gleam/dynamic/decode` decoder. Pairs with\n"
" the `types` plugin, whose type/fields/encoder the host interleaves this\n"
" decoder after, matching the original monolithic emitter's ordering.\n"
).
-file("src/atproto_codegen/plugins/decode_json.gleam", 37).
-spec render_unit(
atproto_codegen@config:config(),
binary(),
atproto_codegen@lower:codec_unit()
) -> binary().
render_unit(Cfg, Nsid, Unit) ->
case Unit of
{def_unit, Def} ->
Name = atproto_codegen@naming:def_type_name(
erlang:element(5, Cfg),
Def
),
Props = atproto_codegen@lower:properties_of(Def),
atproto_codegen@emit@def:emit_decoder(Cfg, Nsid, Def, Name, Props);
{union_unit, Def@1, Field, Refs} ->
Name@1 = atproto_codegen@emit@exprs:union_type_name(
Cfg,
Def@1,
Field
),
erlang:element(
4,
atproto_codegen@emit@union:emit_union(Cfg, Nsid, Name@1, Refs)
)
end.
-file("src/atproto_codegen/plugins/decode_json.gleam", 22).
-spec emit(atproto_codegen@plugin:plugin_context()) -> {ok,
list(atproto_codegen@plugin:output_file())} |
{error, atproto_codegen@plugin:codegen_error()}.
emit(Ctx) ->
_pipe = erlang:element(4, Ctx),
_pipe@1 = gleam@list:filter_map(
_pipe,
fun(Lex) ->
case atproto_codegen@lower:codec_units(erlang:element(4, Lex)) of
[] ->
{error, nil};
Units ->
{ok,
{output_file,
<<(atproto_codegen@naming:module_subpath(
erlang:element(5, erlang:element(2, Ctx)),
erlang:element(2, Lex)
))/binary,
".gleam"/utf8>>,
gleam@list:map(
Units,
fun(_capture) ->
render_unit(
erlang:element(2, Ctx),
erlang:element(2, Lex),
_capture
)
end
)}}
end
end
),
{ok, _pipe@1}.
-file("src/atproto_codegen/plugins/decode_json.gleam", 18).
-spec plugin() -> atproto_codegen@plugin:plugin().
plugin() ->
{plugin, <<"decode-json"/utf8>>, [], fun emit/1}.