refactor: move binary_util to emqx_utils_binary
This commit is contained in:
parent
f8e9e54393
commit
1880da0a2e
|
@ -227,7 +227,7 @@ to_operations(Obj, ObjDefinition) ->
|
||||||
}.
|
}.
|
||||||
|
|
||||||
path_list(Path) ->
|
path_list(Path) ->
|
||||||
case binary:split(binary_util:trim(Path, $/), [<<$/>>], [global]) of
|
case binary:split(emqx_utils_binary:trim(Path, $/), [<<$/>>], [global]) of
|
||||||
[ObjId, ObjInsId, ResId, ResInstId] -> [ObjId, ObjInsId, ResId, ResInstId];
|
[ObjId, ObjInsId, ResId, ResInstId] -> [ObjId, ObjInsId, ResId, ResInstId];
|
||||||
[ObjId, ObjInsId, ResId] -> [ObjId, ObjInsId, ResId];
|
[ObjId, ObjInsId, ResId] -> [ObjId, ObjInsId, ResId];
|
||||||
[ObjId, ObjInsId] -> [ObjId, ObjInsId];
|
[ObjId, ObjInsId] -> [ObjId, ObjInsId];
|
||||||
|
|
|
@ -335,7 +335,7 @@ remove_tmp_fields(Ref) ->
|
||||||
|
|
||||||
-spec path_list(Path :: binary()) -> {[PathWord :: binary()], [Query :: binary()]}.
|
-spec path_list(Path :: binary()) -> {[PathWord :: binary()], [Query :: binary()]}.
|
||||||
path_list(Path) ->
|
path_list(Path) ->
|
||||||
case binary:split(binary_util:trim(Path, $/), [<<$/>>], [global]) of
|
case binary:split(emqx_utils_binary:trim(Path, $/), [<<$/>>], [global]) of
|
||||||
[ObjId, ObjInsId, ResId, LastPart] ->
|
[ObjId, ObjInsId, ResId, LastPart] ->
|
||||||
{ResInstId, QueryList} = query_list(LastPart),
|
{ResInstId, QueryList} = query_list(LastPart),
|
||||||
{[ObjId, ObjInsId, ResId, ResInstId], QueryList};
|
{[ObjId, ObjInsId, ResId, ResInstId], QueryList};
|
||||||
|
@ -389,7 +389,7 @@ observe_seq(Options) ->
|
||||||
add_alternate_path_prefix(<<"/">>, PathList) ->
|
add_alternate_path_prefix(<<"/">>, PathList) ->
|
||||||
PathList;
|
PathList;
|
||||||
add_alternate_path_prefix(AlternatePath, PathList) ->
|
add_alternate_path_prefix(AlternatePath, PathList) ->
|
||||||
[binary_util:trim(AlternatePath, $/) | PathList].
|
[emqx_utils_binary:trim(AlternatePath, $/) | PathList].
|
||||||
|
|
||||||
extract_path(Ref = #{}) ->
|
extract_path(Ref = #{}) ->
|
||||||
drop_query(
|
drop_query(
|
||||||
|
|
|
@ -97,7 +97,7 @@ tlv_single_resource(BaseName, Id, Value, ObjDefinition) ->
|
||||||
[#{path => BaseName, value => Val}].
|
[#{path => BaseName, value => Val}].
|
||||||
|
|
||||||
basename(OldBaseName, _ObjectId, ObjectInstanceId, ResourceId, 3) ->
|
basename(OldBaseName, _ObjectId, ObjectInstanceId, ResourceId, 3) ->
|
||||||
case binary:split(binary_util:trim(OldBaseName, $/), [<<$/>>], [global]) of
|
case binary:split(emqx_utils_binary:trim(OldBaseName, $/), [<<$/>>], [global]) of
|
||||||
[ObjId, ObjInsId, ResId] ->
|
[ObjId, ObjInsId, ResId] ->
|
||||||
<<$/, ObjId/binary, $/, ObjInsId/binary, $/, ResId/binary>>;
|
<<$/, ObjId/binary, $/, ObjInsId/binary, $/, ResId/binary>>;
|
||||||
[ObjId, ObjInsId] ->
|
[ObjId, ObjInsId] ->
|
||||||
|
@ -113,13 +113,13 @@ basename(OldBaseName, _ObjectId, ObjectInstanceId, ResourceId, 3) ->
|
||||||
>>
|
>>
|
||||||
end;
|
end;
|
||||||
basename(OldBaseName, _ObjectId, ObjectInstanceId, _ResourceId, 2) ->
|
basename(OldBaseName, _ObjectId, ObjectInstanceId, _ResourceId, 2) ->
|
||||||
case binary:split(binary_util:trim(OldBaseName, $/), [<<$/>>], [global]) of
|
case binary:split(emqx_utils_binary:trim(OldBaseName, $/), [<<$/>>], [global]) of
|
||||||
[ObjId, ObjInsId, _ResId] -> <<$/, ObjId/binary, $/, ObjInsId/binary>>;
|
[ObjId, ObjInsId, _ResId] -> <<$/, ObjId/binary, $/, ObjInsId/binary>>;
|
||||||
[ObjId, ObjInsId] -> <<$/, ObjId/binary, $/, ObjInsId/binary>>;
|
[ObjId, ObjInsId] -> <<$/, ObjId/binary, $/, ObjInsId/binary>>;
|
||||||
[ObjId] -> <<$/, ObjId/binary, $/, (integer_to_binary(ObjectInstanceId))/binary>>
|
[ObjId] -> <<$/, ObjId/binary, $/, (integer_to_binary(ObjectInstanceId))/binary>>
|
||||||
end.
|
end.
|
||||||
% basename(OldBaseName, _ObjectId, _ObjectInstanceId, _ResourceId, 1) ->
|
% basename(OldBaseName, _ObjectId, _ObjectInstanceId, _ResourceId, 1) ->
|
||||||
% case binary:split(binary_util:trim(OldBaseName, $/), [<<$/>>], [global]) of
|
% case binary:split(emqx_utils_binary:trim(OldBaseName, $/), [<<$/>>], [global]) of
|
||||||
% [ObjId, _ObjInsId, _ResId] -> <<$/, ObjId/binary>>;
|
% [ObjId, _ObjInsId, _ResId] -> <<$/, ObjId/binary>>;
|
||||||
% [ObjId, _ObjInsId] -> <<$/, ObjId/binary>>;
|
% [ObjId, _ObjInsId] -> <<$/, ObjId/binary>>;
|
||||||
% [ObjId] -> <<$/, ObjId/binary>>
|
% [ObjId] -> <<$/, ObjId/binary>>
|
||||||
|
@ -129,7 +129,7 @@ make_path(RelativePath, Id) ->
|
||||||
<<RelativePath/binary, $/, (integer_to_binary(Id))/binary>>.
|
<<RelativePath/binary, $/, (integer_to_binary(Id))/binary>>.
|
||||||
|
|
||||||
object_id(BaseName) ->
|
object_id(BaseName) ->
|
||||||
case binary:split(binary_util:trim(BaseName, $/), [<<$/>>], [global]) of
|
case binary:split(emqx_utils_binary:trim(BaseName, $/), [<<$/>>], [global]) of
|
||||||
[ObjId] -> binary_to_integer(ObjId);
|
[ObjId] -> binary_to_integer(ObjId);
|
||||||
[ObjId, _] -> binary_to_integer(ObjId);
|
[ObjId, _] -> binary_to_integer(ObjId);
|
||||||
[ObjId, _, _] -> binary_to_integer(ObjId);
|
[ObjId, _, _] -> binary_to_integer(ObjId);
|
||||||
|
@ -137,7 +137,7 @@ object_id(BaseName) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
object_resource_id(BaseName) ->
|
object_resource_id(BaseName) ->
|
||||||
case binary:split(binary_util:trim(BaseName, $/), [<<$/>>], [global]) of
|
case binary:split(emqx_utils_binary:trim(BaseName, $/), [<<$/>>], [global]) of
|
||||||
[_ObjIdBin1] ->
|
[_ObjIdBin1] ->
|
||||||
error({invalid_basename, BaseName});
|
error({invalid_basename, BaseName});
|
||||||
[_ObjIdBin2, _] ->
|
[_ObjIdBin2, _] ->
|
||||||
|
@ -371,8 +371,8 @@ translate_element(BaseName, [Element | ElementList], Acc) ->
|
||||||
translate_element(BaseName, ElementList, NewAcc).
|
translate_element(BaseName, ElementList, NewAcc).
|
||||||
|
|
||||||
full_path(BaseName, RelativePath) ->
|
full_path(BaseName, RelativePath) ->
|
||||||
Prefix = binary_util:rtrim(BaseName, $/),
|
Prefix = emqx_utils_binary:rtrim(BaseName, $/),
|
||||||
Path = binary_util:ltrim(RelativePath, $/),
|
Path = emqx_utils_binary:ltrim(RelativePath, $/),
|
||||||
<<Prefix/binary, $/, Path/binary>>.
|
<<Prefix/binary, $/, Path/binary>>.
|
||||||
|
|
||||||
get_element_value(#{<<"t">> := Value}) -> Value;
|
get_element_value(#{<<"t">> := Value}) -> Value;
|
||||||
|
|
|
@ -386,11 +386,11 @@ is_alternate_path(LinkAttrs) ->
|
||||||
LinkAttrs
|
LinkAttrs
|
||||||
).
|
).
|
||||||
|
|
||||||
trim(Str) -> binary_util:trim(Str, $\s).
|
trim(Str) -> emqx_utils_binary:trim(Str, $\s).
|
||||||
|
|
||||||
delink(Str) ->
|
delink(Str) ->
|
||||||
Ltrim = binary_util:ltrim(Str, $<),
|
Ltrim = emqx_utils_binary:ltrim(Str, $<),
|
||||||
binary_util:rtrim(Ltrim, $>).
|
emqx_utils_binary:rtrim(Ltrim, $>).
|
||||||
|
|
||||||
get_lifetime(#{<<"lt">> := LT}) ->
|
get_lifetime(#{<<"lt">> := LT}) ->
|
||||||
case LT of
|
case LT of
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(binary_util).
|
-module(emqx_utils_binary).
|
||||||
|
|
||||||
%% copied from https://github.com/arcusfelis/binary2
|
%% copied from https://github.com/arcusfelis/binary2
|
||||||
|
|
Loading…
Reference in New Issue