Skip to content

Commit

Permalink
Tolerate a message called Unit when generating gRPC services. Fixes s…
Browse files Browse the repository at this point in the history
  • Loading branch information
Grogs authored Apr 19, 2021
1 parent 55239a9 commit 5232a20
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class GrpcServicePrinter(service: ServiceDescriptor, implicits: Descriptor
case StreamType.ClientStreaming =>
s"(responseObserver: ${observer(method.outputType.scalaType)}): ${observer(method.inputType.scalaType)}"
case StreamType.ServerStreaming =>
s"(request: ${method.inputType.scalaType}, responseObserver: ${observer(method.outputType.scalaType)}): Unit"
s"(request: ${method.inputType.scalaType}, responseObserver: ${observer(method.outputType.scalaType)}): _root_.scala.Unit"
case StreamType.Bidirectional =>
s"(responseObserver: ${observer(method.outputType.scalaType)}): ${observer(method.inputType.scalaType)}"
})
Expand Down Expand Up @@ -208,15 +208,15 @@ final class GrpcServicePrinter(service: ServiceDescriptor, implicits: Descriptor
val serverMethod =
s"$serverCalls.UnaryMethod[${method.inputType.scalaType}, ${method.outputType.scalaType}]"
p.add(s"""$call(new $serverMethod {
| override def invoke(request: ${method.inputType.scalaType}, observer: $streamObserver[${method.outputType.scalaType}]): Unit =
| override def invoke(request: ${method.inputType.scalaType}, observer: $streamObserver[${method.outputType.scalaType}]): _root_.scala.Unit =
| $serviceImpl.${method.name}(request).onComplete(scalapb.grpc.Grpc.completeObserver(observer))(
| $executionContext)
|}))""".stripMargin)
case StreamType.ServerStreaming =>
val serverMethod =
s"$serverCalls.ServerStreamingMethod[${method.inputType.scalaType}, ${method.outputType.scalaType}]"
p.add(s"""$call(new $serverMethod {
| override def invoke(request: ${method.inputType.scalaType}, observer: $streamObserver[${method.outputType.scalaType}]): Unit =
| override def invoke(request: ${method.inputType.scalaType}, observer: $streamObserver[${method.outputType.scalaType}]): _root_.scala.Unit =
| $serviceImpl.${method.name}(request, observer)
|}))""".stripMargin)
case _ =>
Expand Down
5 changes: 4 additions & 1 deletion e2e-grpc/src/main/protobuf/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ message SealedResponse {
}
}

// https://github.com/scalapb/ScalaPB/issues/1126
message Unit {}

extend google.protobuf.MethodOptions {
string custom_option = 50001;
}
Expand All @@ -57,7 +60,7 @@ extend google.protobuf.ServiceOptions {

service Service1 {
option (custom_service_option) = "custom_service_value";

// Computes string length
rpc UnaryStringLength(Req1) returns (Res1) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.thesamet.pb

import java.util.concurrent.atomic.AtomicInteger

import com.thesamet.proto.e2e.Service._
import com.thesamet.proto.e2e.Service.{Unit=>_, _}
import com.thesamet.proto.e2e.Service1Grpc._
import io.grpc.stub.StreamObserver

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger

import com.thesamet.proto.e2e.service.SealedRequest
import com.thesamet.proto.e2e.service.Service1Grpc.Service1
import com.thesamet.proto.e2e.service._
import com.thesamet.proto.e2e.service.{Unit=>_, _}
import io.grpc.stub.StreamObserver

import scala.concurrent.Future
Expand Down

0 comments on commit 5232a20

Please sign in to comment.