Current section
Files
Jump to
Current section
Files
src/postgleam@codec@bool.erl
-module(postgleam@codec@bool).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/postgleam/codec/bool.gleam").
-export([encode/1, decode/1, matcher/0]).
-file("src/postgleam/codec/bool.gleam", 31).
-spec encode(postgleam@value:value()) -> {ok, bitstring()} | {error, binary()}.
encode(Val) ->
case Val of
{boolean, true} ->
{ok, <<1>>};
{boolean, false} ->
{ok, <<0>>};
_ ->
{error, <<"bool codec: expected Boolean value"/utf8>>}
end.
-file("src/postgleam/codec/bool.gleam", 39).
-spec decode(bitstring()) -> {ok, postgleam@value:value()} | {error, binary()}.
decode(Data) ->
case Data of
<<1>> ->
{ok, {boolean, true}};
<<0>> ->
{ok, {boolean, false}};
_ ->
{error, <<"bool codec: invalid data"/utf8>>}
end.
-file("src/postgleam/codec/bool.gleam", 21).
-spec build(integer()) -> postgleam@codec:codec().
build(Type_oid) ->
{codec, <<"bool"/utf8>>, Type_oid, binary, fun encode/1, fun decode/1}.
-file("src/postgleam/codec/bool.gleam", 11).
-spec matcher() -> postgleam@codec:codec_matcher().
matcher() ->
{codec_matcher, <<"bool"/utf8>>, [16], none, binary, fun build/1}.