apple / swift-nio

Event-driven network application framework for high performance protocol servers & clients, non-blocking.
https://swiftpackageindex.com/apple/swift-nio/documentation
Apache License 2.0
7.92k stars 643 forks source link

ByteBuffer should have a `.hexdump(format: .compact)` #2825

Open weissi opened 1 month ago

weissi commented 1 month ago

ByteBuffer has awesome hexdump(format: .detailed | .plain) formats (from #2475). They're awesome and I use them all the time. But there's one format that I think is quite useful: A compact one without spaces. So

XCTAssertEqual("68656c6c6f20776f726c640a", ByteBuffer(string: "hello world\n").hexdump(format: .compact))

Why is compact so important? Frequently, UNIX tools output formats that are easy to split using cut -d' ' -f2 or awk '{ print $2 }' or while read -r line prefix hex; do echo "$hex"; done. But all these require that there's no whitespace in the hexdump.

So I think we should add another format which is exactly like .plain but doesn't emit spaces or any other whitespace. #2475 made great groundwork here and this should be very easy to add.

weissi commented 1 month ago

Related to #2748

supersonicbyte commented 2 weeks ago

Made a PR for this!