mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
Motivation: WebSocketOpcode was made an enumeration to make it possible to cleanly switch over the values in switch statements. However, this unfortunately made it possible to construct contradictory values of WebSocketOpcode, such as .unknownNonControl(0x1) (which should be spelled .text), or .unknownControl(0xFF) (which is simply invalid). This patch removes the ability to construct invalid values of WebSocketOpcode by turning it into a struct and using static lets for known values. While we're here it cleans some other stuff up. Modifications: - Made WebSocketOpcode a struct - Added several static lets for easy access and to reduce code churn - Used synthesised Equatable conformance - Added synthesised Hashable conformance - Added CustomStringConvertible conformance to better represent known values - Added CaseIterable conformance to provide entire range of valid values. Result: WebSocketOpcode will be a better-behaved type with more guarantees and fewer places to trap and explode. Resolves #617.