Current section

Files

Jump to
postgleam src postgleam@codec@json.erl
Raw

src/postgleam@codec@json.erl

-module(postgleam@codec@json).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/postgleam/codec/json.gleam").
-export([encode/1, decode/1, matcher/0]).
-file("src/postgleam/codec/json.gleam", 25).
-spec encode(postgleam@value:value()) -> {ok, bitstring()} | {error, binary()}.
encode(Val) ->
case Val of
{json, S} ->
{ok, <<S/binary>>};
_ ->
{error, <<"json codec: expected Json value"/utf8>>}
end.
-file("src/postgleam/codec/json.gleam", 32).
-spec decode(bitstring()) -> {ok, postgleam@value:value()} | {error, binary()}.
decode(Data) ->
case gleam@bit_array:to_string(Data) of
{ok, S} ->
{ok, {json, S}};
{error, _} ->
{error, <<"json codec: invalid UTF-8"/utf8>>}
end.
-file("src/postgleam/codec/json.gleam", 21).
-spec build(integer()) -> postgleam@codec:codec().
build(Type_oid) ->
{codec, <<"json"/utf8>>, Type_oid, binary, fun encode/1, fun decode/1}.
-file("src/postgleam/codec/json.gleam", 11).
-spec matcher() -> postgleam@codec:codec_matcher().
matcher() ->
{codec_matcher, <<"json"/utf8>>, [114], none, binary, fun build/1}.