nemoguardrails.colang.v2_x.runtime.serialization
nemoguardrails.colang.v2_x.runtime.serialization
Utilities for serializing and deserializing state objects to and from JSON.
Module Contents
Functions
Data
API
Helper to decode a hierarchy of objects to a dict.
The decoding is able to correctly restore references to the same object, using the markers with the form:
{“__type”: “ref”, “__id”: obj_id}
Parameters:
The dictionary that must be decoded.
An index with all the objects with references that have been decoded so far.
Helper to encode a hierarchy of objects to a dict.
The encoding is able to mark correctly references to the same object. When an object is encountered a second time, only a reference marker will be added:
{“__type”: “ref”, “__id”: obj_id}
Parameters:
The object that must be encoded.
An index with all the objects that have been encoded so far.
Helper to decode a State object from a JSON string.
Helper to encode a State object to a JSON string.
TODO: to make the size of the JSON even smaller, we can try to minify it.
Parameters:
The state that must be encoded.
Whether the JSON should be nicely indented.