Skip to content

Commit 9986e7b

Browse files
committed
fix structural issues
1 parent d13ec50 commit 9986e7b

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

formats/cbor/commonMain/src/kotlinx/serialization/cbor/internal/CborParserInterface.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal sealed interface CborParserInterface {
3333
fun nextTaggedStringOrNumber(): Triple<String?, Long?, ULongArray?>
3434

3535
// Skip operations
36+
//used only to skip unknown elements
3637
fun skipElement(tags: ULongArray?)
3738

3839
// Tag verification

formats/cbor/commonMain/src/kotlinx/serialization/cbor/internal/Decoder.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -585,32 +585,33 @@ internal class StructuredCborParser(internal val element: CborElement, private v
585585
listIterator = layerStack.removeLast()
586586
}
587587

588+
588589
override fun startArray(tags: ULongArray?): Int {
589590
processTags(tags)
590591
if (currentElement !is CborList) {
591592
throw CborDecodingException("Expected array, got ${currentElement::class.simpleName}")
592593
}
593-
isMapStack+=isMap
594-
layerStack+=listIterator
594+
isMapStack += isMap
595+
layerStack += listIterator
595596
isMap = false
596597
val list = currentElement as CborList
597598
listIterator = list.listIterator()
598-
return list.size
599+
return -1 //just let the iterator run out of elements
599600
}
600601

601602
override fun startMap(tags: ULongArray?): Int {
602603
processTags(tags)
603604
if (currentElement !is CborMap) {
604605
throw CborDecodingException("Expected map, got ${currentElement::class.simpleName}")
605606
}
606-
layerStack+=listIterator
607-
isMapStack+=isMap
607+
layerStack += listIterator
608+
isMapStack += isMap
608609
isMap = true
609610

610611
val map = currentElement as CborMap
611612
//zip key, value, key, value, ... pairs to mirror byte-layout of CBOR map
612613
listIterator = map.entries.flatMap { listOf(it.key, it.value) }.listIterator()
613-
return map.size //cbor map size is the size of the map, not the doubled size of the flattened pairs
614+
return -1// just let the iterator run out of elements
614615
}
615616

616617
override fun nextNull(tags: ULongArray?): Nothing? {
@@ -681,7 +682,7 @@ internal class StructuredCborParser(internal val element: CborElement, private v
681682

682683
// If we're in a list, advance to the next element
683684
if (listIterator != null && listIterator!!.hasNext()) {
684-
currentElement= listIterator!!.next()
685+
currentElement = listIterator!!.next()
685686
}
686687

687688
// Store collected tags for verification
@@ -707,6 +708,7 @@ internal class StructuredCborParser(internal val element: CborElement, private v
707708

708709
override fun skipElement(tags: ULongArray?) {
709710
// Process tags but don't do anything with the element
711+
//TODO check for maps
710712
processTags(tags)
711713
}
712714
}

formats/cbor/commonTest/src/kotlinx/serialization/cbor/CborDecoderTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ class CborDecoderTest {
356356
hex
357357
)
358358
)
359-
val ref = ignoreUnknownKeys.encodeToCbor(expected)
360359
val struct = Cbor.decodeFromHexString<CborElement>(hex)
361360
assertEquals(expected, ignoreUnknownKeys.decodeFromCbor(SealedBox.serializer(), struct))
362361

0 commit comments

Comments
 (0)