Files
Uni-Lab-OS/unilabos/utils/tools.py
Xuwznln c001f6a151 v0.10.19
fast registry load

minor fix on skill & registry

stripe ros2 schema desc
add create-device-skill

new registry system backwards to yaml

remove not exist resource

new registry sys
exp. support with add device

add ai conventions

correct raise create resource error

ret info fix revert

ret info fix

fix prcxi check

add create_resource schema

re signal host ready event

add websocket connection timeout and improve reconnection logic

add open_timeout parameter to websocket connection
add TimeoutError and InvalidStatus exception handling
implement exponential backoff for reconnection attempts
simplify reconnection logic flow

add gzip

change pose extra to any

add isFlapY
2026-03-22 04:25:07 +08:00

40 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import json
from unilabos.utils.type_check import TypeEncoder, json_default
try:
import orjson
def fast_dumps(obj, **kwargs) -> bytes:
"""JSON 序列化为 bytes优先使用 orjson。"""
return orjson.dumps(obj, option=orjson.OPT_NON_STR_KEYS, default=json_default)
def fast_dumps_pretty(obj, **kwargs) -> bytes:
"""JSON 序列化为 bytes带缩进优先使用 orjson。"""
return orjson.dumps(
obj,
option=orjson.OPT_NON_STR_KEYS | orjson.OPT_INDENT_2,
default=json_default,
)
def normalize_json(info: dict) -> dict:
"""经 JSON 序列化/反序列化一轮来清理非标准类型。"""
return orjson.loads(orjson.dumps(info, default=json_default))
except ImportError:
def fast_dumps(obj, **kwargs) -> bytes: # type: ignore[misc]
return json.dumps(obj, ensure_ascii=False, cls=TypeEncoder).encode("utf-8")
def fast_dumps_pretty(obj, **kwargs) -> bytes: # type: ignore[misc]
return json.dumps(obj, indent=2, ensure_ascii=False, cls=TypeEncoder).encode("utf-8")
def normalize_json(info: dict) -> dict: # type: ignore[misc]
return json.loads(json.dumps(info, ensure_ascii=False, cls=TypeEncoder))
# 辅助函数将UUID数组转换为字符串
def uuid_to_str(uuid_array) -> str:
"""将UUID字节数组转换为十六进制字符串"""
return "".join(format(byte, "02x") for byte in uuid_array)