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
1717
1818class ProtosTest {
1919
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-
3220 private fun <M > decodeEncode (
3321 msg : M ,
3422 codec : MessageCodec <M >
Original file line number Diff line number Diff line change @@ -370,12 +370,16 @@ class ModelToKotlinCommonGenerator(
370370 contextReceiver = " ${enum.name.safeFullName()} .Companion" ,
371371 returnType = enum.name.safeFullName(),
372372 ) {
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+ }
377382 }
378- code(" return ${enum.name.safeFullName()} .UNRECOGNIZED(number)" )
379383 }
380384 }
381385
@@ -546,7 +550,7 @@ class ModelToKotlinCommonGenerator(
546550
547551 clazz(
548552 className, " sealed" ,
549- constructorArgs = listOf (" val number: Int" ),
553+ constructorArgs = listOf (" open val number: Int" ),
550554 ) {
551555
552556 declaration.originalEntries.forEach { variant ->
@@ -559,8 +563,9 @@ class ModelToKotlinCommonGenerator(
559563
560564 // TODO: Avoid name conflict
561565 clazz(
566+ modifiers = " data" ,
562567 name = " UNRECOGNIZED" ,
563- constructorArgs = listOf (" number: Int" ),
568+ constructorArgs = listOf (" override val number: Int" ),
564569 superTypes = listOf (" $className (number)" ),
565570 )
566571
You can’t perform that action at this time.
0 commit comments