Skip to content

feat(support): Parity SCALE Codec#171

Merged
recmo merged 11 commits intorecmo:mainfrom
shekhirin:parity-scale-codec
Oct 24, 2022
Merged

feat(support): Parity SCALE Codec#171
recmo merged 11 commits intorecmo:mainfrom
shekhirin:parity-scale-codec

Conversation

@shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Oct 18, 2022

Motivation

Implement SCALE codec for Uint along with the compact types.

Solution

Most of the compact encoding implementation is from https://github.com/paritytech/parity-scale-codec/blob/ca03f7fd981855b7cd6348fe32a9831e8e142813/src/compact.rs, but adapted to work with bits number other than power of 2 and up to 536 (according to the spec) instead of 128.

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

@shekhirin shekhirin requested a review from recmo as a code owner October 18, 2022 18:07
@shekhirin shekhirin changed the title feat(support): parity-scale-codec::{Encode|Decode} feat(support): parity-scale-codec::{Encode|Decode} Oct 18, 2022
@shekhirin shekhirin marked this pull request as draft October 18, 2022 21:21
@shekhirin shekhirin changed the title feat(support): parity-scale-codec::{Encode|Decode} feat(support): parity-scale-codec Oct 19, 2022
@shekhirin shekhirin changed the title feat(support): parity-scale-codec feat(support): Parity SCALE codec Oct 19, 2022
@shekhirin shekhirin changed the title feat(support): Parity SCALE codec feat(support): Parity SCALE Codec Oct 19, 2022
@shekhirin shekhirin marked this pull request as ready for review October 20, 2022 16:30
@shekhirin
Copy link
Collaborator Author

@recmo fyi it's ready for review

Copy link
Owner

@recmo recmo left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for the contribution!

}
}

// TODO: Use nightly generic const expressions to validate that BITS parameter is less than 536
Copy link
Owner

Choose a reason for hiding this comment

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

A workaround is to add assert!(BITS < 536)s in the constructs. Since this is const it will optimize away if everything is good. If the users makes a mistake, it will panic the moment a type is constructed. Presumably the users will at least construct the type during testing.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, you have this with assert_compact_supported, I would add it to the From construtors too.

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.

2 participants