serde-generate
This crate aims to compile the data formats extracted from Rust by serde_reflection
into type definitions for other programming languages.
Supported Languages
The following target languages are currently supported:
- C++ 17
- Java 8
- Python 3
- Rust 2018
Supported Encodings
Type definitions in a target language are meant to be used together with a runtime library that provides (de)serialization in a particular Serde encoding format.
This crate provides easy-to-deploy runtime libraries for the following binary formats, in all supported languages:
- Bincode,
- Libra Canonical Serialization ("LCS" for short).
Quick Start with Python and Bincode
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`. (In practice, formats are more often read from a file.)
let mut tracer = new;
tracer..unwrap;
let registry = tracer.registry.unwrap;
// Create Python class definitions.
let mut source = Vec new;
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!;
Binary Tool
In addition to a Rust library, this crate provides a binary tool serdegen
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
:
To create a python module test
and install the bincode runtime in a directory $DEST
, you may run:
See the help message of the tool with --help
for more options.
Note: Outside of this repository, you may install the tool with cargo install serde-generate
then use $HOME/.cargo/bin/serdegen
.
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.