pg.utils.JSONConversionContext¶
Accessible via pg.utils.JSONConversionContext.
- class JSONConversionContext[source]¶
Bases:
pg.JSONConvertibleJSON conversion context.
JSONConversionContext is introduced to handle serialization scenarios where operations cannot be performed in a single pass. For example: Serialization and deserialization of shared objects across different locations.
# Shared object serialization/deserialization.
In PyGlove, only values referenced by pg.Ref and non-PyGlove managed objects are sharable. This ensures that multiple references to the same object are serialized only once. During deserialization, the object is created just once and shared among all references.
Classes:
ObjectEntry(value, serialized, ref_index, ...)Methods:
from_json(json_value, **kwargs)Deserializes a JSONConvertible value from JSON value.
get_shared(ref_index)Gets the shared object of a ref index.
Returns the next shared index.
serialize_maybe_shared(value[, json_fn])Track maybe shared objects and returns their JSON representation.
to_json(*, root, **kwargs)Serializes a root node with the context to JSON value.
- classmethod from_json(json_value, **kwargs)[source]¶
Deserializes a JSONConvertible value from JSON value.
- Return type:
Gets the shared object of a ref index.
- Return type:
ObjectEntry
Returns the next shared index.
- Return type:
Track maybe shared objects and returns their JSON representation.