refactor(framing): replace Sv2Frame dual-Option fields with FrameBody enum#2128
Open
ThomsenDrake wants to merge 1 commit intostratum-mining:mainfrom
Open
Conversation
… enum (fixes stratum-mining#2111) Eliminates the dual-Option pattern (payload + serialized) in Sv2Frame by introducing a type-safe FrameBody enum (Payload(T) | Serialized(B)). This removes 3 'Impossible state' panic branches from serialize(), encoded_length(), and makes the internal state impossible by construction. Also fixes stratum-mining#2112: get_header() now returns Header directly (always present). Fixes stratum-mining#2113: HandShakeFrame::from_bytes() now returns Self directly (always succeeded, Result was unnecessary). All 9 tests pass (3 framing + 6 codec, default + with_buffer_pool).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2111, #2112, #2113
Summary
Replaces
Sv2Frame<T, B>'s dualOption<T>+Option<B>fields with a type-safeFrameBody<T, B>enum (Payload(T) | Serialized(B)). This makes the invariant that exactly one of payload/serialized is present impossible to violate by construction, eliminating 3panic!("Impossible state")branches.Changes
Core refactor (fixes #2111)
FrameBody<T, B>enum withPayload(T)andSerialized(B)variantsSv2Frame<T, B>now uses a singlebody: FrameBody<T, B>fieldserialize(),encoded_length()are now exhaustive matches (no panic branches)map()updated to match on body variantsAPI soundness (fixes #2112)
Sv2Frame::get_header()now returnsHeaderdirectly (wasOption<Header>— always returnedSome)API soundness (fixes #2113)
HandShakeFrame::from_bytes()now returnsSelfdirectly (wasResult<Self, isize>— always returnedOk)Testing
All 9 tests pass: