-
Notifications
You must be signed in to change notification settings - Fork 95
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
Conversation
src/codec.rs
Outdated
if new_pos <= io_len { | ||
self.0.seek(SeekFrom::Start(new_pos))?; | ||
} else { | ||
self.0.seek(SeekFrom::Start(io_len))?; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Co-authored-by: Bastian Köcher <[email protected]>
user should provide their own input if they want an optimized skip
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
and implement the optimization of this PR later. paritytech/substrate#5462 |
I'll merge master once #236 is in |
Co-authored-by: David <[email protected]>
This should make use of the information providing by |
Co-authored-by: David <[email protected]>
@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. |
I haven't seen usage yet, yes, you can pick it up |
outdated, people can see the code for information if they want to pick it up again |
status:
wait on #236awaiting reviewFix #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:
(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 funcitonexact_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