Merge pull request #12652 from kjellwinblad/kjell/rule_engine/fix/subbits/EMQX-11942

fix: add subbits/4 and subits/5 rule_engine functions
This commit is contained in:
Kjell Winblad 2024-03-06 15:20:30 +01:00 committed by GitHub
commit 78d5f76f70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 0 deletions

View File

@ -96,6 +96,8 @@
bytesize/1, bytesize/1,
subbits/2, subbits/2,
subbits/3, subbits/3,
subbits/4,
subbits/5,
subbits/6 subbits/6
]). ]).
@ -556,6 +558,16 @@ subbits(Bits, Len) when is_integer(Len), is_bitstring(Bits) ->
subbits(Bits, Start, Len) when is_integer(Start), is_integer(Len), is_bitstring(Bits) -> subbits(Bits, Start, Len) when is_integer(Start), is_integer(Len), is_bitstring(Bits) ->
get_subbits(Bits, Start, Len, <<"integer">>, <<"unsigned">>, <<"big">>). get_subbits(Bits, Start, Len, <<"integer">>, <<"unsigned">>, <<"big">>).
subbits(Bits, Start, Len, Type) when
is_integer(Start), is_integer(Len), is_bitstring(Bits)
->
get_subbits(Bits, Start, Len, Type, <<"unsigned">>, <<"big">>).
subbits(Bits, Start, Len, Type, Signedness) when
is_integer(Start), is_integer(Len), is_bitstring(Bits)
->
get_subbits(Bits, Start, Len, Type, Signedness, <<"big">>).
subbits(Bits, Start, Len, Type, Signedness, Endianness) when subbits(Bits, Start, Len, Type, Signedness, Endianness) when
is_integer(Start), is_integer(Len), is_bitstring(Bits) is_integer(Start), is_integer(Len), is_bitstring(Bits)
-> ->

View File

@ -911,6 +911,17 @@ t_subbits2_float(_) ->
ct:pal(";;;;~p", [R2]), ct:pal(";;;;~p", [R2]),
?assert((RL2 >= 0 andalso RL2 < 0.0001) orelse (RL2 =< 0 andalso RL2 > -0.0001)). ?assert((RL2 >= 0 andalso RL2 < 0.0001) orelse (RL2 =< 0 andalso RL2 > -0.0001)).
t_subbits_4_args(_) ->
R = apply_func(subbits, [<<5.3:64/float>>, 1, 64, <<"float">>]),
RL = (5.3 - R),
?assert((RL >= 0 andalso RL < 0.0001) orelse (RL =< 0 andalso RL > -0.0001)).
t_subbits_5_args(_) ->
?assertEqual(
456,
apply_func(subbits, [<<456:32/integer>>, 1, 32, <<"integer">>, <<"unsigned">>])
).
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% Test cases for Hash funcs %% Test cases for Hash funcs
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------

View File

@ -0,0 +1 @@
The subbits functions with 4 and 5 parameters are documented but did not exist in the implementation. These functions have now been added.