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 ff15d72
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion 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 All @@ -186,7 +197,7 @@ decode_string_list(<<Pos:16, String:Pos/binary, Rest/binary>>, Length, Acc) ->

decode_string_map(Bin, 0, Acc) ->
{lists:reverse(Acc), Bin};
decode_string_map(<<Pos:16, Key:Pos/binary, Pos2:16, Value:Pos2/binary,
decode_string_map(<<Pos:32, Key:Pos/binary, Pos2:16, Value:Pos2/binary,
Rest/binary>>, Length, Acc) ->

decode_string_map(Rest, Length - 1, [{Key, Value} | Acc]).
Expand Down

0 comments on commit ff15d72

Please sign in to comment.