Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Rebello <[email protected]>
  • Loading branch information
rebello95 committed May 29, 2024
1 parent 7946f12 commit 3118c1a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Examples/ElizaCocoaPodsApp/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: b598f373a6ab5add976b09c2ac79029bf2200d48

COCOAPODS: 1.13.0
COCOAPODS: 1.15.2
14 changes: 4 additions & 10 deletions Libraries/Connect/Internal/Interceptors/GRPCWebInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ extension GRPCWebInterceptor: UnaryInterceptor {
headers: response.headers,
message: response.message,
trailers: response.trailers,
error: ConnectError.unaryResponseHasNoMessage(),
error: ConnectError(
code: .unimplemented, message: "unary response has no message"
),
tracingInfo: response.tracingInfo
))
}
Expand Down Expand Up @@ -303,7 +305,7 @@ private extension HTTPResponse {
headers: self.headers,
message: nil,
trailers: trailers,
error: ConnectError.unaryResponseHasNoMessage(),
error: ConnectError(code: .unimplemented, message: "unary response has no message"),
tracingInfo: self.tracingInfo
)
} else {
Expand All @@ -318,11 +320,3 @@ private extension HTTPResponse {
}
}
}

private extension ConnectError {
static func unaryResponseHasNoMessage() -> Self {
return ConnectError(
code: .unimplemented, message: "unary response has no message"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import SwiftProtobuf
/// Concrete implementation of `BidirectionalAsyncStreamInterface`.
/// Provides the necessary wiring to bridge from closures/callbacks to Swift's `AsyncStream`
/// to work with async/await.
///
/// If the library removes callback support in favor of only supporting async/await in the future,
/// this class can be simplified.
@available(iOS 13, *)
class BidirectionalAsyncStream<
Input: ProtobufMessage, Output: ProtobufMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import Foundation
/// Concrete implementation of `ClientOnlyAsyncStreamInterface`.
/// Provides the necessary wiring to bridge from closures/callbacks to Swift's `AsyncStream`
/// to work with async/await.
///
/// This subclasses `BidirectionalAsyncStream` since its behavior is purely additive (it overlays
/// some additional validation) and both types are internal to the package, not public.
@available(iOS 13, *)
final class ClientOnlyAsyncStream<
Input: ProtobufMessage, Output: ProtobufMessage
Expand All @@ -34,6 +37,7 @@ final class ClientOnlyAsyncStream<
}
}

@available(iOS 13, *)
extension ClientOnlyAsyncStream: ClientOnlyAsyncStreamInterface {
func closeAndReceive() {
self.close()
Expand Down
3 changes: 3 additions & 0 deletions Libraries/Connect/Internal/Streaming/ClientOnlyStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import SwiftProtobuf

/// Concrete implementation of `ClientOnlyStreamInterface`.
///
/// The complexity around configuring callbacks on this type is an artifact of the library
/// supporting both callbacks and async/await. This is internal to the package, and not public.
final class ClientOnlyStream<Input: ProtobufMessage, Output: ProtobufMessage>: @unchecked Sendable {
private let onResult: @Sendable (StreamResult<Output>) -> Void
private let receivedMessageCount = Locked(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ extension StreamResult {
/// - returns: The validated stream result, which may have been transformed into an error.
func validatedForClientStream(receivedMessageCount: Int) -> Self {
switch self {
case .complete(let code, _, _):
if code == .ok && receivedMessageCount < 1 {
case .headers:
return self
case .message:
if receivedMessageCount > 1 {
return .complete(
code: .internalError,
error: ConnectError(
code: .unimplemented, message: "unary stream has no messages"
code: .unimplemented, message: "unary stream has multiple messages"
),
trailers: nil
)
} else {
return self
}
case .headers:
return self
case .message:
if receivedMessageCount > 1 {
case .complete(let code, _, _):
if code == .ok && receivedMessageCount < 1 {
return .complete(
code: .internalError,
error: ConnectError(
code: .unimplemented, message: "unary stream has multiple messages"
code: .unimplemented, message: "unary stream has no messages"
),
trailers: nil
)
Expand Down
26 changes: 12 additions & 14 deletions Libraries/ConnectNIO/Internal/GRPCInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,21 @@ extension GRPCInterceptor: UnaryInterceptor {
), tracingInfo: response.tracingInfo
))
return
} else if Envelope.containsMultipleMessages(rawData) {
proceed(HTTPResponse(
code: .unimplemented,
headers: response.headers,
message: nil,
trailers: response.trailers,
error: ConnectError(
code: .unimplemented, message: "unary response has multiple messages"
),
tracingInfo: response.tracingInfo
))
return
}

do {
guard Envelope.containsMultipleMessages(rawData) == false else {
proceed(HTTPResponse(
code: .unimplemented,
headers: response.headers,
message: nil,
trailers: response.trailers,
error: ConnectError(
code: .unimplemented, message: "unary response has multiple messages"
),
tracingInfo: response.tracingInfo
))
return
}

let messageData = try Envelope.unpackMessage(
rawData, compressionPool: compressionPool
).unpacked
Expand Down

0 comments on commit 3118c1a

Please sign in to comment.