jadams-tresys commented on code in PR #1652:
URL: https://github.com/apache/daffodil/pull/1652#discussion_r3373660113


##########
daffodil-core/src/main/scala/org/apache/daffodil/runtime1/processors/parsers/SpecifiedLengthParsers.scala:
##########
@@ -136,11 +154,79 @@ class SpecifiedLengthEndOfParentParser(
   eParser: Parser,
   erd: ElementRuntimeData
 ) extends SpecifiedLengthParserBase(eParser, erd),
-    BitLengthFromBitLimitMixin(true) {
+    EndOfParentBitLengthMixin {
 
   override protected def getBitLength(s: PState): MaybeULong = {
-    MaybeULong(super[BitLengthFromBitLimitMixin].getBitLength(s))
+    MaybeULong(getLengthInBits(s))
+  }
+
+  override def parse(pState: PState): Unit = {
+    val dis = pState.dataInputStream
+
+    if (erd.isComplexType) {
+      if (dis.bitLimit0b.isDefined) {
+        val (nBits: Long, dis: InputSourceDataInputStream, startingBitPos0b: 
Long) =
+          checkLengthAndParseWithinBitLimits(
+            pState,
+            shouldCheckDefinedForLength = false
+          ) match {
+            case Some(result) => result
+            case None => return
+          }
+
+        // at this point the recursive parse of the children is finished
+        // so if we're still successful we need to advance the position
+        // to skip past any bits that the recursive child parse did not
+        // consume at the end. That is, the specified length can be an
+        // outer constraint, but the children may not use it all up, leaving
+        // a section at the end.
+        if (pState.processorStatus ne Success) return
+        val finalEndPos0b = startingBitPos0b + nBits
+
+        // we want to capture the length before we do any skipping
+        // value length of simple types is captured by the eParser
+        if (pState.infoset.isComplex)
+          captureValueLength(pState, ULong(startingBitPos0b), 
ULong(dis.bitPos0b))
+
+        Assert.invariant(dis eq pState.dataInputStream)
+        val bitsToSkip = finalEndPos0b - dis.bitPos0b
+        // if this is < 0, then the parsing of children went past the limit, 
which it isn't supposed to.
+        skipBits(pState, bitsToSkip, dis)
+      } else {
+        val startingBitPos0b = dis.bitPos0b
+
+        eParser.parse1(pState)
+
+        // at this point the recursive parse of the children is finished
+        // so if we're still successful we need to advance the position
+        // to skip past any bits that the recursive child parse did not
+        // consume at the end. That is, the specified length can be an
+        // outer constraint, but the children may not use it all up, leaving
+        // a section at the end.
+        if (pState.processorStatus ne Success) return
+
+        // we want to capture the length before we do any skipping
+        // value length of simple types is captured by the eParser
+        if (pState.infoset.isComplex) {
+          captureValueLength(pState, ULong(startingBitPos0b), 
ULong(dis.bitPos0b))
+        }
+
+        val maybeNBits = getBitLength(pState)
+
+        if (pState.processorStatus._ne_(Success)) return

Review Comment:
   Is there a reason for the two different styles of processorStatus checks 
here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to