-
Notifications
You must be signed in to change notification settings - Fork 721
Add WebSocketFrame.reservedBits OptionSet #2971
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
Conversation
Lukasa
left a comment
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.
This mostly looks good, thanks Adam! A quick tweak on the diff.
| public struct ReservedBits: OptionSet, Sendable { | ||
| public var rawValue: UInt8 | ||
|
|
||
| public init(rawValue: UInt8) { |
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.
Let's make this @inlinable and all the static vars as well. That unlocks the meaningful performance improvement.
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 just noticed the get/set accessors on firstByte are not @inlinable. Is it worthwhile tagging all of those? eg fin, opcode
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 tagged them anyway
84e97cf to
dfe0b3e
Compare
Lukasa
left a comment
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.
Nice one, thanks Adam!
Head branch was pushed to by a user without write access
|
aargh swift-format |
Add support for treating WebSocketFrame reserved bits as an option set ### Motivation: I would like to do mask operations on the reserved bits of the WebSocketFrame eg check none are set, check only bits in a mask are set. With the current public interface it is only possible to check the state of one bit at a time. ### Modifications: Add `WebSocketFrame.ReservedBits` OptionSet Add computed member `WebSocketFrame.reservedBits` ### Result: I can now check the status of multiple bits in one operation eg `frame.reservedBits.isEmpty` `frame.reservedBits.itersection([.rsv1, .rsv2]).isEmpty` (cherry picked from commit d836385)
Add support for treating WebSocketFrame reserved bits as an option set
Motivation:
I would like to do mask operations on the reserved bits of the WebSocketFrame eg check none are set, check only bits in a mask are set. With the current public interface it is only possible to check the state of one bit at a time.
Modifications:
Add
WebSocketFrame.ReservedBitsOptionSetAdd computed member
WebSocketFrame.reservedBitsResult:
I can now check the status of multiple bits in one operation eg
frame.reservedBits.isEmptyframe.reservedBits.itersection([.rsv1, .rsv2]).isEmpty