fix: add subbits/4 and subits/5 rule_engine functions
The documentation for the family of subbits functions says that the fifth and sixth parameters are optional (since they only make sense when the forth parameter is 'integer'). However, before this commit `subbits/4` and `subbits/5` did not exist. Fixes: https://emqx.atlassian.net/browse/EMQX-11942 https://github.com/emqx/emqx/issues/12587
This commit is contained in:
parent
c2dcb507cf
commit
365d054e01
|
@ -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
|
||||
%%------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue