verbs.utils.cache_to_json#

cache_to_json(cache: Tuple[int, int, List[Tuple[bytes, Tuple[bytes, int, bytes, bytes]]], List[Tuple[bytes, bytes, bytes]]]) List[source]#

Convert a request cache to a JSON compatible data-structure

Converts a cache of data requests from a fork-env (generated using verbs.envs.ForkEnv.export_cache()) into a JSON friendly data structure, i.e. it converts tuples to lists and bytes to hex strings.

Examples

env = verbs.envs.ForkEnv(...)
cache = env.export_cache()
cache_json = verbs.utils.cache_to_json(cache)
# Can now export the cache to a JSON file
Parameters:

cache (verbs.types.Cache) – Cache generated using verbs.envs.ForkEnv.export_cache().

Returns:

list – JSON compatible data structure with bytes replaces with corresponding hex string.