|
|
@ -1,4 +1,5 @@ |
|
|
|
-module(tpTermCut). |
|
|
|
-include("eTpf.hrl"). |
|
|
|
|
|
|
|
%% 现在要使用硬编码的值。我们不能花时间在记录或地图中查找。 |
|
|
|
|
|
|
@ -15,8 +16,6 @@ cut(_, Depth) when Depth > ?MaxDepth -> |
|
|
|
cut(Bits, _) when is_bitstring(Bits), bit_size(Bits) > ?MaxBitSize -> |
|
|
|
<<CutBits:?MaxBinSize/binary, _/bits>> = Bits, |
|
|
|
<<CutBits/binary, "$truncated">>; |
|
|
|
cut(Term, Depth) when is_list(Term), Depth =:= ?MaxDepth -> |
|
|
|
['$truncated']; |
|
|
|
cut(Term, Depth) when is_list(Term) -> |
|
|
|
cutList(Term, Depth, 0, ?MaxListSize, 0, []); |
|
|
|
cut(Term, Depth) when is_map(Term), Depth =:= ?MaxDepth -> |
|
|
@ -33,11 +32,12 @@ cut(Term, _) -> |
|
|
|
cutList([], _, _, _, _, Acc) -> |
|
|
|
lists:reverse(Acc); |
|
|
|
cutList([Term | Tail], Depth, Len, MaxLen, NumStructs, Acc) -> |
|
|
|
case Len > MaxLen orelse NumStructs > ?MaxNestStruct of |
|
|
|
case Len >= MaxLen orelse NumStructs >= ?MaxNestStruct of |
|
|
|
true -> |
|
|
|
lists:reverse(['$truncated' | Acc]); |
|
|
|
lists:reverse(['$truncated33' | Acc]); |
|
|
|
_ -> |
|
|
|
%% if List was a cons, Tail can be anything |
|
|
|
io:format("IMY********************1111 ~p~n", [{Len, NumStructs, Term}]), |
|
|
|
cutList(Tail, Depth, Len + 1, MaxLen, NumStructs + isStruct(Term), [cut(Term, Depth + 1) | Acc]) |
|
|
|
end; |
|
|
|
cutList(Term, Depth, _, _, _, Acc) -> %% if List was a cons [[[a,a,a|b],1,2,3]|bbbb] |
|
|
|