mike-mcgann commented on code in PR #988:
URL: https://github.com/apache/daffodil/pull/988#discussion_r1147551747


##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/parsers/Parser.scala:
##########
@@ -65,21 +65,42 @@ sealed trait Parser extends Processor {
     pstate.setFailed(new ParseError(One(sfl), One(dataLoc), s, args: _*))
   }
 
-  def PENotEnoughBits(pstate: PState, neededBits: Long, remainingBits: 
MaybeULong) = {
-    val remainingStr =
-      if (remainingBits.isDefined) s" but found only ${remainingBits.get} 
available" else ""
-    PE(pstate, "Insufficient bits in data. Needed %d bit(s)%s.", neededBits, 
remainingStr)
-  }
-
   def PENotEnoughBits(
     pstate: PState,
     sfl: SchemaFileLocation,
     dataLoc: DataLocation,
     neededBits: Long,
-    remainingBits: MaybeULong,
-  ) = {
-    val remainingStr =
-      if (remainingBits.isDefined) s" but found only ${remainingBits.get} 
available" else ""
+    source: InputSourceDataInputStream,
+  ): Unit = {
+    val startPos = dataLoc.bitPos1b - 1
+    val remainingLimitedBits = {
+      if (source.bitLimit0b.isEmpty) MaybeULong.Nope
+      else {
+        val lim = source.bitLimit0b.get
+        Assert.invariant(lim >= 0)
+        val nBits = lim - startPos
+        MaybeULong(nBits)
+      }
+    }
+    val remainingBits = {
+      if (source.hasReachedEndOfData) {
+        val bitsAvailable = {
+          val fragmentBitsReadFromSourcePos = source.bitPos0b % 8
+          val bitsAvailableFromSourcePos =
+            source.knownBytesAvailable * 8 - fragmentBitsReadFromSourcePos
+          val bitsBetweenStartPosAndSourcePos = source.bitPos0b - startPos
+          val bitsAvailableFromStartPos =
+            bitsAvailableFromSourcePos + bitsBetweenStartPosAndSourcePos
+          bitsAvailableFromStartPos
+        }
+        if (remainingLimitedBits.isEmpty || bitsAvailable < 
remainingLimitedBits.get)
+          bitsAvailable
+        else
+          remainingLimitedBits.get
+      } else remainingLimitedBits.get
+    }
+
+    val remainingStr = s" but found only ${remainingBits} available"

Review Comment:
   Updated



##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/parsers/BlobLengthParsers.scala:
##########
@@ -32,15 +31,18 @@ trait ByteChunkWriter { self: PrimParser =>
    * which takes as parameters an array of bytes and the number of bytes in
    * that array that should be written. The chunk size is defined by the
    * blobChunkSizeInBytes tunable.
+   *
+   * @return the actual number of bits written

Review Comment:
   Updated



-- 
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