Count 0 maximum string length for empty RPC list parameters

This commit is contained in:
Jiang Yio 2022-10-01 00:32:48 -04:00
parent 26b4a116ba
commit 17cb40f46a

4
rpc.py
View File

@ -45,9 +45,9 @@ def l_pack(value: Any, envelope: int=3, wrapped: bool=True, basictype=b'0', enco
def l_pack_maxlen(value: Any, encoding: str='latin-1'):
if isinstance(value, dict):
return max(max(l_pack_maxlen(k, encoding=encoding) for k in value.keys()), max(l_pack_maxlen(v, encoding=encoding) for v in value.values()))
return max(max(l_pack_maxlen(k, encoding=encoding) for k in value.keys()), max(l_pack_maxlen(v, encoding=encoding) for v in value.values())) if len(value) > 0 else 0
elif not isinstance(value, str) and hasattr(value, '__iter__'):
return max(len(str(max(0, len(value) - 1))), max(l_pack_maxlen(v, encoding=encoding) for v in value))
return max(len(str(len(value))), max(l_pack_maxlen(v, encoding=encoding) for v in value)) if len(value) > 0 else 0
else:
return len(str(value).encode(encoding))