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

Export decode_vec_with_len #403

Merged
merged 3 commits into from
Jan 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Export decode_vec_with_len
This is necessary to implement a custom `Decode` for `BoundedVec`. See:

paritytech/polkadot#6603 (comment)

> You want to ensure that you don't even start try decoding/allocating when the length of the vector is more than the
> allowed maximum.

> You first decode length of the vector and then early reject if that is too long.
  • Loading branch information
mrcnski committed Jan 23, 2023
commit b52f194f0a2e22d56146e9d2a4489a3edce7e9b5
4 changes: 2 additions & 2 deletions src/codec.rs
Original file line number Diff line number Diff line change
@@ -826,11 +826,11 @@ pub(crate) fn decode_array<I: Input, T: Decode, const N: usize>(input: &mut I) -
}
}

/// Decode the vec (without prepended the len).
/// Decode the vec (without a prepended len).
///
/// This is equivalent to decode all elements one by one, but it is optimized in some
/// situation.
pub(crate) fn decode_vec_with_len<T: Decode, I: Input>(
pub fn decode_vec_with_len<T: Decode, I: Input>(
input: &mut I,
len: usize,
) -> Result<Vec<T>, Error> {