Current section

Files

Jump to
gleam_bson src bson@custom.erl
Raw

src/bson@custom.erl

-module(bson@custom).
-compile([no_auto_import, nowarn_unused_vars]).
-export([to_bit_string_with_code/1, from_bit_string_with_code/2]).
-export_type([custom/0]).
-opaque custom() :: {custom, bitstring(), bitstring()}.
-spec to_bit_string_with_code(custom()) -> {integer(), bitstring()}.
to_bit_string_with_code(Custom) ->
case Custom of
{custom, <<Code>>, Value} ->
{Code, Value}
end.
-spec from_bit_string_with_code(integer(), bitstring()) -> {ok, custom()} |
{error, nil}.
from_bit_string_with_code(Code, Value) ->
case (Code =< 16#ff) andalso (Code >= 16#80) of
true ->
{ok, {custom, <<Code>>, Value}};
false ->
{error, nil}
end.