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:
commit
78d5f76f70
|
@ -96,6 +96,8 @@
|
|||
bytesize/1,
|
||||
subbits/2,
|
||||
subbits/3,
|
||||
subbits/4,
|
||||
subbits/5,
|
||||
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) ->
|
||||
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
|
||||
is_integer(Start), is_integer(Len), is_bitstring(Bits)
|
||||
->
|
||||
|
|
|
@ -911,6 +911,17 @@ t_subbits2_float(_) ->
|
|||
ct:pal(";;;;~p", [R2]),
|
||||
?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
|
||||
%%------------------------------------------------------------------------------
|
||||
|
|
|
@ -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.
|
Loading…
Reference in New Issue