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

fix bincode serialization #223

Merged
merged 4 commits into from
Aug 3, 2023
Merged

fix bincode serialization #223

merged 4 commits into from
Aug 3, 2023

Conversation

Wollac
Copy link
Contributor

@Wollac Wollac commented Aug 2, 2023

Motivation

Fixes bincode deserialization of FixedBytes and Bytes.

Solution

Distinguish between is_human_readable and not also in the deserialization. If it is not human readable (e.g. bincode) allow only bytes instead of also strings.
This fixes #221 .

Added tests for the bincode roundtrip that previously failed.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

LGTM after nit and rebase to fix clippy

}
}

#[cfg(test)]
mod tests {
use super::*;
use bincode as _;
Copy link
Member

@DaniPopes DaniPopes Aug 2, 2023

Choose a reason for hiding this comment

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

Nit: I don't think this does anything (same in ../bits)

Suggested change
use bincode as _;

Copy link
Contributor Author

@Wollac Wollac Aug 2, 2023

Choose a reason for hiding this comment

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

Without those I got

warning: external crate `bincode` unused in `alloy_primitives`: remove the dependency or add `use bincode as _;`

when building the tests without the serde feature.
I don't know how to avoid this warning. Is there a better way?

Copy link
Member

@DaniPopes DaniPopes Aug 2, 2023

Choose a reason for hiding this comment

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

Ah I see, it's fine then. I think the problem is that it gets included in the test binaries but not in the library, so it flags it as unused in the library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we decided to have the use in? In both places?
What I don't really understand is why the same is not needed for serde_json. Seems like it's only used in the serde tests as well...

Copy link
Member

Choose a reason for hiding this comment

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

It is:

// Used in Serde tests.
#[cfg(test)]
use serde as _;
#[cfg(test)]
use serde_json as _;

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

Thanks!

@DaniPopes DaniPopes merged commit 58e2259 into alloy-rs:main Aug 3, 2023
17 of 18 checks passed
@DaniPopes DaniPopes mentioned this pull request Aug 3, 2023
3 tasks
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.

[Bug] bincode deserialization fails for fixed-size byte arrays
3 participants