Skip to content

Add serde Ext support for rmpv and rmps#216

Merged
kornelski merged 4 commits into3Hren:masterfrom
unrealhoang:support-serde-ext
Sep 9, 2019
Merged

Add serde Ext support for rmpv and rmps#216
kornelski merged 4 commits into3Hren:masterfrom
unrealhoang:support-serde-ext

Conversation

@unrealhoang
Copy link
Contributor

No description provided.

Copy link
Collaborator

@daboross daboross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing this!

I've included a number of comments on things I think could be cleaned up a bit. Nothing major, mostly just error messages and removing some of the code in favor of using pre-built alternatives.


Besides the existing code, do you think it'd be possible to get this working with serde_derive-created Serialize and Deserialize implementations?

It looks like it's almost possible to store ext data in something like:

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[serde(rename = "_ExtStruct")]
struct ExtStruct(i8, Vec<u8>);

I've tested it locally, and round-trip tests don't quite succeed, but I think this implementation is fairly close. If we got this working, it seems like it could make for a nicer interface. Thoughts on that?

Regardless, this looks like a good addition to me. I'm good with approving this with or without serde_derive support after fixing the other comments. Thanks!

@unrealhoang
Copy link
Contributor Author

Thank you for your very detailed review. I will fix it all and try to look at the serde_derive support.

* New Ext Data Model: _ExtStruct((tag, binary))
* Fix Review
* Add Serde Derive test
@unrealhoang
Copy link
Contributor Author

I have to change Serde Data Model of Ext to a newtype struct named _ExtStruct, so the serde representation of Ext become _ExtStruct((i8, Bytes)).
This is because, for Value and ValueRef, which rely on deserialize_any to visit the correct type, there's currently no way to communicate the seq's name from deserializer to visitor.

@unrealhoang unrealhoang requested a review from daboross September 8, 2019 15:29
Copy link
Collaborator

@daboross daboross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! Sorry I wasn't able to make a review earlier.

This is because, for Value and ValueRef, which rely on deserialize_any to visit the correct type, there's currently no way to communicate the seq's name from deserializer to visitor.

Makes sense - I'm slightly sad about making it more complex, but I think it's worth it.

Looking over this, I think all the code looks good. A few bits I might have written differently, but that isn't a bad thing.

If we fix the two code blocks in the doc-comments, I'd be happy with this. Thanks again!

@unrealhoang unrealhoang requested a review from daboross September 9, 2019 14:23
Copy link
Collaborator

@daboross daboross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM.

@daboross
Copy link
Collaborator

daboross commented Sep 9, 2019

@kornelski This looks good to me. If you're good with the addition, I'm good with merging it.

@kornelski kornelski merged commit a34ab8f into 3Hren:master Sep 9, 2019
@unrealhoang unrealhoang deleted the support-serde-ext branch September 12, 2019 02:36
vmx added a commit to vmx/serde_ipld_dagcbor that referenced this pull request Sep 25, 2019
Tags are stored as Newtype Structs with the special name `_TagStruct`. The tags
are represented as a struct tuple consisting of the tag identifier and a value.

Example:

    let tag = Value::Tag(123, Box::new(Value::Text("some value".to_string())));
    let tag_encoded = to_vec(&tag).unwrap();

This implementation is heavily based on the msgpack-rust library, when support
for extensions were added [1][2]. They have the same problem as CBOR has, that
such an extension/tagging type is not directly supported by Serde, hence a
workaround is needed. For me it makes sense to use a similarly working workaround
across different libraries.

This commit also contains an example on how to use custom types as tags. It can
be run via:

    cargo run --example tags --features tags

[1]: 3Hren/msgpack-rust@a34ab8f
[2]: 3Hren/msgpack-rust#216
vmx added a commit to vmx/serde_ipld_dagcbor that referenced this pull request Sep 25, 2019
Tags are stored as Newtype Structs with the special name `_TagStruct`. The tags
are represented as a struct tuple consisting of the tag identifier and a value.

Example:

    let tag = Value::Tag(123, Box::new(Value::Text("some value".to_string())));
    let tag_encoded = to_vec(&tag).unwrap();

This implementation is heavily based on the msgpack-rust library, when support
for extensions were added [1][2]. They have the same problem as CBOR has, that
such an extension/tagging type is not directly supported by Serde, hence a
workaround is needed. For me it makes sense to use a similarly working workaround
across different libraries.

This commit also contains an example on how to use custom types as tags. It can
be run via:

    cargo run --example tags --features tags

[1]: 3Hren/msgpack-rust@a34ab8f
[2]: 3Hren/msgpack-rust#216
vmx added a commit to vmx/serde_ipld_dagcbor that referenced this pull request Sep 25, 2019
Tags are stored as Newtype Structs with the special name `_TagStruct`. The tags
are represented as a struct tuple consisting of the tag identifier and a value.

Example:

    let tag = Value::Tag(123, Box::new(Value::Text("some value".to_string())));
    let tag_encoded = to_vec(&tag).unwrap();

This implementation is heavily based on the msgpack-rust library, when support
for extensions were added [1][2]. They have the same problem as CBOR has, that
such an extension/tagging type is not directly supported by Serde, hence a
workaround is needed. For me it makes sense to use a similarly working workaround
across different libraries.

This commit also contains an example on how to use custom types as tags. It can
be run via:

    cargo run --example tags --features tags

[1]: 3Hren/msgpack-rust@a34ab8f
[2]: 3Hren/msgpack-rust#216
vmx added a commit to vmx/serde_ipld_dagcbor that referenced this pull request Sep 25, 2019
Tags are stored as Newtype Structs with the special name `_TagStruct`. The tags
are represented as a struct tuple consisting of the tag identifier and a value.

Example:

    let tag = Value::Tag(123, Box::new(Value::Text("some value".to_string())));
    let tag_encoded = to_vec(&tag).unwrap();

This implementation is heavily based on the msgpack-rust library, when support
for extensions were added [1][2]. They have the same problem as CBOR has, that
such an extension/tagging type is not directly supported by Serde, hence a
workaround is needed. For me it makes sense to use a similarly working workaround
across different libraries.

This commit also contains an example on how to use custom types as tags. It can
be run via:

    cargo run --example tags --features tags

[1]: 3Hren/msgpack-rust@a34ab8f
[2]: 3Hren/msgpack-rust#216
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 this pull request may close these issues.

3 participants