Skip to content

Commit

Permalink
Add service descriptor to code generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Gorzen committed Sep 2, 2024
1 parent 27422f9 commit 8607cdf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,21 @@ abstract class Fs2AbstractServicePrinter extends Fs2ServicePrinter {

private[this] def serviceObject: PrinterEndo =
_.add(s"object $serviceNameFs2 extends $Companion[$serviceNameFs2] {").indent.newline
.call(serviceDescriptor)
.newline
.call(serviceClient)
.newline
.call(serviceBinding)
.outdent
.newline
.add("}")

private[this] def serviceDescriptor: PrinterEndo = {
_.add(
s"def serviceDescriptor: ${Fs2AbstractServicePrinter.constants.ServiceDescriptor} = ${service.grpcDescriptor.fullName}"
)
}

private[this] def serviceClient: PrinterEndo = {
_.add(
s"def mkClient[F[_]: $Async, $Ctx](dispatcher: $Dispatcher[F], channel: $Channel, mkMetadata: $Ctx => F[$Metadata], clientOptions: $ClientOptions): $serviceNameFs2[F, $Ctx] = new $serviceNameFs2[F, $Ctx] {"
Expand Down Expand Up @@ -170,6 +178,7 @@ object Fs2AbstractServicePrinter {
val ServerServiceDefinition = s"$grpcPkg.ServerServiceDefinition"
val Channel = s"$grpcPkg.Channel"
val Metadata = s"$grpcPkg.Metadata"
val ServiceDescriptor = s"$grpcPkg.ServiceDescriptor"

}

Expand Down
2 changes: 2 additions & 0 deletions e2e/src/test/resources/TestServiceFs2Grpc.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ trait TestServiceFs2Grpc[F[_], A] {

object TestServiceFs2Grpc extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2Grpc] {

def serviceDescriptor: _root_.io.grpc.ServiceDescriptor = hello.world.TestServiceGrpc.SERVICE

def mkClient[F[_]: _root_.cats.effect.Async, A](dispatcher: _root_.cats.effect.std.Dispatcher[F], channel: _root_.io.grpc.Channel, mkMetadata: A => F[_root_.io.grpc.Metadata], clientOptions: _root_.fs2.grpc.client.ClientOptions): TestServiceFs2Grpc[F, A] = new TestServiceFs2Grpc[F, A] {
def noStreaming(request: hello.world.TestMessage, ctx: A): F[hello.world.TestMessage] = {
mkMetadata(ctx).flatMap { m =>
Expand Down
2 changes: 2 additions & 0 deletions e2e/src/test/resources/TestServiceFs2GrpcTrailers.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ trait TestServiceFs2GrpcTrailers[F[_], A] {

object TestServiceFs2GrpcTrailers extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2GrpcTrailers] {

def serviceDescriptor: _root_.io.grpc.ServiceDescriptor = hello.world.TestServiceGrpc.SERVICE

def mkClient[F[_]: _root_.cats.effect.Async, A](dispatcher: _root_.cats.effect.std.Dispatcher[F], channel: _root_.io.grpc.Channel, mkMetadata: A => F[_root_.io.grpc.Metadata], clientOptions: _root_.fs2.grpc.client.ClientOptions): TestServiceFs2GrpcTrailers[F, A] = new TestServiceFs2GrpcTrailers[F, A] {
def noStreaming(request: hello.world.TestMessage, ctx: A): F[(hello.world.TestMessage, _root_.io.grpc.Metadata)] = {
mkMetadata(ctx).flatMap { m =>
Expand Down
4 changes: 4 additions & 0 deletions runtime/src/main/scala/fs2/grpc/GeneratedCompanion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ trait GeneratedCompanion[Service[*[_], _]] {

implicit final def serviceCompanion: GeneratedCompanion[Service] = this

/// === ServiceDescriptor ==============================================================================================

def serviceDescriptor: ServiceDescriptor

///=== Client ==========================================================================================================

def mkClient[F[_]: Async, A](
Expand Down

0 comments on commit 8607cdf

Please sign in to comment.