Current section
Files
Jump to
Current section
Files
src/postgleam@codec@jsonpath.erl
-module(postgleam@codec@jsonpath).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/postgleam/codec/jsonpath.gleam").
-export([encode/1, decode/1, matcher/0]).
-file("src/postgleam/codec/jsonpath.gleam", 31).
-spec encode(postgleam@value:value()) -> {ok, bitstring()} | {error, binary()}.
encode(Val) ->
case Val of
{jsonpath, S} ->
{ok, <<1, S/binary>>};
_ ->
{error, <<"jsonpath codec: expected Jsonpath value"/utf8>>}
end.
-file("src/postgleam/codec/jsonpath.gleam", 38).
-spec decode(bitstring()) -> {ok, postgleam@value:value()} | {error, binary()}.
decode(Data) ->
case Data of
<<1, Rest/bitstring>> ->
case gleam@bit_array:to_string(Rest) of
{ok, S} ->
{ok, {jsonpath, S}};
{error, _} ->
{error, <<"jsonpath codec: invalid UTF-8"/utf8>>}
end;
_ ->
{error,
<<"jsonpath codec: missing version byte or invalid data"/utf8>>}
end.
-file("src/postgleam/codec/jsonpath.gleam", 21).
-spec build(integer()) -> postgleam@codec:codec().
build(Type_oid) ->
{codec, <<"jsonpath"/utf8>>, Type_oid, binary, fun encode/1, fun decode/1}.
-file("src/postgleam/codec/jsonpath.gleam", 11).
-spec matcher() -> postgleam@codec:codec_matcher().
matcher() ->
{codec_matcher, <<"jsonpath"/utf8>>, [4072], none, binary, fun build/1}.