|
| 1 | +Mapry |
| 2 | +===== |
| 3 | + |
| 4 | +!!! THIS IS WORK IN PROGRESS. PLEASE DO NOT USE YET !!! |
| 5 | + |
| 6 | +Mapry generates polyglot code for de/serializing object graphs in JSON format. |
| 7 | + |
| 8 | +**Use case**. We needed a yet another domain-specific language for system configuration. The existing solutions |
| 9 | +mostly focused on modeling the configuration as *object trees* in which the configuration is structured hierarchically |
| 10 | +with no cross-references between the objects. We found this structure to be hihgly limiting for most of the complex |
| 11 | +system configuration which required objects to be referenced among each other. |
| 12 | + |
| 13 | +We wanted the serialization itself to be readable so that an operator can edit it using a simple text editor. JSON |
| 14 | +offered itself as a good fit there with a lot of existing assistance tools. |
| 15 | + |
| 16 | +We decided against a NoSQL database as these add an administration burden which is justifyable for dynamic system, but |
| 17 | +we found that burden completely unnecessary for rather static structures such as configuration. |
| 18 | + |
| 19 | +Hence we developed a generator that produces code to de/serialize **object graphs** from **readable JSON files**. |
| 20 | + |
| 21 | +**Maintainability**. We wanted to facilitate maintainability of the system through static checks so that most errors |
| 22 | +in the object graphs are registered prior to the deployment in the production. These checks include strong typing, |
| 23 | +dangling references and certain value checks (*e.g.*, range checks, minimum number of elements in containers *etc*.). |
| 24 | + |
| 25 | +The **schema** of the object graph is stored in a separate JSON file and defines all the data types used in the object |
| 26 | +graph including the object graph itself. |
| 27 | + |
| 28 | +**Code readability over speed**. We wanted the generated code to be rather readable than fast. |
| 29 | +Though the users do not care about the implementation details most of the time, newcomers really like to peek under |
| 30 | +the hub. We found that its much easier for them to get up to speed when the generated code is well-readable. |
| 31 | + |
| 32 | +This is particularly important when the code serialization tool permeates most of your system components. |
| 33 | + |
| 34 | +**Supported languages**. Currently, Mapry speaks C++, Python and Go. |
| 35 | + |
| 36 | + |
| 37 | +We were not happy with the existing de/serializers: |
| 38 | + |
| 39 | +* Proto3 and Cap'n proto can not handle object graphs (only object trees). |
| 40 | +* Flatbuffers do not handle JSON. |
| 41 | +* Boost serialization does not handle JSON nicely. Additionally, its XML format is not really human-readable. |
| 42 | +* ThorsSerializer produces unreadable JSON files. |
| 43 | + |
| 44 | +Installation |
| 45 | +============ |
| 46 | + |
| 47 | +* Create a virtual environment: |
| 48 | + |
| 49 | +.. code-block:: bash |
| 50 | +
|
| 51 | + python3 -m venv venv3 |
| 52 | +
|
| 53 | +* Activate it: |
| 54 | + |
| 55 | +.. code-block:: bash |
| 56 | +
|
| 57 | + source venv3/bin/activate |
| 58 | +
|
| 59 | +* Install mapry with pip: |
| 60 | + |
| 61 | +.. code-block:: bash |
| 62 | +
|
| 63 | + pip3 install mapry |
| 64 | +
|
| 65 | +Development |
| 66 | +=========== |
| 67 | + |
| 68 | +* Check out the repository. |
| 69 | + |
| 70 | +* In the repository root, create the virtual environment: |
| 71 | + |
| 72 | +.. code-block:: bash |
| 73 | +
|
| 74 | + python3 -m venv venv3 |
| 75 | +
|
| 76 | +* Activate the virtual environment: |
| 77 | + |
| 78 | +.. code-block:: bash |
| 79 | +
|
| 80 | + source venv3/bin/activate |
| 81 | +
|
| 82 | +* Install the development dependencies: |
| 83 | + |
| 84 | +.. code-block:: bash |
| 85 | +
|
| 86 | + pip3 install -e .[dev] |
| 87 | +
|
| 88 | +* Run `precommit.py` to execute pre-commit checks locally. |
0 commit comments