import orjson
from kombu.serialization import register


def orjson_dumps(obj):
    return orjson.dumps(obj, option=orjson.OPT_NON_STR_KEYS).decode("utf-8")


def orjson_loads(data):
    if isinstance(data, str):
        data = data.encode("utf-8")
    return orjson.loads(data)


def register_orjson():
    register(
        "orjson",
        orjson_dumps,
        orjson_loads,
        content_type="application/json",
        content_encoding="utf-8",
    )
