-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Making ByteBuffer's description more useful #2864
Conversation
Motivation: Resolving the following issue: apple#2863 Modifications: Rewrote `description` and `debugDescription` on `ByteBuffer` to make it more useful. Result: A more userful `description` and `debugDescription`. After your change, what will change.
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.
LGTM thank you. I'll let the NIO team actually review this before they can merge.
@@ -957,37 +957,30 @@ public struct ByteBuffer { | |||
} | |||
|
|||
extension ByteBuffer: CustomStringConvertible, CustomDebugStringConvertible { | |||
/// A `String` describing this `ByteBuffer`. Example: | |||
/// A `String` describing this `ByteBuffer`. For a `ByteBuffer` initialised with `hello world` |
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.
/// A `String` describing this `ByteBuffer`. For a `ByteBuffer` initialised with `hello world` | |
/// A `String` describing this `ByteBuffer` including length and the bytes it contains (partially). | |
/// | |
/// For a `ByteBuffer` initialised with `hello world` |
Nit: The first line in the doc comments is special, it's the summary. That summary gets displayed by itself in many scenarios so we should aim for it to make sense without the rest of the doc comment.
@@ -24,7 +24,7 @@ class NIOAnyDebugTest: XCTestCase { | |||
let bb = ByteBuffer(string: "byte buffer string") | |||
XCTAssertTrue( | |||
wrappedInNIOAnyBlock(bb).contains( | |||
"NIOAny { ByteBuffer { readerIndex: 0, writerIndex: 18, readableBytes: 18, capacity: 32, storageCapacity: 32, slice: _ByteBufferSlice { 0..<32 }, storage: " | |||
"NIOAny { [627974652062756666657220737472696e67](18 bytes) }" |
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.
Nit: I almost think with this change we should change NIOAny's description
to include ByteBuffer:
when it's the case .byteBuffer
. Previously that wasn't necessary because ByteBuffer.description
contained the word ByteBuffer
but that's now changed.
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.
Looking at NIOAny
I would improve its description altogether to include information about the wrapped type. But I would do that in a separate issue/PR.
@@ -3602,5 +3607,12 @@ extension ByteBufferTest { | |||
XCTAssertEqual(error as? Base64Error, .invalidCharacter) | |||
} | |||
} | |||
|
|||
|
|||
func testByteBufferDescription() { |
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.
think it would be nice to add two other test cases:
- the empty ByteBuffer
- one where the hex bytes get truncated (i.e. more than 128 bytes or whatever the limit is)
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.
Thanks, added!
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 LGTM. @supersonicbyte please raise another PR for adapting NIOAny
then
As per: apple#2864 (comment) we would like that the `description` of `NIOAny` prints the type of the underlaying value that it wraps. Changing `description` and adding a conformance to `CustomDebugStringConvertible`. A nicer `description` and `debugDescription` for `NIOAny`.
) Improving `description` and adding `debugDescription` to `NIOAny` ### Motivation As per: #2864 (comment) we would like that the `description` of `NIOAny` prints the type of the underlaying value that it wraps. ### Modification: Changing `description` and adding a conformance to `CustomDebugStringConvertible`. ### Result: A nicer `description` and `debugDescription` for `NIOAny`. Co-authored-by: Franz Busch <f.busch@apple.com>
…ple#2866) Improving `description` and adding `debugDescription` to `NIOAny` ### Motivation As per: apple#2864 (comment) we would like that the `description` of `NIOAny` prints the type of the underlaying value that it wraps. ### Modification: Changing `description` and adding a conformance to `CustomDebugStringConvertible`. ### Result: A nicer `description` and `debugDescription` for `NIOAny`. Co-authored-by: Franz Busch <f.busch@apple.com>
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [apple/swift-nio](https://github.com/apple/swift-nio) | minor | `2.72.0` -> `2.73.0` | --- ### Release Notes <details> <summary>apple/swift-nio (apple/swift-nio)</summary> ### [`v2.73.0`](https://github.com/apple/swift-nio/releases/tag/2.73.0) [Compare Source](https://github.com/apple/swift-nio/compare/2.72.0...2.73.0) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### SemVer Minor - Make `ByteBuffer`'s description more useful by [@​supersonicbyte](https://github.com/supersonicbyte) in [https://github.com/apple/swift-nio/pull/2864](https://github.com/apple/swift-nio/pull/2864) - Expose `UDP_MAX_SEGMENTS` via System by [@​rnro](https://github.com/rnro) in [https://github.com/apple/swift-nio/pull/2891](https://github.com/apple/swift-nio/pull/2891) - Add new `ChannelOption` to get the amount of buffered outbound data in the Channel by [@​johnnzhou](https://github.com/johnnzhou) in [https://github.com/apple/swift-nio/pull/2849](https://github.com/apple/swift-nio/pull/2849) - Add an `AcceptBackoffHandler` to the async server bootstraps by [@​FranzBusch](https://github.com/FranzBusch) in [https://github.com/apple/swift-nio/pull/2782](https://github.com/apple/swift-nio/pull/2782) ##### SemVer Patch - Adding a nicer description for `WebSocketFrame` by [@​supersonicbyte](https://github.com/supersonicbyte) in [https://github.com/apple/swift-nio/pull/2862](https://github.com/apple/swift-nio/pull/2862) - Improving `description` and adding `debugDescription` to `NIOAny` by [@​supersonicbyte](https://github.com/supersonicbyte) in [https://github.com/apple/swift-nio/pull/2866](https://github.com/apple/swift-nio/pull/2866) - Make FileChunk sendable by [@​ali-ahsan-ali](https://github.com/ali-ahsan-ali) in [https://github.com/apple/swift-nio/pull/2871](https://github.com/apple/swift-nio/pull/2871) - Make `ByteBuffer.debugDescription` suitable for structural display by [@​dnadoba](https://github.com/dnadoba) in [https://github.com/apple/swift-nio/pull/2495](https://github.com/apple/swift-nio/pull/2495) - Add support for WASILibc by [@​MaxDesiatov](https://github.com/MaxDesiatov) in [https://github.com/apple/swift-nio/pull/2671](https://github.com/apple/swift-nio/pull/2671) - `NIOSingleStepByteToMessageDecoder` reentrancy safety by [@​rnro](https://github.com/rnro) in [https://github.com/apple/swift-nio/pull/2881](https://github.com/apple/swift-nio/pull/2881) - Adopt `NIOThrowingAsyncSequenceProducer` by [@​rnro](https://github.com/rnro) in [https://github.com/apple/swift-nio/pull/2879](https://github.com/apple/swift-nio/pull/2879) - Clamp buffer to maximum upon large write operation by [@​ali-ahsan-ali](https://github.com/ali-ahsan-ali) in [https://github.com/apple/swift-nio/pull/2745](https://github.com/apple/swift-nio/pull/2745) - Revert "Adopt `NIOThrowingAsyncSequenceProducer` ([#​2879](https://github.com/apple/swift-nio/issues/2879))" by [@​rnro](https://github.com/rnro) in [https://github.com/apple/swift-nio/pull/2892](https://github.com/apple/swift-nio/pull/2892) - Add concrete description for `EmbeddedEventLoop` by [@​aryan-25](https://github.com/aryan-25) in [https://github.com/apple/swift-nio/pull/2890](https://github.com/apple/swift-nio/pull/2890) - Conditionally include linux/udp.h by [@​rnro](https://github.com/rnro) in [https://github.com/apple/swift-nio/pull/2894](https://github.com/apple/swift-nio/pull/2894) - Work around a type checking error when using the Static Linux SDK by [@​euanh](https://github.com/euanh) in [https://github.com/apple/swift-nio/pull/2898](https://github.com/apple/swift-nio/pull/2898) ##### Other Changes - \[CI] Run tests on push to main by [@​FranzBusch](https://github.com/FranzBusch) in [https://github.com/apple/swift-nio/pull/2868](https://github.com/apple/swift-nio/pull/2868) - \[CI] License header support `.in` and `.cmake` files by [@​FranzBusch](https://github.com/FranzBusch) in [https://github.com/apple/swift-nio/pull/2870](https://github.com/apple/swift-nio/pull/2870) - Include nanoseconds in assertion of timestamp for NIOFileSystem tests by [@​gjcairo](https://github.com/gjcairo) in [https://github.com/apple/swift-nio/pull/2869](https://github.com/apple/swift-nio/pull/2869) - Correct the link of sswg-security at SECURITY.md by [@​lamtrinhdev](https://github.com/lamtrinhdev) in [https://github.com/apple/swift-nio/pull/2872](https://github.com/apple/swift-nio/pull/2872) - Speculative fix for flakey AsyncTestingEventLoop test by [@​simonjbeaumont](https://github.com/simonjbeaumont) in [https://github.com/apple/swift-nio/pull/2873](https://github.com/apple/swift-nio/pull/2873) - ci: Install shellcheck if not present in CI runner by [@​simonjbeaumont](https://github.com/simonjbeaumont) in [https://github.com/apple/swift-nio/pull/2882](https://github.com/apple/swift-nio/pull/2882) - ci: Use ${GITHUB_BASE_REF} as treeish for checking API break by [@​simonjbeaumont](https://github.com/simonjbeaumont) in [https://github.com/apple/swift-nio/pull/2883](https://github.com/apple/swift-nio/pull/2883) - ci: Refer to nested reusable workflows using remote variant by [@​simonjbeaumont](https://github.com/simonjbeaumont) in [https://github.com/apple/swift-nio/pull/2884](https://github.com/apple/swift-nio/pull/2884) - \[CI] Fix pull request label workflow by [@​FranzBusch](https://github.com/FranzBusch) in [https://github.com/apple/swift-nio/pull/2885](https://github.com/apple/swift-nio/pull/2885) #### New Contributors - [@​ali-ahsan-ali](https://github.com/ali-ahsan-ali) made their first contribution in [https://github.com/apple/swift-nio/pull/2871](https://github.com/apple/swift-nio/pull/2871) - [@​aryan-25](https://github.com/aryan-25) made their first contribution in [https://github.com/apple/swift-nio/pull/2890](https://github.com/apple/swift-nio/pull/2890) - [@​johnnzhou](https://github.com/johnnzhou) made their first contribution in [https://github.com/apple/swift-nio/pull/2849](https://github.com/apple/swift-nio/pull/2849) - [@​euanh](https://github.com/euanh) made their first contribution in [https://github.com/apple/swift-nio/pull/2898](https://github.com/apple/swift-nio/pull/2898) **Full Changelog**: apple/swift-nio@2.72.0...2.73.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC45NC4xIiwidXBkYXRlZEluVmVyIjoiMzguOTQuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: cgrindel-self-hosted-renovate[bot] <139595543+cgrindel-self-hosted-renovate[bot]@users.noreply.github.com>
Motivation:
Resolving the following issue: #2863
Modifications:
Rewrote
description
anddebugDescription
onByteBuffer
to make it more useful. Also fixed a bug in the inhexDumpCompact
.Result:
A more useful
description
anddebugDescription
.