Current section

Files

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

src/postgleam@codec@point.erl

-module(postgleam@codec@point).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/postgleam/codec/point.gleam").
-export([encode/1, decode/1, matcher/0]).
-file("src/postgleam/codec/point.gleam", 24).
-spec encode(postgleam@value:value()) -> {ok, bitstring()} | {error, binary()}.
encode(Val) ->
case Val of
{point, X, Y} ->
{ok, <<X:64/float-big, Y:64/float-big>>};
_ ->
{error, <<"point codec: expected Point value"/utf8>>}
end.
-file("src/postgleam/codec/point.gleam", 31).
-spec decode(bitstring()) -> {ok, postgleam@value:value()} | {error, binary()}.
decode(Data) ->
case Data of
<<X:64/float-big, Y:64/float-big>> ->
{ok, {point, X, Y}};
_ ->
{error, <<"point codec: expected 16 bytes"/utf8>>}
end.
-file("src/postgleam/codec/point.gleam", 20).
-spec build(integer()) -> postgleam@codec:codec().
build(Type_oid) ->
{codec, <<"point"/utf8>>, Type_oid, binary, fun encode/1, fun decode/1}.
-file("src/postgleam/codec/point.gleam", 10).
-spec matcher() -> postgleam@codec:codec_matcher().
matcher() ->
{codec_matcher, <<"point"/utf8>>, [600], none, binary, fun build/1}.