From a9b8c8151373ac64e16f0f1020f028fa30020bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Attab?= Date: Mon, 22 Apr 2024 10:35:52 -0400 Subject: [PATCH] Add decode_number_list to marina_types --- src/marina_types.erl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/marina_types.erl b/src/marina_types.erl index 5dc093a..0b6c882 100644 --- a/src/marina_types.erl +++ b/src/marina_types.erl @@ -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, @@ -61,6 +62,11 @@ decode_long_string(Bin) -> decode_long_string_set(<>) -> decode_long_string_set(Rest, Length, []). +-spec decode_number_list(binary()) -> {[integer()], binary()}. + +decode_number_list(<>) -> + decode_number_list(Rest, Length, []). + -spec decode_short(binary()) -> {integer(), binary()}. decode_short(<>) -> @@ -173,6 +179,11 @@ encode_tinyint(Value) -> <>. %% private +decode_number_list(Bin, 0, Acc) -> + {lists:reverse(Acc), Bin}; +decode_number_list(<>, 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) ->