-
Notifications
You must be signed in to change notification settings - Fork 59
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 scale-codec for Multihash
#140
Conversation
@vmx PTAL |
@koushiro I know very little about the scale-codec, I haven't really used it. Could you perhaps put some information into the commit message why it is a breaking change? |
BREAKING CHANGE: Write the digest of multihash directly to dest when encoding multihash, since we have known the size of digest. We do not choose to encode &[u8] directly, because it will add extra bytes (the compact length of digest) at the beinging of encoding result. For a valid multihash, the length of digest must equal to `size` field of multihash. Therefore, we can only read raw bytes whose length is equal to `size` when decoding. And the digest of Multihash<U64> is of type [u8; 64], taking Code::Sha2_256 as an example, if the digest is treated as &[u8] when encoding, useless data will be added to the encoding result. Signed-off-by: koushiro <[email protected]>
Updated, and you could compare the difference between the encoding results of multihash in |
@vmx What do you think? Any suggestions? |
Example:
Before:
After:
|
Sorry for the delay, and thanks for providing an example, that was really helpful. |
Ok, thanks! |
@koushiro sorry for the delay. 0.15 is now released. |
The number of digest bytes written needs to match the size. See the upstream issue here: multiformats/rust-multihash#140 The one change is to not allocate.
The number of digest bytes written needs to match the size. See the upstream issue here: multiformats/rust-multihash#140 All credit goes to @koushiro. My one change is to not allocate.
The number of digest bytes written needs to match the size. See the upstream issue here: multiformats/rust-multihash#140 All credit goes to @koushiro. My one change is to not allocate.
waiting for #139 to be merged firstlyThis PR is a breaking change.
BREAKING CHANGE: Write the digest of multihash directly to dest when encoding multihash, since we have known the size of digest.
We do not choose to encode &[u8] directly, because it will add extra bytes
(the compact length of digest) at the beinging of encoding result.
For a valid multihash, the length of digest must equal to
size
field of multihash.Therefore, we can only read raw bytes whose length is equal to
size
when decoding.And the digest of Multihash<U64> is of type [u8; 64], taking Code::Sha2_256 as an example,
if the digest is treated as &[u8] when encoding, useless data will be added to
the encoding result.