Current section

Files

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

src/postgleam@codec@line.erl

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