File tree Expand file tree Collapse file tree 2 files changed +28
-2
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 +28
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ import OneOfMsg
88import OneOfMsgInternal
99import Outer
1010import OuterInternal
11+ import asInternal
12+ import encodeWith
1113import invoke
1214import kotlinx.io.Buffer
1315import kotlinx.rpc.grpc.codec.MessageCodec
@@ -177,6 +179,30 @@ class ProtosTest {
177179 }
178180 }
179181
182+ @Test
183+ fun testOneOfMsgMerging () {
184+ val part1 = OneOfMsg {
185+ field = OneOfMsg .Field .Other (Other { arg2 = " arg2" })
186+ }
187+ val part2 = OneOfMsg {
188+ field = OneOfMsg .Field .Other (Other { arg1 = " arg1" })
189+ }
190+
191+ val buffer = Buffer ()
192+ val encoder = WireEncoder (buffer)
193+ part1.asInternal().encodeWith(encoder)
194+ part2.asInternal().encodeWith(encoder)
195+ encoder.flush()
196+
197+
198+ val decoded = OneOfMsgInternal .CODEC .decode(buffer)
199+ assertIs<OneOfMsg .Field .Other >(decoded.field)
200+ val decodedOther = (decoded.field as OneOfMsg .Field .Other ).value
201+ assertEquals(" arg2" , decodedOther.arg2)
202+ assertEquals(" arg1" , decodedOther.arg1)
203+ assertEquals(null , decodedOther.arg3)
204+ }
205+
180206 @Test
181207 fun testOneOfLastWins () {
182208 // write two values on the oneOf field.
Original file line number Diff line number Diff line change @@ -265,7 +265,7 @@ class ModelToKotlinCommonGenerator(
265265 code(" val tag = decoder.readTag() ?: break // EOF, we read the whole message" )
266266 whenBlock {
267267 declaration.fields().forEach { (_, field) -> readMatchCase(field) }
268- whenCase(" else" ) { code(" TODO(\" Handle unknown fields\" )" ) }
268+ whenCase(" else" ) { code(" TODO(\" Handle unknown fields: \$ tag \" )" ) }
269269 }
270270 }
271271 ifBranch(
@@ -394,7 +394,7 @@ class ModelToKotlinCommonGenerator(
394394
395395 is FieldType .Message -> {
396396 val internalClassName = fieldType.dec.value.internalClassFullName()
397- code(" decoder.readMessage($lvalue .asInternal(), $internalClassName ::decodeWith)" )
397+ code(" decoder.readMessage($lvalue .asInternal(), $internalClassName .CODEC ::decodeWith)" )
398398 }
399399
400400 is FieldType .Map -> TODO ()
You can’t perform that action at this time.
0 commit comments