Skip to content

Commit 432c955

Browse files
authored
Update example (#2077)
Motivation: Some names changed in #2076 and now our examples don't compile. Modifications: - Update examples Result: Examples compile
1 parent 1e92fc8 commit 432c955

File tree

6 files changed

+160
-160
lines changed

6 files changed

+160
-160
lines changed

Examples/echo/Sources/Generated/echo.grpc.swift

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,27 @@ extension GRPCCore.ServiceDescriptor {
8787
internal protocol Echo_Echo_StreamingServiceProtocol: GRPCCore.RegistrableRPCService {
8888
/// Immediately returns an echo of a request.
8989
func get(
90-
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
90+
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
9191
context: GRPCCore.ServerContext
92-
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse>
92+
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse>
9393

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

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

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

113113
/// Conformance to `GRPCCore.RegistrableRPCService`.
@@ -166,111 +166,111 @@ extension Echo_Echo.StreamingServiceProtocol {
166166
internal protocol Echo_Echo_ServiceProtocol: Echo_Echo.StreamingServiceProtocol {
167167
/// Immediately returns an echo of a request.
168168
func get(
169-
request: GRPCCore.ServerRequest.Single<Echo_EchoRequest>,
169+
request: GRPCCore.ServerRequest<Echo_EchoRequest>,
170170
context: GRPCCore.ServerContext
171-
) async throws -> GRPCCore.ServerResponse.Single<Echo_EchoResponse>
171+
) async throws -> GRPCCore.ServerResponse<Echo_EchoResponse>
172172

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

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

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

192192
/// Partial conformance to `Echo_Echo_StreamingServiceProtocol`.
193193
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
194194
extension Echo_Echo.ServiceProtocol {
195195
internal func get(
196-
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
196+
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
197197
context: GRPCCore.ServerContext
198-
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse> {
198+
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse> {
199199
let response = try await self.get(
200-
request: GRPCCore.ServerRequest.Single(stream: request),
200+
request: GRPCCore.ServerRequest(stream: request),
201201
context: context
202202
)
203-
return GRPCCore.ServerResponse.Stream(single: response)
203+
return GRPCCore.StreamingServerResponse(single: response)
204204
}
205205

206206
internal func expand(
207-
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
207+
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
208208
context: GRPCCore.ServerContext
209-
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse> {
209+
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse> {
210210
let response = try await self.expand(
211-
request: GRPCCore.ServerRequest.Single(stream: request),
211+
request: GRPCCore.ServerRequest(stream: request),
212212
context: context
213213
)
214214
return response
215215
}
216216

217217
internal func collect(
218-
request: GRPCCore.ServerRequest.Stream<Echo_EchoRequest>,
218+
request: GRPCCore.StreamingServerRequest<Echo_EchoRequest>,
219219
context: GRPCCore.ServerContext
220-
) async throws -> GRPCCore.ServerResponse.Stream<Echo_EchoResponse> {
220+
) async throws -> GRPCCore.StreamingServerResponse<Echo_EchoResponse> {
221221
let response = try await self.collect(
222222
request: request,
223223
context: context
224224
)
225-
return GRPCCore.ServerResponse.Stream(single: response)
225+
return GRPCCore.StreamingServerResponse(single: response)
226226
}
227227
}
228228

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

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

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

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

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

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

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

316316
internal func update<R>(
317-
request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
317+
request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
318318
options: GRPCCore.CallOptions = .defaults,
319-
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
319+
_ body: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> R
320320
) async throws -> R where R: Sendable {
321321
try await self.update(
322322
request: request,
@@ -335,11 +335,11 @@ extension Echo_Echo.ClientProtocol {
335335
_ message: Echo_EchoRequest,
336336
metadata: GRPCCore.Metadata = [:],
337337
options: GRPCCore.CallOptions = .defaults,
338-
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> Result = {
338+
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result = {
339339
try $0.message
340340
}
341341
) async throws -> Result where Result: Sendable {
342-
let request = GRPCCore.ClientRequest.Single<Echo_EchoRequest>(
342+
let request = GRPCCore.ClientRequest<Echo_EchoRequest>(
343343
message: message,
344344
metadata: metadata
345345
)
@@ -355,9 +355,9 @@ extension Echo_Echo.ClientProtocol {
355355
_ message: Echo_EchoRequest,
356356
metadata: GRPCCore.Metadata = [:],
357357
options: GRPCCore.CallOptions = .defaults,
358-
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> Result
358+
onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
359359
) async throws -> Result where Result: Sendable {
360-
let request = GRPCCore.ClientRequest.Single<Echo_EchoRequest>(
360+
let request = GRPCCore.ClientRequest<Echo_EchoRequest>(
361361
message: message,
362362
metadata: metadata
363363
)
@@ -373,11 +373,11 @@ extension Echo_Echo.ClientProtocol {
373373
metadata: GRPCCore.Metadata = [:],
374374
options: GRPCCore.CallOptions = .defaults,
375375
requestProducer: @Sendable @escaping (GRPCCore.RPCWriter<Echo_EchoRequest>) async throws -> Void,
376-
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Single<Echo_EchoResponse>) async throws -> Result = {
376+
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Echo_EchoResponse>) async throws -> Result = {
377377
try $0.message
378378
}
379379
) async throws -> Result where Result: Sendable {
380-
let request = GRPCCore.ClientRequest.Stream<Echo_EchoRequest>(
380+
let request = GRPCCore.StreamingClientRequest<Echo_EchoRequest>(
381381
metadata: metadata,
382382
producer: requestProducer
383383
)
@@ -393,9 +393,9 @@ extension Echo_Echo.ClientProtocol {
393393
metadata: GRPCCore.Metadata = [:],
394394
options: GRPCCore.CallOptions = .defaults,
395395
requestProducer: @Sendable @escaping (GRPCCore.RPCWriter<Echo_EchoRequest>) async throws -> Void,
396-
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> Result
396+
onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> Result
397397
) async throws -> Result where Result: Sendable {
398-
let request = GRPCCore.ClientRequest.Stream<Echo_EchoRequest>(
398+
let request = GRPCCore.StreamingClientRequest<Echo_EchoRequest>(
399399
metadata: metadata,
400400
producer: requestProducer
401401
)
@@ -417,11 +417,11 @@ internal struct Echo_Echo_Client: Echo_Echo.ClientProtocol {
417417

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

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

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

476476
/// Streams back messages as they are received in an input stream.
477477
internal func update<R>(
478-
request: GRPCCore.ClientRequest.Stream<Echo_EchoRequest>,
478+
request: GRPCCore.StreamingClientRequest<Echo_EchoRequest>,
479479
serializer: some GRPCCore.MessageSerializer<Echo_EchoRequest>,
480480
deserializer: some GRPCCore.MessageDeserializer<Echo_EchoResponse>,
481481
options: GRPCCore.CallOptions = .defaults,
482-
_ body: @Sendable @escaping (GRPCCore.ClientResponse.Stream<Echo_EchoResponse>) async throws -> R
482+
_ body: @Sendable @escaping (GRPCCore.StreamingClientResponse<Echo_EchoResponse>) async throws -> R
483483
) async throws -> R where R: Sendable {
484484
try await self.client.bidirectionalStreaming(
485485
request: request,

Examples/echo/Sources/Subcommands/Serve.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,26 @@ struct Serve: AsyncParsableCommand {
4545
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
4646
struct EchoService: Echo_Echo_ServiceProtocol {
4747
func get(
48-
request: ServerRequest.Single<Echo_EchoRequest>,
48+
request: ServerRequest<Echo_EchoRequest>,
4949
context: ServerContext
50-
) async throws -> ServerResponse.Single<Echo_EchoResponse> {
51-
return ServerResponse.Single(message: .with { $0.text = request.message.text })
50+
) async throws -> ServerResponse<Echo_EchoResponse> {
51+
return ServerResponse(message: .with { $0.text = request.message.text })
5252
}
5353

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

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

7575
func update(
76-
request: ServerRequest.Stream<Echo_EchoRequest>,
76+
request: StreamingServerRequest<Echo_EchoRequest>,
7777
context: ServerContext
78-
) async throws -> ServerResponse.Stream<Echo_EchoResponse> {
79-
return ServerResponse.Stream { writer in
78+
) async throws -> StreamingServerResponse<Echo_EchoResponse> {
79+
return StreamingServerResponse { writer in
8080
for try await message in request.messages {
8181
try await writer.write(.with { $0.text = message.text })
8282
}

0 commit comments

Comments
 (0)