Skip to content

Commit

Permalink
Add decode_number_list to marina_types
Browse files Browse the repository at this point in the history
  • Loading branch information
RAttab committed Apr 23, 2024
1 parent 21d2058 commit a9b8c81
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/marina_types.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
decode_long/1,
decode_long_string/1,
decode_long_string_set/1,
decode_number_list/1,
decode_short/1,
decode_short_bytes/1,
decode_string/1,
Expand Down Expand Up @@ -61,6 +62,11 @@ decode_long_string(Bin) ->
decode_long_string_set(<<Length:32, Rest/binary>>) ->
decode_long_string_set(Rest, Length, []).

-spec decode_number_list(binary()) -> {[integer()], binary()}.

decode_number_list(<<Length:32, Rest/binary>>) ->
decode_number_list(Rest, Length, []).

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

decode_short(<<Value:16, Rest/binary>>) ->
Expand Down Expand Up @@ -173,6 +179,11 @@ encode_tinyint(Value) ->
<<Value:8>>.

%% private
decode_number_list(Bin, 0, Acc) ->
{lists:reverse(Acc), Bin};
decode_number_list(<<Pos:32, Number:(Pos * 8), Rest/binary>>, Length, Acc) ->
decode_number_list(Rest, Length - 1, [Number | Acc]).

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

0 comments on commit a9b8c81

Please sign in to comment.