|
| 1 | +package hello.world |
| 2 | + |
| 3 | +import _root_.cats.syntax.all._ |
| 4 | + |
| 5 | +/** TestService: Example gRPC service used in e2e tests |
| 6 | + * It demonstrates all four RPC shapes. |
| 7 | + */ |
| 8 | +trait TestServiceFs2GrpcDisableTrailers[F[_], A] { |
| 9 | + /** Unary RPC: no streaming in either direction |
| 10 | + */ |
| 11 | + def noStreaming(request: hello.world.TestMessage, ctx: A): F[hello.world.TestMessage] |
| 12 | + /** Client streaming RPC: client streams, server returns a single response |
| 13 | + */ |
| 14 | + def clientStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage], ctx: A): F[hello.world.TestMessage] |
| 15 | + /** Server streaming RPC: client sends one request, server streams responses |
| 16 | + */ |
| 17 | + def serverStreaming(request: hello.world.TestMessage, ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage] |
| 18 | + /** Bidirectional streaming RPC: both client and server stream |
| 19 | + */ |
| 20 | + def bothStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage], ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage] |
| 21 | +} |
| 22 | + |
| 23 | +object TestServiceFs2GrpcDisableTrailers extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2GrpcDisableTrailers] { |
| 24 | + |
| 25 | + def serviceDescriptor: _root_.io.grpc.ServiceDescriptor = hello.world.TestServiceGrpc.SERVICE |
| 26 | + |
| 27 | + def mkClientFull[F[_], G[_]: _root_.cats.effect.Async, A]( |
| 28 | + dispatcher: _root_.cats.effect.std.Dispatcher[G], |
| 29 | + channel: _root_.io.grpc.Channel, |
| 30 | + clientAspect: _root_.fs2.grpc.client.ClientAspect[F, G, A], |
| 31 | + clientOptions: _root_.fs2.grpc.client.ClientOptions |
| 32 | + ): TestServiceFs2GrpcDisableTrailers[F, A] = new TestServiceFs2GrpcDisableTrailers[F, A] { |
| 33 | + def noStreaming(request: hello.world.TestMessage, ctx: A): F[hello.world.TestMessage] = |
| 34 | + clientAspect.visitUnaryToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]( |
| 35 | + _root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_NO_STREAMING), |
| 36 | + request, |
| 37 | + (req, m) => _root_.fs2.grpc.client.Fs2ClientCall[G](channel, hello.world.TestServiceGrpc.METHOD_NO_STREAMING, dispatcher, clientOptions).flatMap(_.unaryToUnaryCall(req, m)) |
| 38 | + ) |
| 39 | + def clientStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage], ctx: A): F[hello.world.TestMessage] = |
| 40 | + clientAspect.visitStreamingToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]( |
| 41 | + _root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_CLIENT_STREAMING), |
| 42 | + request, |
| 43 | + (req, m) => _root_.fs2.grpc.client.Fs2ClientCall[G](channel, hello.world.TestServiceGrpc.METHOD_CLIENT_STREAMING, dispatcher, clientOptions).flatMap(_.streamingToUnaryCall(req, m)) |
| 44 | + ) |
| 45 | + def serverStreaming(request: hello.world.TestMessage, ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage] = |
| 46 | + clientAspect.visitUnaryToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]( |
| 47 | + _root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_SERVER_STREAMING), |
| 48 | + request, |
| 49 | + (req, m) => _root_.fs2.Stream.eval(_root_.fs2.grpc.client.Fs2ClientCall[G](channel, hello.world.TestServiceGrpc.METHOD_SERVER_STREAMING, dispatcher, clientOptions)).flatMap(_.unaryToStreamingCall(req, m)) |
| 50 | + ) |
| 51 | + def bothStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage], ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage] = |
| 52 | + clientAspect.visitStreamingToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]( |
| 53 | + _root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_BOTH_STREAMING), |
| 54 | + request, |
| 55 | + (req, m) => _root_.fs2.Stream.eval(_root_.fs2.grpc.client.Fs2ClientCall[G](channel, hello.world.TestServiceGrpc.METHOD_BOTH_STREAMING, dispatcher, clientOptions)).flatMap(_.streamingToStreamingCall(req, m)) |
| 56 | + ) |
| 57 | + } |
| 58 | + |
| 59 | + protected def serviceBindingFull[F[_], G[_]: _root_.cats.effect.Async, A]( |
| 60 | + dispatcher: _root_.cats.effect.std.Dispatcher[G], |
| 61 | + serviceImpl: TestServiceFs2GrpcDisableTrailers[F, A], |
| 62 | + serviceAspect: _root_.fs2.grpc.server.ServiceAspect[F, G, A], |
| 63 | + serverOptions: _root_.fs2.grpc.server.ServerOptions |
| 64 | + ) = { |
| 65 | + _root_.io.grpc.ServerServiceDefinition |
| 66 | + .builder(hello.world.TestServiceGrpc.SERVICE) |
| 67 | + .addMethod( |
| 68 | + hello.world.TestServiceGrpc.METHOD_NO_STREAMING, |
| 69 | + _root_.fs2.grpc.server.Fs2ServerCallHandler[G](dispatcher, serverOptions).unaryToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]{ (r, m) => |
| 70 | + serviceAspect.visitUnaryToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]( |
| 71 | + _root_.fs2.grpc.server.ServiceCallContext(m, hello.world.TestServiceGrpc.METHOD_NO_STREAMING), |
| 72 | + r, |
| 73 | + (r, m) => serviceImpl.noStreaming(r, m) |
| 74 | + ) |
| 75 | + } |
| 76 | + ) |
| 77 | + .addMethod( |
| 78 | + hello.world.TestServiceGrpc.METHOD_CLIENT_STREAMING, |
| 79 | + _root_.fs2.grpc.server.Fs2ServerCallHandler[G](dispatcher, serverOptions).streamingToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]{ (r, m) => |
| 80 | + serviceAspect.visitStreamingToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]( |
| 81 | + _root_.fs2.grpc.server.ServiceCallContext(m, hello.world.TestServiceGrpc.METHOD_CLIENT_STREAMING), |
| 82 | + r, |
| 83 | + (r, m) => serviceImpl.clientStreaming(r, m) |
| 84 | + ) |
| 85 | + } |
| 86 | + ) |
| 87 | + .addMethod( |
| 88 | + hello.world.TestServiceGrpc.METHOD_SERVER_STREAMING, |
| 89 | + _root_.fs2.grpc.server.Fs2ServerCallHandler[G](dispatcher, serverOptions).unaryToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]{ (r, m) => |
| 90 | + serviceAspect.visitUnaryToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]( |
| 91 | + _root_.fs2.grpc.server.ServiceCallContext(m, hello.world.TestServiceGrpc.METHOD_SERVER_STREAMING), |
| 92 | + r, |
| 93 | + (r, m) => serviceImpl.serverStreaming(r, m) |
| 94 | + ) |
| 95 | + } |
| 96 | + ) |
| 97 | + .addMethod( |
| 98 | + hello.world.TestServiceGrpc.METHOD_BOTH_STREAMING, |
| 99 | + _root_.fs2.grpc.server.Fs2ServerCallHandler[G](dispatcher, serverOptions).streamingToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]{ (r, m) => |
| 100 | + serviceAspect.visitStreamingToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]( |
| 101 | + _root_.fs2.grpc.server.ServiceCallContext(m, hello.world.TestServiceGrpc.METHOD_BOTH_STREAMING), |
| 102 | + r, |
| 103 | + (r, m) => serviceImpl.bothStreaming(r, m) |
| 104 | + ) |
| 105 | + } |
| 106 | + ) |
| 107 | + .build() |
| 108 | + } |
| 109 | + |
| 110 | +} |
0 commit comments