fix: hexstr2bin support half byte
This commit is contained in:
parent
84fa6bfaeb
commit
de1d8909c3
|
@ -27,6 +27,7 @@ File format:
|
|||
* List subscription topic (/api/v4/subscriptions), the result do not match with multiple conditions.
|
||||
* SSL closed error bug fixed for redis client.
|
||||
* Fix mqtt-sn client disconnected due to re-send a duplicated qos2 message
|
||||
* rule-engine function hexstr2bin/1 support half byte
|
||||
|
||||
* Improved resilience against autocluster partitioning during cluster
|
||||
startup. [#7876]
|
||||
|
|
|
@ -159,8 +159,12 @@ t_term_encode(_) ->
|
|||
end, TestData).
|
||||
|
||||
t_hexstr2bin(_) ->
|
||||
?assertEqual(<<1,2>>, emqx_rule_funcs:hexstr2bin(<<"0102">>)),
|
||||
?assertEqual(<<17,33>>, emqx_rule_funcs:hexstr2bin(<<"1121">>)).
|
||||
?assertEqual(<<6, 54, 79>>, emqx_rule_funcs:hexstr2bin(<<"6364f">>)),
|
||||
?assertEqual(<<10>>, emqx_rule_funcs:hexstr2bin(<<"a">>)),
|
||||
?assertEqual(<<15>>, emqx_rule_funcs:hexstr2bin(<<"f">>)),
|
||||
?assertEqual(<<5>>, emqx_rule_funcs:hexstr2bin(<<"5">>)),
|
||||
?assertEqual(<<1, 2>>, emqx_rule_funcs:hexstr2bin(<<"0102">>)),
|
||||
?assertEqual(<<17, 33>>, emqx_rule_funcs:hexstr2bin(<<"1121">>)).
|
||||
|
||||
t_bin2hexstr(_) ->
|
||||
?assertEqual(<<"0102">>, emqx_rule_funcs:bin2hexstr(<<1,2>>)),
|
||||
|
|
|
@ -2,13 +2,15 @@
|
|||
%% Unless you know what you are doing, DO NOT edit manually!!
|
||||
{VSN,
|
||||
[{"4.3.15",
|
||||
[{load_module,emqx_frame,brutal_purge,soft_purge,[]},
|
||||
[{load_module,emqx_misc,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_frame,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_channel,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_access_rule,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_app,brutal_purge,soft_purge,[]}]},
|
||||
{"4.3.14",
|
||||
[{load_module,emqx_access_rule,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_channel,brutal_purge,soft_purge,[]},
|
||||
[{load_module,emqx_misc,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_access_rule,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_channel,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_sys,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_plugins,brutal_purge,soft_purge,[]},
|
||||
|
@ -459,12 +461,14 @@
|
|||
{load_module,emqx_limiter,brutal_purge,soft_purge,[]}]},
|
||||
{<<".*">>,[]}],
|
||||
[{"4.3.15",
|
||||
[{load_module,emqx_frame,brutal_purge,soft_purge,[]},
|
||||
[{load_module,emqx_misc,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_frame,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_channel,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_access_rule,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_app,brutal_purge,soft_purge,[]}]},
|
||||
{"4.3.14",
|
||||
[{load_module,emqx_access_rule,brutal_purge,soft_purge,[]},
|
||||
[{load_module,emqx_misc,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_access_rule,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_channel,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_sys,brutal_purge,soft_purge,[]},
|
||||
|
|
|
@ -317,7 +317,19 @@ int2hexchar(I, lower) -> I - 10 + $a.
|
|||
|
||||
-spec(hexstr2bin(binary()) -> binary()).
|
||||
hexstr2bin(B) when is_binary(B) ->
|
||||
<< <<(hexchar2int(H)*16 + hexchar2int(L))>> || <<H:8, L:8>> <= B>>.
|
||||
hexstr2bin(B, erlang:bit_size(B)).
|
||||
|
||||
hexstr2bin(B, Size) when is_binary(B) ->
|
||||
case Size rem 16 of
|
||||
0 ->
|
||||
make_binary(B);
|
||||
8 ->
|
||||
make_binary(<<"0", B/binary>>);
|
||||
_ ->
|
||||
throw({unsupport_hex_string, B, Size})
|
||||
end.
|
||||
|
||||
make_binary(B) -> <<<<(hexchar2int(H) * 16 + hexchar2int(L))>> || <<H:8, L:8>> <= B>>.
|
||||
|
||||
hexchar2int(I) when I >= $0 andalso I =< $9 -> I - $0;
|
||||
hexchar2int(I) when I >= $A andalso I =< $F -> I - $A + 10;
|
||||
|
|
Loading…
Reference in New Issue