Skip to content

Commit

Permalink
Add encode_list and encode_tinyint to marina_types
Browse files Browse the repository at this point in the history
  • Loading branch information
RAttab authored and lpgauth committed Mar 18, 2024
1 parent 89204db commit 2800bd6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/marina_types.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@
decode_string_list/1,
decode_string_map/1,
decode_string_multimap/1,
decode_tinyint/1,
decode_uuid/1,
encode_boolean/1,
encode_bytes/1,
encode_int/1,
encode_list/1,
encode_long/1,
encode_long_string/1,
encode_short/1,
encode_short_bytes/1,
encode_string/1,
encode_string_list/1,
encode_string_map/1,
encode_string_multimap/1
encode_string_multimap/1,
encode_tinyint/1
]).

%% public
Expand Down Expand Up @@ -90,6 +93,11 @@ decode_string_map(<<Length:16, Rest/binary>>) ->
decode_string_multimap(<<Length:16, Rest/binary>>) ->
decode_string_multimap(Rest, Length, []).

-spec decode_tinyint(binary()) -> {integer(), binary()}.

decode_tinyint(<<Value:8, Rest/binary>>) ->
{Value, Rest}.

-spec decode_uuid(binary()) -> {binary(), binary()}.

decode_uuid(<<Value:16/binary, Rest/binary>>) ->
Expand All @@ -112,6 +120,11 @@ encode_bytes(Value) ->
encode_int(Value) ->
<<Value:32>>.

-spec encode_list([binary()]) -> binary().

encode_list(Values) ->
iolist_to_binary([encode_short(length(Values)), Values]).

-spec encode_long(integer()) -> binary().

encode_long(Value) ->
Expand Down Expand Up @@ -154,6 +167,9 @@ encode_string_map(KeyValues) ->
encode_string_multimap(KeyValues) ->
encode_string_multimap(KeyValues, []).

encode_tinyint(Value) ->
<<Value:8>>.

%% private
decode_long_string_set(Bin, 0, Acc) ->
{lists:reverse(Acc), Bin};
Expand Down

0 comments on commit 2800bd6

Please sign in to comment.