Skip to content

Commit a1823b3

Browse files
committed
Adds support for generating the explicit streaming calls in the kotlin generator
1 parent c56d501 commit a1823b3

File tree

8 files changed

+91
-15
lines changed

8 files changed

+91
-15
lines changed

wire-compiler/api/wire-compiler.api

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public final class com/squareup/wire/DryRunFileSystem : okio/ForwardingFileSyste
88
public final class com/squareup/wire/WireCompiler {
99
public static final field CODE_GENERATED_BY_WIRE Ljava/lang/String;
1010
public static final field Companion Lcom/squareup/wire/WireCompiler$Companion;
11-
public synthetic fun <init> (Lokio/FileSystem;Lcom/squareup/wire/WireLogger;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/Map;ZZZZZZZZIZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZLjava/lang/String;ZZZLjava/util/List;Ljava/util/Map;Ljava/util/List;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
11+
public synthetic fun <init> (Lokio/FileSystem;Lcom/squareup/wire/WireLogger;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/Map;ZZZZZZZZIZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZLjava/lang/String;ZZZZLjava/util/List;Ljava/util/Map;Ljava/util/List;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
1212
public final fun compile ()V
1313
public static final fun forArgs (Ljava/nio/file/FileSystem;Lcom/squareup/wire/WireLogger;[Ljava/lang/String;)Lcom/squareup/wire/WireCompiler;
1414
public static final fun forArgs (Lokio/FileSystem;Lcom/squareup/wire/WireLogger;[Ljava/lang/String;)Lcom/squareup/wire/WireCompiler;
@@ -31,6 +31,7 @@ public final class com/squareup/wire/WireCompiler {
3131
public final fun getKotlinBuildersOnly ()Z
3232
public final fun getKotlinEscapeKeywords ()Z
3333
public final fun getKotlinExclusive ()Z
34+
public final fun getKotlinExplicitStreamingCalls ()Z
3435
public final fun getKotlinNameSuffix ()Ljava/lang/String;
3536
public final fun getKotlinOut ()Ljava/lang/String;
3637
public final fun getKotlinRpcCallStyle ()Lcom/squareup/wire/kotlin/RpcCallStyle;
@@ -117,8 +118,8 @@ public final class com/squareup/wire/schema/JavaTarget : com/squareup/wire/schem
117118
}
118119

119120
public final class com/squareup/wire/schema/KotlinTarget : com/squareup/wire/schema/Target {
120-
public fun <init> (Ljava/util/List;Ljava/util/List;ZLjava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZ)V
121-
public synthetic fun <init> (Ljava/util/List;Ljava/util/List;ZLjava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
121+
public fun <init> (Ljava/util/List;Ljava/util/List;ZLjava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZZ)V
122+
public synthetic fun <init> (Ljava/util/List;Ljava/util/List;ZLjava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
122123
public final fun component1 ()Ljava/util/List;
123124
public final fun component10 ()Lcom/squareup/wire/kotlin/RpcRole;
124125
public final fun component11 ()Z
@@ -135,8 +136,8 @@ public final class com/squareup/wire/schema/KotlinTarget : com/squareup/wire/sch
135136
public final fun component7 ()Z
136137
public final fun component8 ()Z
137138
public final fun component9 ()Lcom/squareup/wire/kotlin/RpcCallStyle;
138-
public final fun copy (Ljava/util/List;Ljava/util/List;ZLjava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZ)Lcom/squareup/wire/schema/KotlinTarget;
139-
public static synthetic fun copy$default (Lcom/squareup/wire/schema/KotlinTarget;Ljava/util/List;Ljava/util/List;ZLjava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZILjava/lang/Object;)Lcom/squareup/wire/schema/KotlinTarget;
139+
public final fun copy (Ljava/util/List;Ljava/util/List;ZLjava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZZ)Lcom/squareup/wire/schema/KotlinTarget;
140+
public static synthetic fun copy$default (Lcom/squareup/wire/schema/KotlinTarget;Ljava/util/List;Ljava/util/List;ZLjava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZZILjava/lang/Object;)Lcom/squareup/wire/schema/KotlinTarget;
140141
public fun copyTarget (Ljava/util/List;Ljava/util/List;ZLjava/lang/String;)Lcom/squareup/wire/schema/Target;
141142
public fun equals (Ljava/lang/Object;)Z
142143
public final fun getAndroid ()Z

wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class WireCompiler internal constructor(
142142
val kotlinBuildersOnly: Boolean,
143143
val kotlinEscapeKeywords: Boolean,
144144
val emitProtoReader32: Boolean,
145+
val kotlinExplicitStreamingCalls: Boolean,
145146
val eventListenerFactoryClasses: List<String>,
146147
val customOptions: Map<String, String>,
147148
val opaqueTypes: List<String> = listOf(),
@@ -177,6 +178,7 @@ class WireCompiler internal constructor(
177178
buildersOnly = kotlinBuildersOnly,
178179
escapeKotlinKeywords = kotlinEscapeKeywords,
179180
emitProtoReader32 = emitProtoReader32,
181+
explicitStreamingCalls = kotlinExplicitStreamingCalls,
180182
)
181183
}
182184
if (swiftOut != null) {
@@ -290,6 +292,7 @@ class WireCompiler internal constructor(
290292
private const val EMIT_PROTO_READER_32 = "--emit_proto_reader_32"
291293
private const val CUSTOM_OPTION_FLAG = "--custom_option="
292294
private const val OPAQUE_TYPES_FLAG = "--opaque_types="
295+
private const val KOTLIN_EXPLICIT_STREAMING_CALLS = "--kotlin_explicit_streaming_calls"
293296

294297
@Throws(IOException::class)
295298
@JvmStatic
@@ -353,6 +356,7 @@ class WireCompiler internal constructor(
353356
var kotlinBuildersOnly = false
354357
var kotlinEscapeKeywords = false
355358
var emitProtoReader32 = false
359+
var kotlinExplicitStreamingCalls = false
356360
var dryRun = false
357361
val customOptions = mutableMapOf<String, String>()
358362
val opaqueTypes = mutableListOf<String>()
@@ -473,6 +477,7 @@ class WireCompiler internal constructor(
473477
arg == LOAD_EXHAUSTIVELY -> loadExhaustively = true
474478
arg == JAVA_INTEROP -> javaInterop = true
475479
arg == EMIT_PROTO_READER_32 -> emitProtoReader32 = true
480+
arg == KOTLIN_EXPLICIT_STREAMING_CALLS -> kotlinExplicitStreamingCalls = true
476481
arg.startsWith("--") -> throw IllegalArgumentException("Unknown argument '$arg'.")
477482
else -> sourceFileNames.add(arg)
478483
}
@@ -527,6 +532,7 @@ class WireCompiler internal constructor(
527532
eventListenerFactoryClasses = eventListenerFactoryClasses,
528533
customOptions = customOptions,
529534
opaqueTypes = opaqueTypes,
535+
kotlinExplicitStreamingCalls = kotlinExplicitStreamingCalls,
530536
)
531537
}
532538
}

wire-compiler/src/main/java/com/squareup/wire/schema/Target.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ data class KotlinTarget(
147147
* If true, the generated classes will be mutable..
148148
*/
149149
private val mutableTypes: Boolean = false,
150+
151+
/**
152+
* If true, the generated gRPC client will use explicit classes for client, server,
153+
* and bidirectional streaming calls.
154+
*/
155+
private val explicitStreamingCalls: Boolean = false,
156+
150157
) : Target() {
151158
override fun newHandler(): SchemaHandler {
152159
return KotlinSchemaHandler(
@@ -165,6 +172,7 @@ data class KotlinTarget(
165172
enumMode = enumMode,
166173
emitProtoReader32 = emitProtoReader32,
167174
mutableTypes = mutableTypes,
175+
explicitStreamingCalls = explicitStreamingCalls,
168176
)
169177
}
170178

wire-gradle-plugin/api/wire-gradle-plugin.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class com/squareup/wire/gradle/KotlinOutput : com/squareup/wire/gradle/Wi
5252
public final fun getEscapeKotlinKeywords ()Z
5353
public final fun getExcludes ()Ljava/util/List;
5454
public final fun getExclusive ()Z
55+
public final fun getExplicitStreamingCalls ()Z
5556
public final fun getGrpcServerCompatible ()Z
5657
public final fun getIncludes ()Ljava/util/List;
5758
public final fun getJavaInterop ()Z
@@ -70,6 +71,7 @@ public class com/squareup/wire/gradle/KotlinOutput : com/squareup/wire/gradle/Wi
7071
public final fun setEscapeKotlinKeywords (Z)V
7172
public final fun setExcludes (Ljava/util/List;)V
7273
public final fun setExclusive (Z)V
74+
public final fun setExplicitStreamingCalls (Z)V
7375
public final fun setGrpcServerCompatible (Z)V
7476
public final fun setIncludes (Ljava/util/List;)V
7577
public final fun setJavaInterop (Z)V

wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireOutput.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ open class KotlinOutput @Inject constructor() : WireOutput() {
159159
*/
160160
var mutableTypes: Boolean = false
161161

162+
/**
163+
* If true, the generated gRPC client will use explicit classes for client, server,
164+
* and bidirectional streaming calls.
165+
*/
166+
var explicitStreamingCalls: Boolean = false
167+
162168
override fun toTarget(outputDirectory: String): KotlinTarget {
163169
if (grpcServerCompatible) {
164170
throw IllegalArgumentException(
@@ -203,6 +209,7 @@ open class KotlinOutput @Inject constructor() : WireOutput() {
203209
enumMode = enumMode,
204210
emitProtoReader32 = emitProtoReader32,
205211
mutableTypes = mutableTypes,
212+
explicitStreamingCalls = explicitStreamingCalls,
206213
)
207214
}
208215
}

wire-kotlin-generator/api/wire-kotlin-generator.api

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public final class com/squareup/wire/kotlin/EnumMode : java/lang/Enum {
88

99
public final class com/squareup/wire/kotlin/KotlinGenerator {
1010
public static final field Companion Lcom/squareup/wire/kotlin/KotlinGenerator$Companion;
11-
public synthetic fun <init> (Lcom/squareup/wire/schema/Schema;Ljava/util/Map;Ljava/util/Map;Lcom/squareup/wire/schema/Profile;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZLkotlin/jvm/internal/DefaultConstructorMarker;)V
11+
public synthetic fun <init> (Lcom/squareup/wire/schema/Schema;Ljava/util/Map;Ljava/util/Map;Lcom/squareup/wire/schema/Profile;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZZLkotlin/jvm/internal/DefaultConstructorMarker;)V
1212
public final fun generateOptionType (Lcom/squareup/wire/schema/Extend;Lcom/squareup/wire/schema/Field;)Lcom/squareup/kotlinpoet/TypeSpec;
1313
public final fun generateServiceTypeSpecs (Lcom/squareup/wire/schema/Service;Lcom/squareup/wire/schema/Rpc;)Ljava/util/Map;
1414
public static synthetic fun generateServiceTypeSpecs$default (Lcom/squareup/wire/kotlin/KotlinGenerator;Lcom/squareup/wire/schema/Service;Lcom/squareup/wire/schema/Rpc;ILjava/lang/Object;)Ljava/util/Map;
@@ -17,20 +17,20 @@ public final class com/squareup/wire/kotlin/KotlinGenerator {
1717
public static synthetic fun generatedServiceName$default (Lcom/squareup/wire/kotlin/KotlinGenerator;Lcom/squareup/wire/schema/Service;Lcom/squareup/wire/schema/Rpc;ZILjava/lang/Object;)Lcom/squareup/kotlinpoet/ClassName;
1818
public final fun generatedTypeName (Lcom/squareup/wire/schema/ProtoMember;)Lcom/squareup/kotlinpoet/ClassName;
1919
public final fun generatedTypeName (Lcom/squareup/wire/schema/Type;)Lcom/squareup/kotlinpoet/ClassName;
20-
public static final fun get (Lcom/squareup/wire/schema/Schema;Lcom/squareup/wire/schema/Profile;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZ)Lcom/squareup/wire/kotlin/KotlinGenerator;
20+
public static final fun get (Lcom/squareup/wire/schema/Schema;Lcom/squareup/wire/schema/Profile;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZZ)Lcom/squareup/wire/kotlin/KotlinGenerator;
2121
public final fun getSchema ()Lcom/squareup/wire/schema/Schema;
2222
}
2323

2424
public final class com/squareup/wire/kotlin/KotlinGenerator$Companion {
2525
public final fun builtInType (Lcom/squareup/wire/schema/ProtoType;)Z
26-
public final fun get (Lcom/squareup/wire/schema/Schema;Lcom/squareup/wire/schema/Profile;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZ)Lcom/squareup/wire/kotlin/KotlinGenerator;
27-
public static synthetic fun get$default (Lcom/squareup/wire/kotlin/KotlinGenerator$Companion;Lcom/squareup/wire/schema/Schema;Lcom/squareup/wire/schema/Profile;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZILjava/lang/Object;)Lcom/squareup/wire/kotlin/KotlinGenerator;
26+
public final fun get (Lcom/squareup/wire/schema/Schema;Lcom/squareup/wire/schema/Profile;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZZ)Lcom/squareup/wire/kotlin/KotlinGenerator;
27+
public static synthetic fun get$default (Lcom/squareup/wire/kotlin/KotlinGenerator$Companion;Lcom/squareup/wire/schema/Schema;Lcom/squareup/wire/schema/Profile;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZZILjava/lang/Object;)Lcom/squareup/wire/kotlin/KotlinGenerator;
2828
}
2929

3030
public final class com/squareup/wire/kotlin/KotlinSchemaHandler : com/squareup/wire/schema/SchemaHandler {
3131
public static final field Companion Lcom/squareup/wire/kotlin/KotlinSchemaHandler$Companion;
32-
public fun <init> (Ljava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZ)V
33-
public synthetic fun <init> (Ljava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
32+
public fun <init> (Ljava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZZ)V
33+
public synthetic fun <init> (Ljava/lang/String;ZZZZLcom/squareup/wire/kotlin/RpcCallStyle;Lcom/squareup/wire/kotlin/RpcRole;ZILjava/lang/String;ZZLcom/squareup/wire/kotlin/EnumMode;ZZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
3434
public final fun getEnumMode ()Lcom/squareup/wire/kotlin/EnumMode;
3535
public fun handle (Lcom/squareup/wire/schema/Extend;Lcom/squareup/wire/schema/Field;Lcom/squareup/wire/schema/SchemaHandler$Context;)Lokio/Path;
3636
public fun handle (Lcom/squareup/wire/schema/Schema;Lcom/squareup/wire/schema/SchemaHandler$Context;)V

wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ import com.squareup.wire.EnumAdapter
5757
import com.squareup.wire.FieldEncoding
5858
import com.squareup.wire.GrpcCall
5959
import com.squareup.wire.GrpcClient
60+
import com.squareup.wire.GrpcClientStreamingCall
6061
import com.squareup.wire.GrpcMethod
62+
import com.squareup.wire.GrpcServerStreamingCall
6163
import com.squareup.wire.GrpcStreamingCall
6264
import com.squareup.wire.Message
6365
import com.squareup.wire.MessageSink
@@ -138,6 +140,7 @@ class KotlinGenerator private constructor(
138140
private val enumMode: EnumMode,
139141
private val emitProtoReader32: Boolean,
140142
private val mutableTypes: Boolean,
143+
private val explicitStreamingCalls: Boolean,
141144
) {
142145
private val nameAllocatorStore = mutableMapOf<Type, NameAllocator>()
143146

@@ -208,6 +211,18 @@ class KotlinGenerator private constructor(
208211
else -> throw IllegalArgumentException("No Array adapter for $type")
209212
}
210213

214+
private val Rpc.clientStreaming: Boolean
215+
get() = requestStreaming && !responseStreaming
216+
217+
private val Rpc.serverStreaming: Boolean
218+
get() = !requestStreaming && responseStreaming
219+
220+
private val Rpc.bidirectionalStreaming: Boolean
221+
get() = requestStreaming && responseStreaming
222+
223+
private val Rpc.streaming
224+
get() = requestStreaming || responseStreaming
225+
211226
/** Returns the full name of the class generated for [type]. */
212227
fun generatedTypeName(type: Type) = type.typeName as ClassName
213228

@@ -385,17 +400,17 @@ class KotlinGenerator private constructor(
385400
funSpecBuilder.addModifiers(KModifier.SUSPEND)
386401
}
387402
when {
388-
rpc.requestStreaming && rpc.responseStreaming -> {
403+
rpc.bidirectionalStreaming -> {
389404
funSpecBuilder
390405
.addParameter("request", readableStreamOf(requestType))
391406
.addParameter("response", writableStreamOf(responseType))
392407
}
393-
rpc.requestStreaming -> {
408+
rpc.clientStreaming -> {
394409
funSpecBuilder
395410
.addParameter("request", readableStreamOf(requestType))
396411
.returns(responseType)
397412
}
398-
rpc.responseStreaming -> {
413+
rpc.serverStreaming -> {
399414
funSpecBuilder
400415
.addParameter("request", requestType)
401416
.addParameter("response", writableStreamOf(responseType))
@@ -415,7 +430,9 @@ class KotlinGenerator private constructor(
415430
.add("⇤⇤)")
416431
.build()
417432
when {
418-
rpc.requestStreaming || rpc.responseStreaming -> {
433+
// if explicitStreamingCalls is false use the GrpcStreamingCall for every streaming call (legacy).
434+
// Otherwise, use it just for bidirectional streaming.
435+
(rpc.streaming && !explicitStreamingCalls) || rpc.bidirectionalStreaming -> {
419436
funSpecBuilder
420437
.returns(
421438
GrpcStreamingCall::class.asClassName().parameterizedBy(requestType, responseType),
@@ -428,6 +445,33 @@ class KotlinGenerator private constructor(
428445
funSpecBuilder.addModifiers(ABSTRACT)
429446
}
430447
}
448+
rpc.clientStreaming -> {
449+
funSpecBuilder
450+
.returns(
451+
GrpcClientStreamingCall::class.asClassName().parameterizedBy(requestType, responseType),
452+
)
453+
if (isImplementation) {
454+
funSpecBuilder
455+
.addModifiers(OVERRIDE)
456+
.addStatement("return client.newClientStreamingCall(%L)", grpcMethod)
457+
} else {
458+
funSpecBuilder.addModifiers(ABSTRACT)
459+
}
460+
}
461+
rpc.serverStreaming -> {
462+
funSpecBuilder
463+
.returns(
464+
GrpcServerStreamingCall::class.asClassName().parameterizedBy(requestType, responseType),
465+
)
466+
if (isImplementation) {
467+
funSpecBuilder
468+
.addModifiers(OVERRIDE)
469+
.addStatement("return client.newServerStreamingCall(%L)", grpcMethod)
470+
} else {
471+
funSpecBuilder.addModifiers(ABSTRACT)
472+
}
473+
}
474+
431475
else -> {
432476
funSpecBuilder
433477
.returns(
@@ -3135,6 +3179,7 @@ class KotlinGenerator private constructor(
31353179
enumMode: EnumMode = ENUM_CLASS,
31363180
emitProtoReader32: Boolean = false,
31373181
mutableTypes: Boolean = false,
3182+
explicitStreamingCalls: Boolean = false,
31383183
): KotlinGenerator {
31393184
val typeToKotlinName = mutableMapOf<ProtoType, TypeName>()
31403185
val memberToKotlinName = mutableMapOf<ProtoMember, TypeName>()
@@ -3188,6 +3233,7 @@ class KotlinGenerator private constructor(
31883233
enumMode = enumMode,
31893234
emitProtoReader32 = emitProtoReader32,
31903235
mutableTypes = mutableTypes,
3236+
explicitStreamingCalls = explicitStreamingCalls,
31913237
)
31923238
}
31933239

wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinSchemaHandler.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ class KotlinSchemaHandler(
9191
* If true, the generated classes will be mutable..
9292
*/
9393
private val mutableTypes: Boolean = false,
94+
95+
/**
96+
* If true, streaming calls will generate explicit call types for client,server, and bidirectional streaming.
97+
*/
98+
private val explicitStreamingCalls: Boolean = false,
9499
) : SchemaHandler() {
95100
private lateinit var kotlinGenerator: KotlinGenerator
96101

@@ -113,6 +118,7 @@ class KotlinSchemaHandler(
113118
enumMode = enumMode,
114119
emitProtoReader32 = emitProtoReader32,
115120
mutableTypes = mutableTypes,
121+
explicitStreamingCalls = explicitStreamingCalls,
116122
)
117123
context.fileSystem.createDirectories(context.outDirectory)
118124
super.handle(schema, context)

0 commit comments

Comments
 (0)