akka.grpc.gen.scaladsl.Service.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of akka-grpc-codegen_2.13 Show documentation
Show all versions of akka-grpc-codegen_2.13 Show documentation
Akka gRPC - Support for building streaming gRPC servers and clients on top of Akka Streams.
/*
* Copyright (C) 2018-2021 Lightbend Inc.
*/
package akka.grpc.gen.scaladsl
import scala.collection.immutable
import scala.collection.JavaConverters._
import com.google.protobuf.Descriptors._
import protocgen.CodeGenRequest
import scalapb.compiler.{ DescriptorImplicits, GeneratorParams }
case class Service(
descriptor: String,
packageName: String,
name: String,
grpcName: String,
methods: immutable.Seq[Method],
serverPowerApi: Boolean,
usePlayActions: Boolean,
options: com.google.protobuf.DescriptorProtos.ServiceOptions,
comment: Option[String] = None) {
def serializers: Seq[Serializer] = (methods.map(_.deserializer) ++ methods.map(_.serializer)).distinct
def packageDir = packageName.replace('.', '/')
}
object Service {
def apply(
request: CodeGenRequest,
generatorParams: GeneratorParams,
fileDesc: FileDescriptor,
serviceDescriptor: ServiceDescriptor,
serverPowerApi: Boolean,
usePlayActions: Boolean): Service = {
implicit val ops =
DescriptorImplicits.fromCodeGenRequest(generatorParams, request)
import ops._
val serviceClassName = serviceDescriptor.getName
Service(
fileDesc.fileDescriptorObject.fullName + ".javaDescriptor",
fileDesc.scalaPackage.fullName,
serviceClassName,
(if (fileDesc.getPackage.isEmpty) "" else fileDesc.getPackage + ".") + serviceDescriptor.getName,
serviceDescriptor.getMethods.asScala.map(method => Method(method)).toList,
serverPowerApi,
usePlayActions,
serviceDescriptor.getOptions,
serviceDescriptor.comment)
}
}