Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling, extra fields, and error handling for IDL deserialization #53

Merged
merged 25 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions lib/serde_idl/README.adoc
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
= IDL Serialization library in Rust

== Using the library
* Serialization
* Example
[source,rust]
#[macro_use]
extern crate serde_idl;
Encode!(&42, &Some(42), &[1,2,3])
// Encode! macro expands to:
IDLBuilder::new().arg(&42).arg(&Some(42)).arg(&[1,2,3]).to_vec().unwrap(),
use serde_idl::{IDLType, Deserialize, Encode, Decode};
// Serialization
let bytes = Encode!(&[(42, "text")], &(42, "text"));
// Deserialization
Decode!(&bytes, a: Vec<(i64, &str)>, b: (i32, String));
assert_eq!(a, [(42, "text")]);
assert_eq!(b, (42i32, "text".to_string()));

* Serialize/Deserialize struct/enum
[source,rust]
#[derive(IDLType, Deserialize)]
struct List {
head: i32,
tail: Option<Box<List>>,
}
let list = List { head: 42, tail: None };
let bytes = Encode!(&list);
Decode!(&bytes, l: List);

* Derive serialization trait and inspect IDL type
* Inspect IDL type
[source,rust]
#[derive(IDLType)]
struct List { head: i32, tail: Option<Box<List>> }
let list = List { head: 42, tail: None };
assert_eq!(serde_idl::get_type(&list),
assert_eq!(List::ty(),
Type::Record(vec![
field("head", Type::Int),
field("tail", Type::Opt(Box::new(
Type::Knot(TypeId::of::<List>()))))])
);
assert_eq!(Encode!(&list),
hex::decode("4449444c026c02a0d2aca8047c90eddae704016e00002a00").unwrap());

* Deserialization
[source,rust]
let bytes = Encode!(&[(42, "text")], &(42, "text"));
assert_eq!(bytes, hex::decode("4449444c026d016c02007c0171020001012a04746578742a0474657874").unwrap());
Decode!(&bytes, a: Vec<(i64, &str)>, b: (i64, &str));
assert_eq!(a, [(42, "text")]);
assert_eq!(b, (42, "text"));

== Remaining items
* Error handling
# Limit recursion depth for deserialization
* Ignore extra fields, future values (subtype)
* Limit recursion depth for deserialization
* Support future values
* Optimize for `new struct` type
* Refactor serialization to use serde
* Import `.did` file in Rust
Expand Down
Loading