File tree Expand file tree Collapse file tree 2 files changed +12
-19
lines changed
grpc/grpc-core/src/commonTest/kotlin/kotlinx/rpc/grpc/pb
protoc-gen/src/main/kotlin/kotlinx/rpc/protobuf Expand file tree Collapse file tree 2 files changed +12
-19
lines changed Original file line number Diff line number Diff line change @@ -17,18 +17,6 @@ import kotlin.test.assertFailsWith
17
17
18
18
class ProtosTest {
19
19
20
- @Test
21
- fun bugDemo () {
22
- val buffer = Buffer ()
23
- val encoder = WireEncoder (buffer)
24
- encoder.writeEnum(1 , 0 )
25
- encoder.flush()
26
-
27
- val decodedMsg = UsingEnumInternal .CODEC .decode(buffer)
28
- assertEquals(Enum .UNRECOGNIZED (50 ), decodedMsg.enum)
29
- }
30
-
31
-
32
20
private fun <M > decodeEncode (
33
21
msg : M ,
34
22
codec : MessageCodec <M >
Original file line number Diff line number Diff line change @@ -370,12 +370,16 @@ class ModelToKotlinCommonGenerator(
370
370
contextReceiver = " ${enum.name.safeFullName()} .Companion" ,
371
371
returnType = enum.name.safeFullName(),
372
372
) {
373
- scope(" for (entry in entries)" ) {
374
- ifBranch(condition = " entry.number == number" , ifBlock = {
375
- code(" return entry" )
376
- })
373
+ whenBlock(prefix = " return" ) {
374
+ enum.originalEntries.forEach { entry ->
375
+ whenCase(" number == ${entry.dec.number} " ) {
376
+ code(" ${entry.name} " )
377
+ }
378
+ }
379
+ whenCase(" else" ) {
380
+ code(" ${enum.name.safeFullName()} .UNRECOGNIZED(number)" )
381
+ }
377
382
}
378
- code(" return ${enum.name.safeFullName()} .UNRECOGNIZED(number)" )
379
383
}
380
384
}
381
385
@@ -546,7 +550,7 @@ class ModelToKotlinCommonGenerator(
546
550
547
551
clazz(
548
552
className, " sealed" ,
549
- constructorArgs = listOf (" val number: Int" ),
553
+ constructorArgs = listOf (" open val number: Int" ),
550
554
) {
551
555
552
556
declaration.originalEntries.forEach { variant ->
@@ -559,8 +563,9 @@ class ModelToKotlinCommonGenerator(
559
563
560
564
// TODO: Avoid name conflict
561
565
clazz(
566
+ modifiers = " data" ,
562
567
name = " UNRECOGNIZED" ,
563
- constructorArgs = listOf (" number: Int" ),
568
+ constructorArgs = listOf (" override val number: Int" ),
564
569
superTypes = listOf (" $className (number)" ),
565
570
)
566
571
You can’t perform that action at this time.
0 commit comments