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

Use base64 for serde_bytes annotated fields #109

Merged
merged 2 commits into from
Jun 14, 2018

Conversation

fengalin
Copy link
Contributor

With the following struct, small will be represented as an array of u8 and large as a base64 String.

extern crate serde_derive;

extern crate serde;
extern crate serde_bytes;

#[derive(Serialize, Deserialize)]
struct BytesStruct {
    small: Vec<u8>,
    #[serde(with = "serde_bytes")]
    large: Vec<u8>,
}

Copy link
Collaborator

@kvark kvark left a comment

Choose a reason for hiding this comment

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

I think this is a great improvement. Thank you for the PR!
We should bump the minor version of the crate for this is a breaking change, technically.
@torkleyy do you want to review as well?

Copy link
Contributor

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

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

Not very active currently. Let's bump the version and merge this :)

@fengalin
Copy link
Contributor Author

fengalin commented Jun 7, 2018

I'm glad you find this PR interesting! Is there anything I could do to help push this forward?

@kvark
Copy link
Collaborator

kvark commented Jun 8, 2018

@fengalin sorry about the wait. Please rebase in the meantime :)
@torkleyy must have just missed this. PING!

@kvark
Copy link
Collaborator

kvark commented Jun 8, 2018

oh I see the response now, oops, sorry @torkleyy :)
@fengalin please bump the minor version and rebase

@fengalin
Copy link
Contributor Author

fengalin commented Jun 8, 2018

@kvark no problem, I was just checking.
Rebased and bumped version.

Copy link
Contributor

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

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

One last concern, how can we recognize a bytes value in deserialize_any?

@fengalin
Copy link
Contributor Author

fengalin commented Jun 8, 2018

@torkleyy I'm not quite sure about this. I think base64 handling should only be selected when user explicitly uses Bytes/_buf. I'll take a deeper look at this tomorrow.

@torkleyy
Copy link
Contributor

torkleyy commented Jun 8, 2018 via email

@fengalin fengalin force-pushed the serde_bytes_base64 branch 2 times, most recently from ac9d0c5 to e4f4b4b Compare June 9, 2018 13:06
@fengalin
Copy link
Contributor Author

fengalin commented Jun 9, 2018

I marked the Value::Bytes variant as unreachable! in deserialize_any and implemented deserialize_bytes and deserialize_byte_buf. Does it address your concerns @torkleyy?

@torkleyy
Copy link
Contributor

torkleyy commented Jun 9, 2018

The problem is that this violates the following assumption:

(value -> serialization -> deserialization) == value

@fengalin
Copy link
Contributor Author

fengalin commented Jun 9, 2018

AFAIU, you will get the same value if the origin and target struct are annotated with serde_bytes or use ByteBuf. Are you saying we should use a specific notation in the serialized field to show this is base64?

@torkleyy
Copy link
Contributor

torkleyy commented Jun 9, 2018

Yes, with fields this holds, but not with ron::Value.

With the following `struct`, `small` will be represented as an array of `u8`
and `large` as a base64 `String`.

``` rust
extern crate serde_derive;

extern crate serde;
extern crate serde_bytes;

struct BytesStruct {
    small: Vec<u8>,
    #[serde(with = "serde_bytes")]
    large: Vec<u8>,
}
```
@fengalin
Copy link
Contributor Author

fengalin commented Jun 10, 2018

I think I got it:

  • Removed Bytes from Value.
  • base64 ser / de should only apply to serde_bytes annotated / typed fields now.

Copy link
Contributor

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

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

Sounds like a good solution to me! Thanks!

@torkleyy
Copy link
Contributor

@kvark Do you still approve the PR with the new changes?

@kvark
Copy link
Collaborator

kvark commented Jun 14, 2018

@fengalin thanks for your changes!
@torkleyy thanks for reviewing!
bors r=torkleyy

bors bot added a commit that referenced this pull request Jun 14, 2018
109: Use base64 for `serde_bytes` annotated fields r=torkleyy a=fengalin

With the following `struct`, `small` will be represented as an array of `u8` and `large` as a base64 `String`.

``` rust
extern crate serde_derive;

extern crate serde;
extern crate serde_bytes;

#[derive(Serialize, Deserialize)]
struct BytesStruct {
    small: Vec<u8>,
    #[serde(with = "serde_bytes")]
    large: Vec<u8>,
}
```

Co-authored-by: François Laignel <fengalin@free.fr>
@bors
Copy link
Contributor

bors bot commented Jun 14, 2018

Build succeeded

@bors bors bot merged commit c106c76 into ron-rs:master Jun 14, 2018
@fengalin fengalin deleted the serde_bytes_base64 branch June 14, 2018 15:09
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.

None yet

3 participants