Skip to content

Commit

Permalink
Expose service descriptors in companion object.
Browse files Browse the repository at this point in the history
Fixes #111
  • Loading branch information
thesamet committed May 8, 2016
1 parent 5e80150 commit a754b35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Expand Up @@ -223,7 +223,7 @@ final class GrpcServicePrinter(service: ServiceDescriptor, override val params:
printer.add(
"package " + service.getFile.scalaPackageName,
"",
s"object ${service.objectName} {"
s"object ${service.objectName} extends _root_.com.trueaccord.scalapb.grpc.ServiceCompanion {"
).newline.withIndent(
_.call(service.methods.map(methodDescriptor): _*),
serviceTrait,
Expand All @@ -238,7 +238,9 @@ final class GrpcServicePrinter(service: ServiceDescriptor, override val params:
_.newline,
_.add(s"def blockingStub(channel: $channel): ${service.blockingStub} = new ${service.blockingStub}(channel)"),
_.newline,
_.add(s"def stub(channel: $channel): ${service.stub} = new ${service.stub}(channel)")
_.add(s"def stub(channel: $channel): ${service.stub} = new ${service.stub}(channel)"),
_.newline,
_.add(s"def descriptor: _root_.com.google.protobuf.Descriptors.ServiceDescriptor = ${service.getFile.fileDescriptorObjectFullName}.descriptor.getServices().get(${service.getIndex})")
)
.add("}")
}
Expand Down
6 changes: 6 additions & 0 deletions e2e/src/test/scala/GrpcServiceScalaServerSpec.scala
Expand Up @@ -5,6 +5,12 @@ import scala.concurrent.duration._
import scala.util.Random

class GrpcServiceScalaServerSpec extends GrpcServiceSpecBase {
describe("scala companion object") {
it("provides descriptor object") {
import com.trueaccord.proto.e2e.service.{Service1Grpc => Service1GrpcScala}
Service1GrpcScala.descriptor.getName must be("Service1")
}
}

describe("scala server") {

Expand Down
@@ -0,0 +1,7 @@
package com.trueaccord.scalapb.grpc

import com.google.protobuf.Descriptors.ServiceDescriptor

abstract class ServiceCompanion {
def descriptor: ServiceDescriptor
}

0 comments on commit a754b35

Please sign in to comment.