Current section

Files

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

src/postgleam@codec@timetz.erl

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