Current section
Files
Jump to
Current section
Files
src/postgleam@codec@text.erl
-module(postgleam@codec@text).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/postgleam/codec/text.gleam").
-export([encode/1, decode/1, matcher/0]).
-file("src/postgleam/codec/text.gleam", 40).
-spec encode(postgleam@value:value()) -> {ok, bitstring()} | {error, binary()}.
encode(Val) ->
case Val of
{text, S} ->
{ok, <<S/binary>>};
_ ->
{error, <<"text codec: expected Text value"/utf8>>}
end.
-file("src/postgleam/codec/text.gleam", 47).
-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, <<"text codec: invalid UTF-8"/utf8>>}
end.
-file("src/postgleam/codec/text.gleam", 30).
-spec build(integer()) -> postgleam@codec:codec().
build(Type_oid) ->
{codec, <<"text"/utf8>>, Type_oid, binary, fun encode/1, fun decode/1}.
-file("src/postgleam/codec/text.gleam", 20).
-spec matcher() -> postgleam@codec:codec_matcher().
matcher() ->
{codec_matcher,
<<"text"/utf8>>,
[25, 1043, 18, 1042, 705],
{some, <<"textsend"/utf8>>},
binary,
fun build/1}.