tuxji commented on code in PR #988:
URL: https://github.com/apache/daffodil/pull/988#discussion_r1137856524
##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/parsers/BlobLengthParsers.scala:
##########
@@ -55,9 +55,9 @@ trait ByteChunkWriter { self: PrimParser =>
remainingBitsToGet -= bitsToGet
} else {
val remainingBits =
- if (dis.remainingBits.isDefined) {
+ if (dis.remainingLimitedBits.isDefined) {
val totalBitsRead = nBits - remainingBitsToGet
- MaybeULong(dis.remainingBits.get + totalBitsRead)
+ MaybeULong(dis.remainingLimitedBits.get + totalBitsRead)
Review Comment:
Please add a comment explaining why out of 26 places calling
`remainingBits`, you decided to change this particular place to call
`remainingLimitedBits` instead of `remainingBits`. The `remainingLimitedBits`
function returns only the remaining bits until the limit is reached, so you're
losing the information that the remaining bits until the end of the input is
reached might be even smaller.
##########
daffodil-io/src/main/scala/org/apache/daffodil/io/InputSourceDataInputStream.scala:
##########
@@ -128,6 +128,25 @@ final class InputSourceDataInputStream private (val
inputSource: InputSource)
*/
def hasReachedEndOfData: Boolean = inputSource.hasReachedEndOfData
+ /**
+ * The number of bits remaining if known. If a limit has not been set,
+ * returns Nope. If a limit has been set, the number of bits available
+ * until the limit as long as the end of data has not been seen. If the
+ * end of data has been seen, the smaller value of the remaining bits
+ * in the limit and the remaining bits in the data stream.
+ */
+ def remainingBits: MaybeULong = {
+ if (hasReachedEndOfData) {
+ val bitsAvailable = inputSource.bytesAvailable * 8
+ if (remainingLimitedBits.isDefined && bitsAvailable <
remainingLimitedBits.get)
Review Comment:
Simply noting for other reviewers the reason why the `remainingBits`
function is defined in this class instead of in `DataInputStreamImplMixin` or
another base trait is because the `hasReachedEndOfData` and
`inputSource.bytesAvailable` functions it calls are defined only within this
class.
--
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]