Merge pull request #7842 from zmstone/0429-refactor-rename-funs-to-please-elvis

refactor: rename functions to please elvis
This commit is contained in:
zhouzb 2022-04-29 17:38:17 +08:00 committed by GitHub
commit fc2169ba18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 17 deletions

View File

@ -145,10 +145,10 @@ npid() ->
NPid. NPid.
to_hexstr(I) when byte_size(I) =:= 16 -> to_hexstr(I) when byte_size(I) =:= 16 ->
emqx_misc:bin2hexstr_A_F(I). emqx_misc:bin_to_hexstr(I, upper).
from_hexstr(S) when byte_size(S) =:= 32 -> from_hexstr(S) when byte_size(S) =:= 32 ->
emqx_misc:hexstr2bin(S). emqx_misc:hexstr_to_bin(S).
to_base62(<<I:128>>) -> to_base62(<<I:128>>) ->
emqx_base62:encode(I). emqx_base62:encode(I).

View File

@ -53,9 +53,8 @@
]). ]).
-export([ -export([
bin2hexstr_A_F/1, bin_to_hexstr/2,
bin2hexstr_a_f/1, hexstr_to_bin/1
hexstr2bin/1
]). ]).
-export([clamp/3]). -export([clamp/3]).
@ -304,20 +303,18 @@ index_of(E, I, [E | _]) ->
index_of(E, I, [_ | L]) -> index_of(E, I, [_ | L]) ->
index_of(E, I + 1, L). index_of(E, I + 1, L).
-spec bin2hexstr_A_F(binary()) -> binary(). -spec bin_to_hexstr(binary(), lower | upper) -> binary().
bin2hexstr_A_F(B) when is_binary(B) -> bin_to_hexstr(B, upper) when is_binary(B) ->
<<<<(int2hexchar(H, upper)), (int2hexchar(L, upper))>> || <<H:4, L:4>> <= B>>. <<<<(int2hexchar(H, upper)), (int2hexchar(L, upper))>> || <<H:4, L:4>> <= B>>;
bin_to_hexstr(B, lower) when is_binary(B) ->
-spec bin2hexstr_a_f(binary()) -> binary().
bin2hexstr_a_f(B) when is_binary(B) ->
<<<<(int2hexchar(H, lower)), (int2hexchar(L, lower))>> || <<H:4, L:4>> <= B>>. <<<<(int2hexchar(H, lower)), (int2hexchar(L, lower))>> || <<H:4, L:4>> <= B>>.
int2hexchar(I, _) when I >= 0 andalso I < 10 -> I + $0; int2hexchar(I, _) when I >= 0 andalso I < 10 -> I + $0;
int2hexchar(I, upper) -> I - 10 + $A; int2hexchar(I, upper) -> I - 10 + $A;
int2hexchar(I, lower) -> I - 10 + $a. int2hexchar(I, lower) -> I - 10 + $a.
-spec hexstr2bin(binary()) -> binary(). -spec hexstr_to_bin(binary()) -> binary().
hexstr2bin(B) when is_binary(B) -> hexstr_to_bin(B) when is_binary(B) ->
<<<<(hexchar2int(H) * 16 + hexchar2int(L))>> || <<H:8, L:8>> <= 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 >= $0 andalso I =< $9 -> I - $0;

View File

@ -190,7 +190,7 @@ handler_id(Name, Type) ->
do_handler_id(Name, Type) do_handler_id(Name, Type)
catch catch
_:_ -> _:_ ->
Hash = emqx_misc:bin2hexstr_a_f(crypto:hash(md5, Name)), Hash = emqx_misc:bin_to_hexstr(crypto:hash(md5, Name), lower),
do_handler_id(Hash, Type) do_handler_id(Hash, Type)
end. end.

View File

@ -20,6 +20,8 @@
-include_lib("emqx/include/emqx.hrl"). -include_lib("emqx/include/emqx.hrl").
-include_lib("emqx/include/logger.hrl"). -include_lib("emqx/include/logger.hrl").
-elvis([{elvis_style, god_modules, disable}]).
%% IoT Funcs %% IoT Funcs
-export([ -export([
msgid/0, msgid/0,
@ -617,10 +619,10 @@ map(Data) ->
emqx_plugin_libs_rule:map(Data). emqx_plugin_libs_rule:map(Data).
bin2hexstr(Bin) when is_binary(Bin) -> bin2hexstr(Bin) when is_binary(Bin) ->
emqx_misc:bin2hexstr_A_F(Bin). emqx_misc:bin_to_hexstr(Bin, upper).
hexstr2bin(Str) when is_binary(Str) -> hexstr2bin(Str) when is_binary(Str) ->
emqx_misc:hexstr2bin(Str). emqx_misc:hexstr_to_bin(Str).
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% NULL Funcs %% NULL Funcs
@ -885,7 +887,7 @@ sha256(S) when is_binary(S) ->
hash(sha256, S). hash(sha256, S).
hash(Type, Data) -> hash(Type, Data) ->
emqx_misc:bin2hexstr_a_f(crypto:hash(Type, Data)). emqx_misc:bin_to_hexstr(crypto:hash(Type, Data), lower).
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% Data encode and decode Funcs %% Data encode and decode Funcs