|
|
@ -11,28 +11,28 @@ |
|
|
|
cut(Term) -> |
|
|
|
cut(Term, 1). |
|
|
|
|
|
|
|
cut(_, Depth) when Depth > ?MaxDepth -> |
|
|
|
cut(_, Depth) when Depth > ?tcmDepth -> |
|
|
|
'$truncated11'; |
|
|
|
cut(Bits, _) when is_bitstring(Bits), bit_size(Bits) > ?MaxBitSize -> |
|
|
|
<<CutBits:?MaxBinSize/binary, _/bits>> = Bits, |
|
|
|
cut(Bits, _) when is_bitstring(Bits), bit_size(Bits) > ?tcmBitSize -> |
|
|
|
<<CutBits:?tcmBitSize/binary, _/bits>> = Bits, |
|
|
|
<<CutBits/binary, "$truncated">>; |
|
|
|
cut(Term, Depth) when is_list(Term) -> |
|
|
|
cutList(Term, Depth, 0, ?MaxListSize, 0, []); |
|
|
|
cut(Term, Depth) when is_map(Term), Depth =:= ?MaxDepth -> |
|
|
|
cutList(Term, Depth, 0, ?tcmListSize, 0, []); |
|
|
|
cut(Term, Depth) when is_map(Term), Depth =:= ?tcmDepth -> |
|
|
|
#{'$truncated' => '$truncated'}; |
|
|
|
cut(Term, Depth) when is_map(Term) -> |
|
|
|
maps:from_list(cutMap(maps_to_list(Term, ?MaxMapSize), Depth, 0)); |
|
|
|
cut(Term, Depth) when is_tuple(Term), Depth =:= ?MaxDepth -> |
|
|
|
maps:from_list(cutMap(maps_to_list(Term, ?tcmMapSize), Depth, 0)); |
|
|
|
cut(Term, Depth) when is_tuple(Term), Depth =:= ?tcmDepth -> |
|
|
|
{'$truncated'}; |
|
|
|
cut(Term, Depth) when is_tuple(Term) -> |
|
|
|
list_to_tuple(cutList(tuple_to_list(Term), Depth, 0, ?MaxTupleSize, 0, [])); |
|
|
|
list_to_tuple(cutList(tuple_to_list(Term), Depth, 0, ?tcmTupleSize, 0, [])); |
|
|
|
cut(Term, _) -> |
|
|
|
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 >= ?tcmNestStruct of |
|
|
|
true -> |
|
|
|
lists:reverse(['$truncated33' | Acc]); |
|
|
|
_ -> |
|
|
@ -45,7 +45,7 @@ cutList(Term, Depth, _, _, _, Acc) -> %% if List was a cons [[[a,a,a|b],1,2,3]| |
|
|
|
|
|
|
|
cutMap([], _, _) -> |
|
|
|
[]; |
|
|
|
cutMap(_, _, NumStructs) when NumStructs > ?MaxNestStruct -> |
|
|
|
cutMap(_, _, NumStructs) when NumStructs > ?tcmNestStruct -> |
|
|
|
[{'$truncated', '$truncated'}]; |
|
|
|
cutMap([{Key, Value} | Tail], Depth, NumStructs) -> |
|
|
|
AddStruct = isStruct(Key) + isStruct(Value), |
|
|
|