|
10 | 10 | - **Metadata Inclusion**: Automatically includes metadata in the YAML, eliminating the need for users to manually identify the correct type when importing JSON data, ensuring seamless (de-)serialization.
|
11 | 11 | - **Custom Transformations**: Allows for hooking in custom transformations so that users can work with familiar formats (e.g., dates or coordinate representations) instead of thinking in unfamiliar formats.
|
12 | 12 |
|
| 13 | +## Design Principles |
| 14 | + |
| 15 | +1. **Transparency Over Magic**: |
| 16 | + - Prioritize clear and understandable processes. For example, users can fully render the YAML to see the actual data conforming to the underlying zserio schema. |
| 17 | + - This approach avoids black-box conversions, simplifying debugging and ensuring user confidence in the data. |
| 18 | + |
| 19 | +2. **Accessibility and Simplicity**: |
| 20 | + - Make the tool easy to use and understand, even for beginners. |
| 21 | + - Features are designed with simplicity in mind. For instance, we use string-only templates as one way to keep things straightforward. |
| 22 | + |
| 23 | +3. **Performance for Trusted Sources**: |
| 24 | + - Optimize for performance, assuming trusted YAML sources. |
| 25 | + - Faster processing is crucial for rapid iterations and maintaining workflow. |
| 26 | + |
| 27 | +4. **Flexibility Within Simplicity**: |
| 28 | + - While maintaining a simple core, provide powerful features like YAML imports, built-in and custom transformations, and basic templating. |
| 29 | + - This balance allows for adaptability to various use cases without compromising ease of use. |
| 30 | + |
| 31 | +## Installation |
| 32 | + |
| 33 | +Install `zs-yaml` using pip: |
| 34 | + |
| 35 | +```bash |
| 36 | +python -m pip install --upgrade zs-yaml |
| 37 | +``` |
| 38 | + |
| 39 | +## Usage |
| 40 | + |
| 41 | +The main entry point for the application is `zs-yaml`. It accepts arguments for specifying the input and output file paths. You can run the application as follows: |
| 42 | + |
| 43 | +```bash |
| 44 | +zs-yaml input.yaml output.bin |
| 45 | +zs-yaml input.bin output.yaml |
| 46 | +``` |
| 47 | + |
| 48 | +### Notes |
| 49 | + |
| 50 | +- You have to use the exact same order of fields in the YAML as defined by the zserio schema, because zserio expects this. |
| 51 | +- When converting from binary to YAML, the target YAML file must already exist and contain the necessary metadata. |
| 52 | +- The minimal metadata content in the target YAML file should be: |
| 53 | + |
| 54 | +```yaml |
| 55 | +_meta: |
| 56 | + schema_module: <module_name> |
| 57 | + schema_type: <type_name> |
| 58 | +``` |
| 59 | +
|
| 60 | +### Initialization Arguments |
| 61 | +
|
| 62 | +Some Zserio types require additional arguments during initialization, either when deserializing from binary or when creating objects from JSON. To support these types, you can specify initialization arguments in the `_meta` section of your YAML file: |
| 63 | + |
| 64 | +```yaml |
| 65 | +_meta: |
| 66 | + schema_module: <module_name> |
| 67 | + schema_type: <type_name> |
| 68 | + initialization_args: |
| 69 | + - <arg1> |
| 70 | + - <arg2> |
| 71 | + # ... more arguments as needed |
| 72 | +``` |
| 73 | + |
| 74 | +**Hint:** At the moment only plain values are supported, although zserio supports also compound values as args. |
| 75 | +Support for these may be added in the future. |
| 76 | + |
| 77 | +These arguments will be passed to the appropriate Zserio functions: |
| 78 | +- `zserio.deserialize_from_file()` when converting from binary to YAML |
| 79 | +- `zserio.from_json_file()` when converting from YAML to binary |
| 80 | + |
| 81 | +For example: |
| 82 | + |
| 83 | +```yaml |
| 84 | +_meta: |
| 85 | + schema_module: my_schema |
| 86 | + schema_type: MyType |
| 87 | + initialization_args: |
| 88 | + - 0xAB |
| 89 | + - 42 |
| 90 | +
|
| 91 | +# ... rest of your YAML data |
| 92 | +``` |
| 93 | + |
| 94 | +In this example, `0xAB` and `42` will be passed as additional arguments to the initialization functions. |
| 95 | + |
| 96 | +This feature ensures that types requiring additional initialization parameters can be properly handled in both directions of conversion (YAML to binary and binary to YAML). |
| 97 | + |
13 | 98 | ## Example
|
14 | 99 |
|
15 | 100 | ### Zserio Schema Module Creation
|
@@ -60,8 +145,9 @@ Using **zs-yaml**, you can define the same data in a more human-readable YAML fo
|
60 | 145 | ```yaml
|
61 | 146 | # 1) Metadata is used to specify the type needed for
|
62 | 147 | # (de-)serialization and custom transform functions
|
63 |
| -# 2) User are free to use their preferred date format |
| 148 | +# 2) Users are free to use their preferred date format |
64 | 149 | # for the birth data as the a normalization function
|
| 150 | +# (defined in the referenced `transformations.py`) |
65 | 151 | # get invoked.
|
66 | 152 | # 3) Yaml allows avoiding clutter and adding comments
|
67 | 153 | # like this one :)
|
@@ -114,39 +200,18 @@ After you have installed `zs-yaml`, call `zs-yaml` to convert your YAML file to
|
114 | 200 | zs-yaml person.yaml person.bin
|
115 | 201 | ```
|
116 | 202 |
|
117 |
| -## Installation |
118 |
| - |
119 |
| -Currently, the Python package is only available at test.pypi. Once the official release is available, |
120 |
| -you can install the package without specifying an index URL. |
121 |
| - |
122 |
| -```bash |
123 |
| -python -m pip install --upgrade zs-yaml |
124 |
| -``` |
125 |
| - |
126 |
| -## Usage |
127 |
| - |
128 |
| -The main entry point for the application is `main.py`. It accepts arguments for specifying the input and output file paths. You can run the application as follows: |
129 |
| - |
130 |
| -```bash |
131 |
| -zs-yaml input.yaml output.bin |
132 |
| -zs-yaml input.bin output.yaml |
133 |
| -``` |
134 |
| - |
135 |
| -### Notes |
| 203 | +## Built-in Transformations |
136 | 204 |
|
137 |
| -- You have to use the exact same order of field in the yaml as defined by the zserio schema, because zserio expects this |
138 |
| -- When converting from binary to YAML, the target YAML file must already exist and contain the necessary metadata. |
139 |
| -- The minimal metadata content in the target YAML file should be: |
| 205 | +zs-yaml comes with several built-in transformation functions that can be used in your YAML files. Here's a brief overview of the available functions: |
140 | 206 |
|
141 |
| -```yaml |
142 |
| -_meta: |
143 |
| - schema_module: <module_name> |
144 |
| - schema_type: <type_name> |
145 |
| -``` |
| 207 | +- `insert_yaml_as_extern`: Includes external YAML content by transforming it to JSON and using zserio. |
| 208 | +- `insert_yaml`: Inserts YAML content directly from an external file. |
| 209 | +- `repeat_node`: Repeats a specific node a specified number of times. |
| 210 | +- `extract_extern_as_yaml`: Extracts binary data and saves it as an external YAML file. |
146 | 211 |
|
147 |
| -### Future Considerations |
| 212 | +For more detailed information about these functions and their usage, please refer to the [built_in_transformations.py](https://github.com/ndsev/zs_yaml/blob/main/zs_yaml/built_in_transformations.py) source file. |
148 | 213 |
|
149 |
| -In the future, we may consider using YAML tags for a more integrated approach to handling transformations directly within the YAML files, simplifying syntax and enhancing readability. |
| 214 | +Note: We plan to implement automatic source documentation generation in a future release, which will provide more comprehensive information about these functions and their parameters. |
150 | 215 |
|
151 | 216 | ## Project Structure
|
152 | 217 |
|
|
0 commit comments