Crates.io | postcard-bindgen-core |
lib.rs | postcard-bindgen-core |
version | |
source | src |
created_at | 2022-11-06 21:23:20.793472 |
updated_at | 2025-02-14 18:26:21.611198 |
description | A crate to generate bindings for the postcard binary format for other languages than Rust - Core Crate |
homepage | |
repository | https://github.com/teamplayer3/postcard-bindgen |
max_upload_size | |
id | 706750 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Postcard Bindgen
generates code for other languages to serialize and deserialize postcard byte format. This facilitates communication between, for example, a microcontroller and a mobile app using the postcard
crate.
Structs and enums can be annotated with PostcardBindings
to generate code. The generated code can be exported as an npm package for JavaScript or a pip package for Python.
:warning: Use rust nightly to run the crate that generates the bindings. This crate depends on genco, which uses a nightly feature.
Annotate structs and enums with Serialize
/Deserialize
from the serde crate and the PostcardBindings
macro from this crate.
The process has two steps:
Enable the
generating
feature ifpostcard-bindgen
is added as a dependency in the generation binary crate.
This example shows how to generate an npm package. The struct Test
and the generation logic are in the same Rust file.
#[derive(Serialize, PostcardBindings)]
struct Test {
name: u8,
other: u16,
}
fn main() {
javascript::build_package(
std::env::current_dir().unwrap().as_path(),
PackageInfo {
name: "generation-test".into(),
version: "0.1.0".try_into().unwrap(),
},
javascript::GenerationSettings::enable_all(),
generate_bindings!(Test),
)
.unwrap();
}
The following code can now be used to serialize an object in JavaScript.
import { serialize } from "generation-test";
const test = {
name: "test",
other: 23
}
const bytes = serialize("Test", test)
Type Name | Rust | Js | Python |
Unit Type |
|
|
|
Tuple Struct |
|
|
|
Struct |
|
|
|
Enum |
|
|
|
Option |
|
|
|
Map |
|
|
|
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Postcard Bindgen by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions