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

Expose to_hex and from_hex from impl-serde #302

Merged
merged 3 commits into from
Jan 3, 2020
Merged

Expose to_hex and from_hex from impl-serde #302

merged 3 commits into from
Jan 3, 2020

Conversation

tomusdrw
Copy link
Contributor

@tomusdrw tomusdrw commented Jan 2, 2020

Since the implementation is already there and we use impl-serde as sp_core::bytes in substrate repo it makes sense to additionally expose "raw" (i.e. non-serde-specific) to_hex/from_hex methods from that crate.

Technically we could make it a separate crate (or we did already rustc_hex?) but imho it makes sense to maintain it in a single place.

Also this PR bumps minor version of impl-serde, but does not change the versions of packages that depend on it, since no functionality is being changed there.

Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

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

LGTM modulo return value.

bytes
}
} else if bytes.is_empty() {
return "0x".into()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return "0x".into()
return "0x0".into()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But empty byte set (not uint) should be encoded as 0x not 0x0, vec![0] should have 0x00 encoding, one byte = two nibbles (always, since we don't trim zeros).

///
/// Returns an error if the string is not prefixed with `0x`
/// or non-hex characters are present.
pub fn from_hex(v: &str) -> Result<Vec<u8>, String> {
Copy link
Member

Choose a reason for hiding this comment

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

I thought you were against String error types :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you're right. I just simply extracted the method, but haven't thought of proper error type here. Let me do a follow up PR on this :)

@NikVolf NikVolf merged commit 5371e63 into master Jan 3, 2020
@NikVolf NikVolf deleted the td-hex branch January 3, 2020 07:00
dvdplm added a commit that referenced this pull request Jan 14, 2020
* master: (27 commits)
  update parity-util-mem (#309)
  Update features and feature dependencies (#307)
  Use proper memory queries to rocksdb (#308)
  Draft version updates and changelog (#299)
  Use custom error type for `from_hex` (#305)
  Fix typo. (#303)
  kvdb: remove KeyValueDBHandler (#304)
  extract common kvdb tests into a crate (#301)
  Expose to_hex and from_hex from impl-serde (#302)
  Add a top level function to parity-util-mem (#298)
  I/O statistic for key-value databases (#294)
  use for_tuples (#300)
  Add memory extensions for LRUCache, hashbrown (#293)
  Add memory stats for kvdb-s (#292)
  Provide #[derive(MallocSizeOf)] that is actually working (#291)
  Move and extend impls for locking primitives (#290)
  Update uint README (#288)
  Update README.md (#287)
  [ci]: remove feature flags in virtual workspace (#289)
  Prepare releases (#286)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants