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

Implement decode::skip #208

Closed
wants to merge 34 commits into from
Closed

Implement decode::skip #208

wants to merge 34 commits into from

Conversation

gui1117
Copy link
Contributor

@gui1117 gui1117 commented Apr 15, 2020

status: wait on #236 awaiting review
Fix #201

notes:

  • For IoReader input Seek trait is not very handy because seeking beyond the end is allowed and up to implementation. Thus we have to do 3 seek instead of one just to check that we haven't reached the end. Maybe we should remember the size of Seek in the IoReader wrapper. but maybe its size can be not fixed. I'm not sure yet about this optimisation.

  • For types such as Compact or Result or Option I wonder how I should implement skip, should skip always consider the input as valid or shouldn't it.
    if it can consider the value as always valid the following scenario can happen:

    • decoding A fails but doing on a tuple (B, A) skip B decode A succeed.
      this happens because B is invalid and because its length is variable it can make the decode A starting from an offset which result in decode A successful.
      EDIT: actually I think its fine, skip doesn't check if the value is correct, that's all.

    if this doesn't matter I have the branch https://github.com/paritytech/parity-scale-codec/compare/gui-decode-skip...gui-decode-skip-compact-optimization?expand=1

  • Also for the implementation of Vec<T>::skip I thought having a funciton exact_size() -> Option<usize> could be useful so I implemented in this branch: https://github.com/paritytech/parity-scale-codec/compare/gui-decode-skip...gui-decode-skip-with-exact-size?expand=1

@gui1117 gui1117 changed the title Implement decode::skip WIP: Implement decode::skip Jun 2, 2020
@gui1117 gui1117 changed the title WIP: Implement decode::skip Implement decode::skip Jun 2, 2020
src/codec.rs Outdated
if new_pos <= io_len {
self.0.seek(SeekFrom::Start(new_pos))?;
} else {
self.0.seek(SeekFrom::Start(io_len))?;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we throw an error here, because the user wanted to skip more bytes than available?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can see, Seek end position is not final, it can change over time, in substrate I expect our implementation to do so, seek::End(0) will return the temporar end but can grow when we read on it.
I open this issue for fixing IoReader in this regard: #212

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as follow up of #212 skip is not optimized anymore for IoReader as Read doesn't provide enough to do so.

@gui1117
Copy link
Contributor Author

gui1117 commented Aug 18, 2020

I'm not sure how to decide what to prioritize at this point if we just want to release a new major version without having to review this PR we can just add a non-optimized skip into the trait

       fn skip<I: Input>(value: &mut I) -> Result<(), Error> {
               Self::decode(value).map(|_| ())
       }

and implement the optimization of this PR later. paritytech/substrate#5462

@gui1117
Copy link
Contributor Author

gui1117 commented Jan 7, 2021

I'll merge master once #236 is in
EDIT: done

@gui1117
Copy link
Contributor Author

gui1117 commented Jan 21, 2021

This should make use of the information providing by Decode::fix_encoded_len once #243 is merged

@coriolinus
Copy link
Contributor

@thiolliere Would you like me to pick up work on this PR? It looks like it's gotten a bit stale; I don't know if it's still needed.

@gui1117
Copy link
Contributor Author

gui1117 commented Jun 24, 2021

I haven't seen usage yet, yes, you can pick it up

@gui1117
Copy link
Contributor Author

gui1117 commented Nov 2, 2024

outdated, people can see the code for information if they want to pick it up again

@gui1117 gui1117 closed this Nov 2, 2024
@gui1117 gui1117 deleted the gui-decode-skip branch November 2, 2024 03:10
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.

Add skip()
4 participants