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

derive Serialize Deserialize macros #4

Open
xlc opened this issue Nov 26, 2019 · 4 comments · May be fixed by #13
Open

derive Serialize Deserialize macros #4

xlc opened this issue Nov 26, 2019 · 4 comments · May be fixed by #13

Comments

@xlc
Copy link
Owner

xlc commented Nov 26, 2019

Add derive macro to for auto serialization and deserialization implementation generation.

@jimmychu0807
Copy link

@xlc I want to try to tackle this issue.

Currently, I am using code here to get a certain value/object out from JsonValue. But this is kind of tedious. Will be nice if we can do something like what serde does.

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let point = Point { x: 1, y: 2 };

    let serialized = serde_json::to_string(&point).unwrap();
    println!("serialized = {}", serialized);

    let deserialized: Point = serde_json::from_str(&serialized).unwrap();
    println!("deserialized = {:?}", deserialized);

     // So in lite-json
    let deserialized2: Point = lite_json::parse_json(&serialized).unwrap().deserialize().unwrap();
}

I am still not sure about the implementation yet. How hard would it be to do something like this in no_std env?

@xlc xlc linked a pull request Apr 18, 2020 that will close this issue
@xlc
Copy link
Owner Author

xlc commented Apr 18, 2020

@jimmychu0807 I have started it at #13 and you are welcome to finish it. You can PR into derive branch.

Current status is it compiles, but I never ran it once so likely missing a lot of details.

The code is heavily inspired by parity-scale-codec.

@jimmychu0807
Copy link

Thanks. Let me take a look

@justinfrevert
Copy link

I would love to see this 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants