WolframModel.Serializer (WolframModel v1.4.0)

Copy Markdown View Source

JSON serialization and deserialization for WolframModel.

Handles all internal types (atoms, tuples, MapSet) that do not have a native JSON representation.

Vertex encoding

Vertices are encoded as follows inside JSON arrays / objects:

Elixir typeJSON representation
integerJSON number
atom["a", "name"]
{atom, gen, id} tuple["v", "name", gen, id]
{atom, offset} tuple["c", "name", offset]

The id_generator field (a function) is not serialized. When a model is loaded it defaults to WolframModel.default_id_gen/0.

Summary

Functions

Deserializes a WolframModel from a JSON file at path.

Serializes a WolframModel to a pretty-printed JSON file at path.

Functions

load(path)

@spec load(Path.t()) :: {:ok, WolframModel.t()} | {:error, term()}

Deserializes a WolframModel from a JSON file at path.

Returns {:ok, model} on success or {:error, reason} on failure.

save(model, path)

@spec save(WolframModel.t(), Path.t()) :: :ok | {:error, term()}

Serializes a WolframModel to a pretty-printed JSON file at path.

Returns :ok on success or {:error, reason} on failure.