Skip to content

Commit

Permalink
Pass safe and idempotent options to the MethodDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-vovk committed Nov 28, 2024
1 parent f515f96 commit f472ae9
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package scalapb.compiler

import com.google.protobuf.DescriptorProtos.MethodOptions.IdempotencyLevel
import com.google.protobuf.Descriptors.{MethodDescriptor, ServiceDescriptor}
import scalapb.compiler.FunctionalPrinter.PrinterEndo
import scalapb.compiler.ProtobufGenerator.asScalaDocBlock
Expand Down Expand Up @@ -179,12 +180,18 @@ final class GrpcServicePrinter(service: ServiceDescriptor, implicits: Descriptor

val grpcMethodDescriptor = "_root_.io.grpc.MethodDescriptor"

val idempotencyLevel = method.getOptions.getIdempotencyLevel
val safe = idempotencyLevel == IdempotencyLevel.NO_SIDE_EFFECTS
val idempotent = idempotencyLevel == IdempotencyLevel.IDEMPOTENT

p.add(
s"""${method.deprecatedAnnotation}val ${method.grpcDescriptor.nameSymbol}: $grpcMethodDescriptor[${method.inputType.scalaType}, ${method.outputType.scalaType}] =
| $grpcMethodDescriptor.newBuilder()
| .setType($grpcMethodDescriptor.MethodType.$methodType)
| .setFullMethodName($grpcMethodDescriptor.generateFullMethodName("${service.getFullName}", "${method.getName}"))
| .setSampledToLocalTracing(true)
| .setSafe($safe)
| .setIdempotent($idempotent)
| .setRequestMarshaller(${marshaller(method.inputType)})
| .setResponseMarshaller(${marshaller(method.outputType)})
| .setSchemaDescriptor(_root_.scalapb.grpc.ConcreteProtoMethodDescriptorSupplier.fromMethodDescriptor(${method.javaDescriptorSource}))
Expand Down

0 comments on commit f472ae9

Please sign in to comment.