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(
59
59
}
60
60
}
61
61
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
- }
68
62
} else {
69
63
populateCacheMap(descriptor, elements)
70
64
}
@@ -92,10 +86,7 @@ internal open class ProtobufDecoder(
92
86
}
93
87
94
88
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)
99
90
}
100
91
101
92
private fun getIndexByNum (protoNum : Int ): Int {
Original file line number Diff line number Diff line change @@ -546,6 +546,7 @@ class ProtobufOneOfTest {
546
546
@Test
547
547
fun testDuplicatedIdClass () {
548
548
val duplicated = DuplicatingIdData (DuplicatingIdStringType (" foo" ), 42 )
549
+ // Fine to encode duplicated proto number properties in wire data
549
550
ProtoBuf .encodeToHexString(duplicated).also {
550
551
/* *
551
552
* 3:LEN {"foo"}
@@ -554,8 +555,11 @@ class ProtobufOneOfTest {
554
555
assertEquals(" 1a03666f6f182a" , it)
555
556
}
556
557
558
+ // Without checking duplication of proto numbers,
559
+ // ProtoBuf just throw exception about wrong wire type
557
560
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"
559
563
) {
560
564
/* *
561
565
* 3:LEN {"foo"}
You can’t perform that action at this time.
0 commit comments