o
    YÛ·iž	  ã                   @  sJ   d Z ddlmZ ddlmZ ddlmZ dddd„Zddd„ZddgZ	dS )a  Utilities for serializing and deserializing FFI object graphs.

These helpers produce a stable JSON graph representation that preserves
object identity and references. It is useful for debugging and for
lightweight persistence when pickling is not available.
é    )Úannotations)ÚAnyé   )Ú_ffi_apiNÚobjr   Úmetadataúdict[str, Any] | NoneÚreturnÚstrc                 C  s   t  | |¡S )a©  Dump an object to a JSON graph string.

    The JSON graph is a textual representation of the object graph that
    preserves shared references. It can be used for debugging or simple
    persistence.

    Parameters
    ----------
    obj
        The object to save.

    metadata
        Extra metadata to save into the json graph string.

    Returns
    -------
    json_str
        The JSON graph string.

    Examples
    --------
    .. code-block:: python

        import tvm_ffi

        a = tvm_ffi.convert([1, 2, 3])
        s = tvm_ffi.serialization.to_json_graph_str(a)
        b = tvm_ffi.serialization.from_json_graph_str(s)
        assert list(b) == [1, 2, 3]

    )r   ÚToJSONGraphString)r   r   © r   úK/home/ubuntu/vllm_env/lib/python3.10/site-packages/tvm_ffi/serialization.pyÚto_json_graph_str   s    r   Újson_strc                 C  s
   t  | ¡S )aM  Load an object from a JSON graph string.

    The JSON graph string is produced by :py:func:`to_json_graph_str` and
    can be converted back into the corresponding FFI-backed objects.

    Parameters
    ----------
    json_str
        The JSON graph string to load.

    Returns
    -------
    obj
        The loaded object.

    )r   ÚFromJSONGraphString)r   r   r   r   Úfrom_json_graph_strB   s   
r   )N)r   r   r   r   r	   r
   )r   r
   r	   r   )
Ú__doc__Ú
__future__r   Útypingr   Ú r   r   r   Ú__all__r   r   r   r   Ú<module>   s   
#