akka.grpc.gen.scaladsl.ScalaMarshallersCodeGenerator.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.12 Show documentation
Show all versions of akka-grpc-codegen_2.12 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.annotation.nowarn
import scala.collection.immutable
import akka.grpc.gen.{ BuildInfo, CodeGenerator, Logger }
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse
import protocbridge.Artifact
import templates.ScalaCommon.txt._
/**
* Has to be a separate generator rather than a parameter to the existing ones, because
* it introduces a suggestedDependency on akka-http.
*/
trait ScalaMarshallersCodeGenerator extends ScalaCodeGenerator {
def name = "akka-grpc-scaladsl-server-marshallers"
override def perServiceContent = Set(generateMarshalling)
override def suggestedDependencies =
(scalaBinaryVersion: CodeGenerator.ScalaBinaryVersion) =>
Artifact("com.typesafe.akka", s"akka-http_${scalaBinaryVersion.prefix}", BuildInfo.akkaHttpVersion) +: super
.suggestedDependencies(scalaBinaryVersion)
def generateMarshalling(
@nowarn("cat=unused-params") logger: Logger,
service: Service): immutable.Seq[CodeGeneratorResponse.File] = {
val b = CodeGeneratorResponse.File.newBuilder()
b.setContent(Marshallers(service).body)
b.setName(s"${service.packageDir}/${service.name}Marshallers.scala")
immutable.Seq(b.build)
}
}
object ScalaMarshallersCodeGenerator extends ScalaMarshallersCodeGenerator