Skip to content

Commit

Permalink
Added default minimums for async byte requests
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitribouniol committed Nov 18, 2021
1 parent 3adb4b3 commit 1f1303f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Sources/Bytes/AsyncBytes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension AsyncIteratorProtocol where Element == UInt8 {
/// - Returns: A byte array of size at least `minCount` and at most `maxCount`.
/// - Throws: `BytesError.invalidMemorySize` if a complete byte array could not be returned by the time the sequence ended.
@inlinable
public mutating func next(bytes type: Bytes.Type, min minCount: Int, max maxCount: Int) async throws -> Bytes {
public mutating func next(bytes type: Bytes.Type, min minCount: Int = 0, max maxCount: Int) async throws -> Bytes {
precondition(minCount <= maxCount, "maxCount must be larger than or equal to minCount")
precondition(minCount >= 0, "minCount must be larger than 0")
var result = Bytes()
Expand Down Expand Up @@ -77,7 +77,7 @@ extension AsyncIteratorProtocol where Element == UInt8 {
/// - Returns: A byte array of size at least `minCount` and at most `maxCount`, or `nil` if the sequence is finished.
/// - Throws: `BytesError.invalidMemorySize` if a complete byte array could not be returned by the time the sequence ended.
@inlinable
public mutating func nextIfPresent(bytes type: Bytes.Type, min minCount: Int, max maxCount: Int) async throws -> Bytes? {
public mutating func nextIfPresent(bytes type: Bytes.Type, min minCount: Int = 0, max maxCount: Int) async throws -> Bytes? {
precondition(minCount <= maxCount, "maxCount must be larger than or equal to minCount")
precondition(minCount >= 0, "minCount must be larger than 0")
var result = Bytes()
Expand Down
4 changes: 2 additions & 2 deletions Sources/Bytes/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension AsyncIteratorProtocol where Element == UInt8 {
/// - Returns: A string of size at least `minCount` and at most `maxCount`.
/// - Throws: `BytesError.invalidMemorySize` if a complete string could not be returned by the time the sequence ended.
@inlinable
public mutating func next(utf8 type: String.Type, min minCount: Int, max maxCount: Int) async throws -> String {
public mutating func next(utf8 type: String.Type, min minCount: Int = 0, max maxCount: Int) async throws -> String {
String(utf8Bytes: try await next(bytes: Bytes.self, min: minCount, max: maxCount))
}

Expand All @@ -91,7 +91,7 @@ extension AsyncIteratorProtocol where Element == UInt8 {
/// - Returns: A string of size at least `minCount` and at most `maxCount`, or `nil` if the sequence is finished.
/// - Throws: `BytesError.invalidMemorySize` if a complete string could not be returned by the time the sequence ended.
@inlinable
public mutating func nextIfPresent(utf8 type: String.Type, min minCount: Int, max maxCount: Int) async throws -> String? {
public mutating func nextIfPresent(utf8 type: String.Type, min minCount: Int = 0, max maxCount: Int) async throws -> String? {
try (await nextIfPresent(bytes: Bytes.self, min: minCount, max: maxCount)).map { String(utf8Bytes: $0) }
}
}
Expand Down

0 comments on commit 1f1303f

Please sign in to comment.