-
Notifications
You must be signed in to change notification settings - Fork 649
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
Adding a nicer description for WebSocketFrame
.
#2862
Merged
FranzBusch
merged 6 commits into
apple:main
from
supersonicbyte:websocketframe-description
Sep 4, 2024
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
af95304
Adding a nicer description for `WebSocketFrame`.
supersonicbyte 9411308
Add unit test for WebSocketFrame description
supersonicbyte 64ca1eb
Make WebSocketFrame description one liner
supersonicbyte 1c958b4
Drop type name from description
supersonicbyte 65ff53a
Reuse description for debugDescription
supersonicbyte b769920
Merge branch 'main' into websocketframe-description
FranzBusch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -363,3 +363,60 @@ extension WebSocketFrame._Storage: Equatable { | |
lhs.data == rhs.data && lhs.extensionData == rhs.extensionData | ||
} | ||
} | ||
|
||
extension WebSocketFrame: CustomStringConvertible { | ||
/// A `String` describing this `WebSocketFrame`. Example: | ||
/// | ||
/// WebSocketFrame { | ||
/// maskKey: Optional(NIOWebSocket.WebSocketMaskingKey(_key: (187, 28, 185, 79))), | ||
/// fin: true, | ||
/// rsv1: true, | ||
/// rsv2: true, | ||
/// rsv3: true, | ||
/// opcode: WebSocketOpcode.binary, | ||
/// length: 0, | ||
/// data: ByteBuffer { readerIndex: 0, writerIndex: 0, readableBytes: 0, capacity: 0, storageCapacity: 0, slice: _ByteBufferSlice { 0..<0 }, storage: 0x00006000028246b0 (0 bytes) }, | ||
/// extensionData: nil, | ||
/// unmaskedData: ByteBuffer { readerIndex: 0, writerIndex: 0, readableBytes: 0, capacity: 0, storageCapacity: 0, slice: _ByteBufferSlice { 0..<0 }, storage: 0x0000600002824800 (0 bytes) }, | ||
/// unmaskedDataExtension: nil | ||
/// } | ||
/// | ||
/// The format of the description is not API. | ||
/// | ||
/// - returns: A description of this `WebSocketFrame`. | ||
public var description: String { | ||
""" | ||
maskKey: \(String(describing: self.maskKey)), \ | ||
fin: \(self.fin), \ | ||
rsv1: \(self.rsv1), \ | ||
rsv2: \(self.rsv2), \ | ||
rsv3: \(self.rsv3), \ | ||
opcode: \(self.opcode), \ | ||
length: \(self.length), \ | ||
data: \(String(describing: self.data)), \ | ||
extensionData: \(String(describing: self.extensionData)), \ | ||
unmaskedData: \(String(describing: self.unmaskedData)), \ | ||
unmaskedDataExtension: \(String(describing: self.unmaskedExtensionData)) | ||
""" | ||
} | ||
} | ||
|
||
extension WebSocketFrame: CustomDebugStringConvertible { | ||
public var debugDescription: String { | ||
""" | ||
( \ | ||
maskKey: \(String(describing: self.maskKey)), \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just interpolate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, done! |
||
fin: \(self.fin), \ | ||
rsv1: \(self.rsv1), \ | ||
rsv2: \(self.rsv2), \ | ||
rsv3: \(self.rsv3), \ | ||
opcode: \(self.opcode), \ | ||
length: \(self.length), \ | ||
data: \(String(describing: self.data)), \ | ||
extensionData: \(String(describing: self.extensionData)), \ | ||
unmaskedData: \(String(describing: self.unmaskedData)), \ | ||
unmaskedDataExtension: \(String(describing: self.unmaskedExtensionData)) \ | ||
) | ||
""" | ||
} | ||
} |
This file contains 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
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.
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.
Can we please avoid adding a multiline string as a description here.
description
is often used in other interpolated strings such as log messages and adding line breaks can often break those formats. Instead can we add a single line for this.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.
good point, we should add
\
s to the end of the line (such that the result is just one line). I missed that currently we'll actually print multiple lines.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.
@FranzBusch very good point, thanks! I will fix it.
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 is still a multiline string from what I can see. Can you use
"
instead of"""
unless I am missing something hereThere 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.
@FranzBusch no it's not, it has
\
s everywhere but the last line.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.