Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Sources/NIOCore/ByteBuffer-aux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,23 @@ extension ByteBuffer {
/// - plainHexEncodedBytes: The hex encoded string to write. Plain hex dump format is hex bytes optionally separated by spaces, i.e. `48 65 6c 6c 6f` or `48656c6c6f` for `Hello`.
/// This format is compatible with `xxd` CLI utility.
/// - Returns: The number of bytes written.
@_disfavoredOverload
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think @_disfavoredOverload should be needed here.

@discardableResult
@inlinable
public mutating func writePlainHexEncodedBytes(_ plainHexEncodedBytes: String) throws -> Int {
try self.writePlainHexEncodedBytes(plainHexEncodedBytes)
}

// MARK: Hex encoded string APIs
/// Write ASCII hexadecimal `string` into this `ByteBuffer` as raw bytes, decoding the hexadecimal & moving the writer index forward appropriately.
/// This method will throw if the string input is not of the "plain" hex encoded format.
/// - Parameters:
/// - plainHexEncodedBytes: The hex encoded string to write. Plain hex dump format is hex bytes optionally separated by spaces, i.e. `48 65 6c 6c 6f` or `48656c6c6f` for `Hello`.
/// This format is compatible with `xxd` CLI utility.
/// - Returns: The number of bytes written.
@discardableResult
@inlinable
public mutating func writePlainHexEncodedBytes(_ plainHexEncodedBytes: some StringProtocol) throws -> Int {
var slice = plainHexEncodedBytes.utf8[...]
let initialWriterIndex = self.writerIndex

Expand Down Expand Up @@ -895,8 +909,19 @@ extension ByteBufferAllocator {
/// This will allocate a new `ByteBuffer` with enough space to fit `bytes` and potentially some extra space.
///
/// - Returns: The `ByteBuffer` containing the written bytes.
@_disfavoredOverload
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think @_disfavoredOverload should be needed here.

@inlinable
public func buffer(plainHexEncodedBytes string: String) throws -> ByteBuffer {
try buffer(plainHexEncodedBytes: string)
}

/// Create a fresh `ByteBuffer` containing the `bytes` decoded from the ASCII `plainHexEncodedBytes` string .
///
/// This will allocate a new `ByteBuffer` with enough space to fit `bytes` and potentially some extra space.
///
/// - Returns: The `ByteBuffer` containing the written bytes.
@inlinable
public func buffer(plainHexEncodedBytes string: some StringProtocol) throws -> ByteBuffer {
var buffer = self.buffer(capacity: string.utf8.count / 2)
try buffer.writePlainHexEncodedBytes(string)
return buffer
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOCore/ByteBuffer-hex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ extension UInt8 {
}
}

extension Substring.UTF8View {
extension Collection<UInt8> where Self == Self.SubSequence {
@usableFromInline
mutating func popNextHexByte() throws -> UInt8? {
while let nextByte = self.first, nextByte.isASCIIWhitespace {
Expand Down
Loading