@@ -595,7 +595,7 @@ internal class StructuredCborParser(internal val element: CborElement, private v
595
595
isMap = false
596
596
val list = currentElement as CborList
597
597
listIterator = list.listIterator()
598
- return - 1 // just let the iterator run out of elements
598
+ return list.size
599
599
}
600
600
601
601
override fun startMap (tags : ULongArray? ): Int {
@@ -608,9 +608,10 @@ internal class StructuredCborParser(internal val element: CborElement, private v
608
608
isMap = true
609
609
610
610
val map = currentElement as CborMap
611
- // zip key, value, key, value, ... pairs to mirror byte-layout of CBOR map
611
+ // zip key, value, key, value, ... pairs to mirror byte-layout of CBOR map, so decoding this here works the same
612
+ // as decoding from bytes
612
613
listIterator = map.entries.flatMap { listOf (it.key, it.value) }.listIterator()
613
- return - 1 // just let the iterator run out of elements
614
+ return map.size
614
615
}
615
616
616
617
override fun nextNull (tags : ULongArray? ): Nothing? {
@@ -677,9 +678,14 @@ internal class StructuredCborParser(internal val element: CborElement, private v
677
678
}
678
679
}
679
680
681
+ /* *
682
+ * Verify the current element's object tags and advance to the next element if inside a list/map.
683
+ * The reason this method mixes two behaviours is that decoding a primitive is invoked on a single element.
684
+ * `decodeElementIndex`, etc. is invoked on an iterable and there are key tags and value tags
685
+ */
680
686
private fun processTags (tags : ULongArray? ): ULongArray? {
681
687
682
- // If we're in a list, advance to the next element
688
+ // If we're in a list/map , advance to the next element
683
689
if (listIterator != null && listIterator!! .hasNext()) {
684
690
currentElement = listIterator!! .next()
685
691
}
@@ -707,7 +713,6 @@ internal class StructuredCborParser(internal val element: CborElement, private v
707
713
708
714
override fun skipElement (tags : ULongArray? ) {
709
715
// Process tags but don't do anything with the element
710
- // TODO check for maps
711
716
processTags(tags)
712
717
}
713
718
}
0 commit comments