akka.grpc.gen.CodeGenerator.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
import com.google.protobuf.ExtensionRegistry
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse
import protocbridge.Artifact
/**
* Code generator trait that is not directly bound to scala-pb or protoc (other than the types).
*/
trait CodeGenerator {
import CodeGenerator._
/** Generator name; example: `akka-grpc-scala` */
def name: String
def run(request: CodeGeneratorRequest, logger: Logger): CodeGeneratorResponse
/** Takes Scala binary version and returns suggested dependency Seq */
def suggestedDependencies: ScalaBinaryVersion => Seq[Artifact]
def registerExtensions(registry: ExtensionRegistry): Unit = {}
final def run(request: Array[Byte], logger: Logger): Array[Byte] = {
val registry = ExtensionRegistry.newInstance
registerExtensions(registry)
run(CodeGeneratorRequest.parseFrom(request, registry), logger: Logger).toByteArray
}
}
object CodeGenerator {
/** Holds the prefix of a given Scala binary version */
case class ScalaBinaryVersion(prefix: String)
}