DataDecoder
- class compas.data.DataDecoder[source]
Bases:
JSONDecoderData decoder for custom JSON serialization with support for COMPAS data structures and geometric primitives.
The decoder hooks into the JSON deserialisation process to reconstruct
compas.data.Dataobjects, such as geometric primitives and shapes, data structures, robots, …, from the serialized data when possible.The reconstruction is possible if
the serialized data has the following structure:
{"dtype": "...", 'data': {...}};a class can be imported into the current scope from the info in
o["dtype"]; andthe imported class has a method
__from_data__.
See also
Examples
Explicit use case.
>>> import json >>> from compas.data import DataDecoder >>> with open('point.json', 'r') as f: ... point = json.load(f, cls=DataDecoder) ...
Implicit use case.
>>> from compas.data import json_load >>> point = json_load('point.json')
Methods
Reconstruct a deserialized object.
Inherited Methods
Return the Python representation of
s(astrinstance containing a JSON document).Decode a JSON document from
s(astrbeginning with a JSON document) and return a 2-tuple of the Python representation and the index inswhere the document ended.