serde-generate
This crate provides experimental code generation in several languages for the formats
extracted by serde_reflection.
Supported Languages
- Python 3
- C++ 17
- Rust 2018
Supported Encodings
The code generated by this crate is meant to be used together with a runtime that defines a particular Serde encoding format.
We currently only support binary formats similar to Bincode.
Binary Tool
Together with the library serde_generate, we provide a simple binary tool to process Serde formats
saved on disk.
Assuming that a serde_reflection::Registry object has been serialized in a YAML file test.yaml,
the following command will generate Python class definitions and write them into test.py.
See the help message of the tool with --help for more options.
Bincode Runtimes
For testing purposes, we use the Bincode encoding format provided by the
bincode crate in Rust and
provide experimental Bincode runtimes in Python and C++.
In the following example, we transfer a Test value from Rust to Python using bincode.
use ;
use ;
use Write;
// Obtain the Serde format of `Test`.
let mut tracer = new;
tracer..unwrap;
let registry = tracer.registry.unwrap;
// Create Python class definitions.
let mut source = Vecnew;
output?;
assert_eq!;
// Append some test code to demonstrate Bincode deserialization
// using the runtime in `serde_generate/runtime/python/bincode`.
writeln!?;
// Execute the Python code.
let mut child = new
.arg
.env
.stdin
.spawn?;
child.stdin.as_mut.unwrap.write_all?;
let output = child.wait_with_output?;
assert!;
Contributing
See the CONTRIBUTING file for how to help out.
License
This project is available under the terms of either the Apache 2.0 license or the MIT license.