Current section

Files

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

src/postgleam@codec@uuid.erl

-module(postgleam@codec@uuid).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/postgleam/codec/uuid.gleam").
-export([encode/1, decode/1, matcher/0]).
-file("src/postgleam/codec/uuid.gleam", 32).
-spec encode(postgleam@value:value()) -> {ok, bitstring()} | {error, binary()}.
encode(Val) ->
case Val of
{uuid, Data} ->
case erlang:byte_size(Data) of
16 ->
{ok, Data};
_ ->
{error, <<"uuid codec: expected 16-byte UUID"/utf8>>}
end;
_ ->
{error, <<"uuid codec: expected Uuid value"/utf8>>}
end.
-file("src/postgleam/codec/uuid.gleam", 43).
-spec decode(bitstring()) -> {ok, postgleam@value:value()} | {error, binary()}.
decode(Data) ->
case erlang:byte_size(Data) of
16 ->
{ok, {uuid, Data}};
_ ->
{error, <<"uuid codec: expected 16 bytes"/utf8>>}
end.
-file("src/postgleam/codec/uuid.gleam", 22).
-spec build(integer()) -> postgleam@codec:codec().
build(Type_oid) ->
{codec, <<"uuid"/utf8>>, Type_oid, binary, fun encode/1, fun decode/1}.
-file("src/postgleam/codec/uuid.gleam", 12).
-spec matcher() -> postgleam@codec:codec_matcher().
matcher() ->
{codec_matcher, <<"uuid"/utf8>>, [2950], none, binary, fun build/1}.