All Downloads are FREE. Search and download functionalities are using the official Maven repository.

akka.grpc.gen.scaladsl.ScalaMarshallersCodeGenerator.scala Maven / Gradle / Ivy

Go to download

Akka gRPC - Support for building streaming gRPC servers and clients on top of Akka Streams.

There is a newer version: 2.3.4
Show newest version
/*
 * 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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy