@@ -595,7 +595,7 @@ internal class StructuredCborParser(internal val element: CborElement, private v
595595 isMap = false
596596 val list = currentElement as CborList
597597 listIterator = list.listIterator()
598- return - 1 // just let the iterator run out of elements
598+ return list.size
599599 }
600600
601601 override fun startMap (tags : ULongArray? ): Int {
@@ -608,9 +608,10 @@ internal class StructuredCborParser(internal val element: CborElement, private v
608608 isMap = true
609609
610610 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
612613 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
614615 }
615616
616617 override fun nextNull (tags : ULongArray? ): Nothing? {
@@ -677,9 +678,14 @@ internal class StructuredCborParser(internal val element: CborElement, private v
677678 }
678679 }
679680
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+ */
680686 private fun processTags (tags : ULongArray? ): ULongArray? {
681687
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
683689 if (listIterator != null && listIterator!! .hasNext()) {
684690 currentElement = listIterator!! .next()
685691 }
@@ -707,7 +713,6 @@ internal class StructuredCborParser(internal val element: CborElement, private v
707713
708714 override fun skipElement (tags : ULongArray? ) {
709715 // Process tags but don't do anything with the element
710- // TODO check for maps
711716 processTags(tags)
712717 }
713718}
0 commit comments