-
Notifications
You must be signed in to change notification settings - Fork 143
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
Simplify and encapsulate ReadDecoder
implementation
#523
Simplify and encapsulate ReadDecoder
implementation
#523
Conversation
Before this commit calling `Reader.finish` a 2nd time would return a random, accidental error (`UnexpectedEof`), because of how `StreamingDecoder`'s `state` is set after processing the `IEND` chunk. After this commit, `Reader.finish` will handle this condition explicitly, in a similar same way to how `next_frame` handles being called when we have already consumed all the frames.
After a recent commit, all public APIs of a `Reader` take care of not going beyond the `IEND` chunk and returning `PolledAfterEndOfImage` instead. This means that tracking `at_eof` at the level of `ReadDecoder` is obsolete and leads to unnecessary complexity. This commit refactors away this complexity.
`ReadDecoder::finish_decoding` now reuses `decode_next` instead of duplicating some of its code. Some duplication (e.g. handling of `Decoded::Nothing` remains - this will be taken care of in a subsequent commit).
This commit means that `decode_next` can be a private method of `ReadDecoder` (this is not enforced yet, before a subsequent commit moves `ReadDecoder` into a separate `mod`ule).
Before this commit `fn decode_next` would `loop` to skip `Decoded::Nothing` events. This is unnecessary, because all the callers of `decode_next` already account for `Decoded::Nothing` (explicitly or implicitly via a wildcard).
This commit helps to keep some aspects of `ReadDecoder` private (e.g. its fields, `decode_next` methods, etc.). This commit also means that `mod.rs` no longer directly depends on `Decoded` nor `StreamingDecoder`.
8e0f284
to
2fb4b8e
Compare
My appologies for the force push above. I've realized that in the last commit (when moving some of the code into the new file) I didn't preserve the comment tweaks that I've made in the earlier commits after a self-review... |
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.
I think this is a positive change
BTW, I've redesigned the same bits in the |
Hello!
This PR isn't strictly necessary for any major feature requests or bug fixes, but I think that this PR is still desirable - I think the resulting encapsulation helps with readability of the code.
I hope that splitting this PR into smaller, granular commits helps to follow along and review the changes.
PTAL?