Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example #2077

Merged
merged 2 commits into from
Oct 1, 2024
Merged
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
116 changes: 58 additions & 58 deletions Examples/echo/Sources/Generated/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,27 @@ extension GRPCCore.ServiceDescriptor {
internal protocol Echo_Echo_StreamingServiceProtocol: GRPCCore.RegistrableRPCService {
/// Immediately returns an echo of a request.
func get(
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>

/// Splits a request into words and returns each word in a stream of messages.
func expand(
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>

/// Collects a stream of messages and returns them concatenated when the caller closes.
func collect(
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>

/// Streams back messages as they are received in an input stream.
func update(
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>
}

/// Conformance to `GRPCCore.RegistrableRPCService`.
Expand Down Expand Up @@ -166,111 +166,111 @@ extension Echo_Echo.StreamingServiceProtocol {
internal protocol Echo_Echo_ServiceProtocol: Echo_Echo.StreamingServiceProtocol {
/// Immediately returns an echo of a request.
func get(
request: GRPCCore.ServerRequest.Single<Echo_EchoRequest>,
request: GRPCCore.ServerRequest<Echo_EchoRequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse.Single<Echo_EchoResponse>
) async throws -> GRPCCore.ServerResponse<Echo_EchoResponse>

/// Splits a request into words and returns each word in a stream of messages.
func expand(
request: GRPCCore.ServerRequest.Single<Echo_EchoRequest>,
request: GRPCCore.ServerRequest<Echo_EchoRequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>

/// Collects a stream of messages and returns them concatenated when the caller closes.
func collect(
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse.Single<Echo_EchoResponse>
) async throws -> GRPCCore.ServerResponse<Echo_EchoResponse>

/// Streams back messages as they are received in an input stream.
func update(
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>
}

/// Partial conformance to `Echo_Echo_StreamingServiceProtocol`.
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
extension Echo_Echo.ServiceProtocol {
internal func get(
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse> {
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse> {
let response = try await self.get(
request: GRPCCore.ServerRequest.Single(stream: request),
request: GRPCCore.ServerRequest(stream: request),
context: context
)
return GRPCCore.ServerResponse.Stream(single: response)
return GRPCCore.StreamingServerResponse(single: response)
}

internal func expand(
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse> {
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse> {
let response = try await self.expand(
request: GRPCCore.ServerRequest.Single(stream: request),
request: GRPCCore.ServerRequest(stream: request),
context: context
)
return response
}

internal func collect(
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
context: GRPCCore.ServerContext
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse> {
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse> {
let response = try await self.collect(
request: request,
context: context
)
return GRPCCore.ServerResponse.Stream(single: response)
return GRPCCore.StreamingServerResponse(single: response)
}
}

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
internal protocol Echo_Echo_ClientProtocol: Sendable {
/// Immediately returns an echo of a request.
func get<R>(
request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
request: GRPCCore.ClientRequest<Echo_EchoRequest>,
serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
options: GRPCCore.CallOptions,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R
_ body: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> R
) async throws -> R where R: Sendable

/// Splits a request into words and returns each word in a stream of messages.
func expand<R>(
request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
request: GRPCCore.ClientRequest<Echo_EchoRequest>,
serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
options: GRPCCore.CallOptions,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
_ body: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> R
) async throws -> R where R: Sendable

/// Collects a stream of messages and returns them concatenated when the caller closes.
func collect<R>(
request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
options: GRPCCore.CallOptions,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R
_ body: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> R
) async throws -> R where R: Sendable

/// Streams back messages as they are received in an input stream.
func update<R>(
request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
options: GRPCCore.CallOptions,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
_ body: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> R
) async throws -> R where R: Sendable
}

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
extension Echo_Echo.ClientProtocol {
internal func get<R>(
request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
request: GRPCCore.ClientRequest<Echo_EchoRequest>,
options: GRPCCore.CallOptions = .defaults,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
_ body: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> R = {
try $0.message
}
) async throws -> R where R: Sendable {
Expand All @@ -284,9 +284,9 @@ extension Echo_Echo.ClientProtocol {
}

internal func expand<R>(
request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
request: GRPCCore.ClientRequest<Echo_EchoRequest>,
options: GRPCCore.CallOptions = .defaults,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
_ body: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> R
) async throws -> R where R: Sendable {
try await self.expand(
request: request,
Expand All @@ -298,9 +298,9 @@ extension Echo_Echo.ClientProtocol {
}

internal func collect<R>(
request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
options: GRPCCore.CallOptions = .defaults,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
_ body: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> R = {
try $0.message
}
) async throws -> R where R: Sendable {
Expand All @@ -314,9 +314,9 @@ extension Echo_Echo.ClientProtocol {
}

internal func update<R>(
request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
options: GRPCCore.CallOptions = .defaults,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
_ body: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> R
) async throws -> R where R: Sendable {
try await self.update(
request: request,
Expand All @@ -335,11 +335,11 @@ extension Echo_Echo.ClientProtocol {
_ message: Echo_EchoRequest,
metadata: GRPCCore.Metadata = [:],
options: GRPCCore.CallOptions = .defaults,
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> Result = {
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result = {
try $0.message
}
) async throws -> Result where Result: Sendable {
let request = GRPCCore.ClientRequest.Single<Echo_EchoRequest>(
let request = GRPCCore.ClientRequest<Echo_EchoRequest>(
message: message,
metadata: metadata
)
Expand All @@ -355,9 +355,9 @@ extension Echo_Echo.ClientProtocol {
_ message: Echo_EchoRequest,
metadata: GRPCCore.Metadata = [:],
options: GRPCCore.CallOptions = .defaults,
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> Result
onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
) async throws -> Result where Result: Sendable {
let request = GRPCCore.ClientRequest.Single<Echo_EchoRequest>(
let request = GRPCCore.ClientRequest<Echo_EchoRequest>(
message: message,
metadata: metadata
)
Expand All @@ -373,11 +373,11 @@ extension Echo_Echo.ClientProtocol {
metadata: GRPCCore.Metadata = [:],
options: GRPCCore.CallOptions = .defaults,
requestProducer: @Sendable @escaping (GRPCCore.RPCWriter<Echo_EchoRequest>) async throws -> Void,
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> Result = {
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result = {
try $0.message
}
) async throws -> Result where Result: Sendable {
let request = GRPCCore.ClientRequest.Stream<Echo_EchoRequest>(
let request = GRPCCore.StreamingClientRequest<Echo_EchoRequest>(
metadata: metadata,
producer: requestProducer
)
Expand All @@ -393,9 +393,9 @@ extension Echo_Echo.ClientProtocol {
metadata: GRPCCore.Metadata = [:],
options: GRPCCore.CallOptions = .defaults,
requestProducer: @Sendable @escaping (GRPCCore.RPCWriter<Echo_EchoRequest>) async throws -> Void,
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> Result
onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
) async throws -> Result where Result: Sendable {
let request = GRPCCore.ClientRequest.Stream<Echo_EchoRequest>(
let request = GRPCCore.StreamingClientRequest<Echo_EchoRequest>(
metadata: metadata,
producer: requestProducer
)
Expand All @@ -417,11 +417,11 @@ internal struct Echo_Echo_Client: Echo_Echo.ClientProtocol {

/// Immediately returns an echo of a request.
internal func get<R>(
request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
request: GRPCCore.ClientRequest<Echo_EchoRequest>,
serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
options: GRPCCore.CallOptions = .defaults,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
_ body: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> R = {
try $0.message
}
) async throws -> R where R: Sendable {
Expand All @@ -437,11 +437,11 @@ internal struct Echo_Echo_Client: Echo_Echo.ClientProtocol {

/// Splits a request into words and returns each word in a stream of messages.
internal func expand<R>(
request: GRPCCore.ClientRequest.Single<Echo_EchoRequest>,
request: GRPCCore.ClientRequest<Echo_EchoRequest>,
serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
options: GRPCCore.CallOptions = .defaults,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
_ body: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> R
) async throws -> R where R: Sendable {
try await self.client.serverStreaming(
request: request,
Expand All @@ -455,11 +455,11 @@ internal struct Echo_Echo_Client: Echo_Echo.ClientProtocol {

/// Collects a stream of messages and returns them concatenated when the caller closes.
internal func collect<R>(
request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
options: GRPCCore.CallOptions = .defaults,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> R = {
_ body: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> R = {
try $0.message
}
) async throws -> R where R: Sendable {
Expand All @@ -475,11 +475,11 @@ internal struct Echo_Echo_Client: Echo_Echo.ClientProtocol {

/// Streams back messages as they are received in an input stream.
internal func update<R>(
request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
options: GRPCCore.CallOptions = .defaults,
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
_ body: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> R
) async throws -> R where R: Sendable {
try await self.client.bidirectionalStreaming(
request: request,
Expand Down
24 changes: 12 additions & 12 deletions Examples/echo/Sources/Subcommands/Serve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,26 @@ struct Serve: AsyncParsableCommand {
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
struct EchoService: Echo_Echo_ServiceProtocol {
func get(
request: ServerRequest.Single<Echo_EchoRequest>,
request: ServerRequest<Echo_EchoRequest>,
context: ServerContext
) async throws -> ServerResponse.Single<Echo_EchoResponse> {
return ServerResponse.Single(message: .with { $0.text = request.message.text })
) async throws -> ServerResponse<Echo_EchoResponse> {
return ServerResponse(message: .with { $0.text = request.message.text })
}

func collect(
request: ServerRequest.Stream<Echo_EchoRequest>,
request: StreamingServerRequest<Echo_EchoRequest>,
context: ServerContext
) async throws -> ServerResponse.Single<Echo_EchoResponse> {
) async throws -> ServerResponse<Echo_EchoResponse> {
let messages = try await request.messages.reduce(into: []) { $0.append($1.text) }
let joined = messages.joined(separator: " ")
return ServerResponse.Single(message: .with { $0.text = joined })
return ServerResponse(message: .with { $0.text = joined })
}

func expand(
request: ServerRequest.Single<Echo_EchoRequest>,
request: ServerRequest<Echo_EchoRequest>,
context: ServerContext
) async throws -> ServerResponse.Stream<Echo_EchoResponse> {
return ServerResponse.Stream { writer in
) async throws -> StreamingServerResponse<Echo_EchoResponse> {
return StreamingServerResponse { writer in
let parts = request.message.text.split(separator: " ")
let messages = parts.map { part in Echo_EchoResponse.with { $0.text = String(part) } }
try await writer.write(contentsOf: messages)
Expand All @@ -73,10 +73,10 @@ struct EchoService: Echo_Echo_ServiceProtocol {
}

func update(
request: ServerRequest.Stream<Echo_EchoRequest>,
request: StreamingServerRequest<Echo_EchoRequest>,
context: ServerContext
) async throws -> ServerResponse.Stream<Echo_EchoResponse> {
return ServerResponse.Stream { writer in
) async throws -> StreamingServerResponse<Echo_EchoResponse> {
return StreamingServerResponse { writer in
for try await message in request.messages {
try await writer.write(.with { $0.text = message.text })
}
Expand Down
Loading
Loading