File tree Expand file tree Collapse file tree 2 files changed +6
-11
lines changed
commonMain/src/kotlinx/serialization/protobuf/internal
commonTest/src/kotlinx/serialization/protobuf Expand file tree Collapse file tree 2 files changed +6
-11
lines changed Original file line number Diff line number Diff line change @@ -59,12 +59,6 @@ internal open class ProtobufDecoder(
5959 }
6060 }
6161 indexCache = cache
62-
63- // Class type should have unique proto id for its elements
64- require(descriptor.kind != StructureKind .CLASS ||
65- indexCache?.toSet()?.size == elements) {
66- " Duplicated proto number in ${descriptor.serialName} ."
67- }
6862 } else {
6963 populateCacheMap(descriptor, elements)
7064 }
@@ -92,10 +86,7 @@ internal open class ProtobufDecoder(
9286 }
9387
9488 private fun MutableMap <Int , Int >.putProtoId (protoId : Int , index : Int ) {
95- val old = put(protoId, index)
96- require(old == null ) {
97- " Duplicated proto number $protoId in ${descriptor.serialName} for elements: ${descriptor.getElementName(index)} , ${descriptor.getElementName(old!! )} ."
98- }
89+ put(protoId, index)
9990 }
10091
10192 private fun getIndexByNum (protoNum : Int ): Int {
Original file line number Diff line number Diff line change @@ -546,6 +546,7 @@ class ProtobufOneOfTest {
546546 @Test
547547 fun testDuplicatedIdClass () {
548548 val duplicated = DuplicatingIdData (DuplicatingIdStringType (" foo" ), 42 )
549+ // Fine to encode duplicated proto number properties in wire data
549550 ProtoBuf .encodeToHexString(duplicated).also {
550551 /* *
551552 * 3:LEN {"foo"}
@@ -554,8 +555,11 @@ class ProtobufOneOfTest {
554555 assertEquals(" 1a03666f6f182a" , it)
555556 }
556557
558+ // Without checking duplication of proto numbers,
559+ // ProtoBuf just throw exception about wrong wire type
557560 assertFailsWithMessage<IllegalArgumentException >(
558- " Duplicated proto number 3 in kotlinx.serialization.protobuf.ProtobufOneOfTest.DuplicatingIdData for elements: d, bad."
561+ // "Duplicated proto number 3 in kotlinx.serialization.protobuf.ProtobufOneOfTest.DuplicatingIdData for elements: d, bad."
562+ " Expected wire type 0, but found 2"
559563 ) {
560564 /* *
561565 * 3:LEN {"foo"}
You can’t perform that action at this time.
0 commit comments