Current section
Files
Jump to
Current section
Files
src/postgleam@codec@name.erl
-module(postgleam@codec@name).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/postgleam/codec/name.gleam").
-export([encode/1, decode/1, matcher/0]).
-file("src/postgleam/codec/name.gleam", 32).
-spec encode(postgleam@value:value()) -> {ok, bitstring()} | {error, binary()}.
encode(Val) ->
case Val of
{text, S} ->
Bytes = <<S/binary>>,
case erlang:byte_size(Bytes) < 64 of
true ->
{ok, Bytes};
false ->
{error, <<"name codec: value must be < 64 bytes"/utf8>>}
end;
_ ->
{error, <<"name codec: expected Text value"/utf8>>}
end.
-file("src/postgleam/codec/name.gleam", 45).
-spec decode(bitstring()) -> {ok, postgleam@value:value()} | {error, binary()}.
decode(Data) ->
case gleam@bit_array:to_string(Data) of
{ok, S} ->
{ok, {text, S}};
{error, _} ->
{error, <<"name codec: invalid UTF-8"/utf8>>}
end.
-file("src/postgleam/codec/name.gleam", 22).
-spec build(integer()) -> postgleam@codec:codec().
build(Type_oid) ->
{codec, <<"name"/utf8>>, Type_oid, binary, fun encode/1, fun decode/1}.
-file("src/postgleam/codec/name.gleam", 12).
-spec matcher() -> postgleam@codec:codec_matcher().
matcher() ->
{codec_matcher, <<"name"/utf8>>, [19], none, binary, fun build/1}.