Skip to content

Commit ce3b69f

Browse files
committed
grpc-native: Address PR comments
Signed-off-by: Johannes Zottele <[email protected]>
1 parent d5e9f00 commit ce3b69f

File tree

8 files changed

+61
-6
lines changed

8 files changed

+61
-6
lines changed

gradle-plugin/src/main/kotlin/kotlinx/rpc/proto/DefaultProtoSourceSet.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ internal fun Project.createProtoExtensions() {
9898
project.withKotlinKmpExtension {
9999
findOrCreateAndConfigure("jvmMain", null)
100100
findOrCreateAndConfigure("jvmTest", null)
101+
findOrCreateAndConfigure("commonMain", null)
102+
findOrCreateAndConfigure("commonTest", null)
101103

102104
sourceSets.configureEach {
103-
if (name == "jvmMain" || name == "jvmTest" || name == "nativeTest" || name == "commonTest") {
105+
if (name == "jvmMain" || name == "jvmTest" || name == "commonMain" || name == "commonTest") {
104106
findOrCreateAndConfigure(name, this)
105107
}
106108
}

grpc/grpc-core/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protoSourceSets {
139139
}
140140
}
141141

142-
configureEach {
142+
commonTest {
143143
proto {
144144
exclude("exclude/**")
145145
}
@@ -163,7 +163,7 @@ rpc {
163163
// Set compile for common(native) option
164164
if (name.endsWith("CommonTest")) {
165165
protocPlugins.kotlinMultiplatform {
166-
options.set(options.getOrElse(emptyMap()) + mapOf("targetMode" to "common"))
166+
options.put("targetMode", "common")
167167
}
168168
}
169169

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/pb/KTag.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
package kotlinx.rpc.grpc.pb
66

7+
import kotlinx.rpc.internal.utils.InternalRpcApi
8+
9+
@InternalRpcApi
710
public enum class WireType {
811
VARINT, // 0
912
FIXED64, // 1
@@ -13,6 +16,7 @@ public enum class WireType {
1316
FIXED32, // 5
1417
}
1518

19+
@InternalRpcApi
1620
public data class KTag(val fieldNr: Int, val wireType: WireType) {
1721

1822
init {

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/pb/WireDecoder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public interface WireDecoder : AutoCloseable {
4242
public fun hadError(): Boolean
4343

4444
/**
45-
* When the read tag is null, it indicates EOF and the parse may stop at this point.
45+
* When the read tag is null, it indicates EOF and the parser may stop at this point.
4646
*/
4747
public fun readTag(): KTag?
4848
public fun readBool(): Boolean

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/pb/WireSize.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,52 @@
44

55
package kotlinx.rpc.grpc.pb
66

7+
import kotlinx.rpc.internal.utils.InternalRpcApi
8+
9+
@InternalRpcApi
710
public object WireSize
811

12+
@InternalRpcApi
913
public expect fun WireSize.int32(value: Int): Int
14+
15+
@InternalRpcApi
1016
public expect fun WireSize.int64(value: Long): Int
17+
18+
@InternalRpcApi
1119
public expect fun WireSize.uInt32(value: UInt): Int
20+
21+
@InternalRpcApi
1222
public expect fun WireSize.uInt64(value: ULong): Int
23+
24+
@InternalRpcApi
1325
public expect fun WireSize.sInt32(value: Int): Int
26+
27+
@InternalRpcApi
1428
public expect fun WireSize.sInt64(value: Long): Int
1529

30+
@InternalRpcApi
1631
public fun WireSize.bool(value: Boolean): Int = int32(if (value) 1 else 0)
32+
33+
@InternalRpcApi
1734
public fun WireSize.enum(value: Int): Int = int32(value)
35+
36+
@InternalRpcApi
1837
public fun WireSize.packedInt32(value: List<Int>): Int = value.sumOf { int32(it) }
38+
39+
@InternalRpcApi
1940
public fun WireSize.packedInt64(value: List<Long>): Int = value.sumOf { int64(it) }
41+
42+
@InternalRpcApi
2043
public fun WireSize.packedUInt32(value: List<UInt>): Int = value.sumOf { uInt32(it) }
44+
45+
@InternalRpcApi
2146
public fun WireSize.packedUInt64(value: List<ULong>): Int = value.sumOf { uInt64(it) }
47+
48+
@InternalRpcApi
2249
public fun WireSize.packedSInt32(value: List<Int>): Int = value.sumOf { sInt32(it) }
50+
51+
@InternalRpcApi
2352
public fun WireSize.packedSInt64(value: List<Long>): Int = value.sumOf { sInt64(it) }
53+
54+
@InternalRpcApi
2455
public fun WireSize.packedEnum(value: List<Int>): Int = value.sumOf { enum(it) }

grpc/grpc-core/src/commonTest/proto/repeated.proto

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ syntax = "proto3";
22

33
package kotlinx.rpc.grpc.test.common;
44

5-
//import 'reference_package.proto';
6-
75
message RepeatedCommon {
86
repeated fixed32 listFixed32 = 1 [packed = true];
97
repeated int32 listInt32 = 2 [packed = false];

grpc/grpc-core/src/jvmMain/kotlin/kotlinx/rpc/grpc/pb/WireSize.jvm.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,36 @@
55
package kotlinx.rpc.grpc.pb
66

77
import com.google.protobuf.CodedOutputStream.*
8+
import kotlinx.rpc.internal.utils.InternalRpcApi
89

10+
@InternalRpcApi
911
public actual fun WireSize.int32(value: Int): Int {
1012
return computeInt32SizeNoTag(value)
1113
}
1214

15+
@InternalRpcApi
1316
public actual fun WireSize.int64(value: Long): Int {
1417
return computeInt64SizeNoTag(value)
1518
}
1619

20+
@InternalRpcApi
1721
public actual fun WireSize.uInt32(value: UInt): Int {
1822
// todo check java unsigned types
1923
return computeUInt32SizeNoTag(value.toInt())
2024
}
2125

26+
@InternalRpcApi
2227
public actual fun WireSize.uInt64(value: ULong): Int {
2328
// todo check java unsigned types
2429
return computeUInt64SizeNoTag(value.toLong())
2530
}
2631

32+
@InternalRpcApi
2733
public actual fun WireSize.sInt32(value: Int): Int {
2834
return computeSInt32SizeNoTag(value)
2935
}
3036

37+
@InternalRpcApi
3138
public actual fun WireSize.sInt64(value: Long): Int {
3239
return computeSInt64SizeNoTag(value)
3340
}

grpc/grpc-core/src/nativeMain/kotlin/kotlinx/rpc/grpc/pb/WireSize.native.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@
77
package kotlinx.rpc.grpc.pb
88

99
import kotlinx.cinterop.ExperimentalForeignApi
10+
import kotlinx.rpc.internal.utils.InternalRpcApi
1011
import libprotowire.*
1112

13+
@InternalRpcApi
1214
public actual fun WireSize.int32(value: Int): Int = pw_size_int32(value).toInt()
15+
16+
@InternalRpcApi
1317
public actual fun WireSize.int64(value: Long): Int = pw_size_int64(value).toInt()
18+
19+
@InternalRpcApi
1420
public actual fun WireSize.uInt32(value: UInt): Int = pw_size_uint32(value).toInt()
21+
22+
@InternalRpcApi
1523
public actual fun WireSize.uInt64(value: ULong): Int = pw_size_uint64(value).toInt()
24+
25+
@InternalRpcApi
1626
public actual fun WireSize.sInt32(value: Int): Int = pw_size_sint32(value).toInt()
27+
28+
@InternalRpcApi
1729
public actual fun WireSize.sInt64(value: Long): Int = pw_size_sint64(value).toInt()
1830

31+

0 commit comments

Comments
 (0)