jadams-tresys commented on a change in pull request #215: Ensure fragment bytes
are delivered correctly when dfdl:outputValueCalc is followed by a different
bitOrder
URL: https://github.com/apache/incubator-daffodil/pull/215#discussion_r283031022
##########
File path:
daffodil-io/src/main/scala/org/apache/daffodil/io/DirectOrBufferedDataOutputStream.scala
##########
@@ -790,13 +790,34 @@ object DirectOrBufferedDataOutputStream {
val wholeBytesWritten = directDOS.putBytes(ba, 0, byteCount, finfo)
Assert.invariant(byteCount == wholeBytesWritten)
if (nFragBits > 0) {
- val origfrag = bufDOS.fragmentLastByte
- val fragNum =
- if (finfoBitOrder eq BitOrder.MostSignificantBitFirst)
- origfrag >> (8 - nFragBits)
- else
- origfrag
- Assert.invariant(directDOS.putLongUnchecked(fragNum, nFragBits,
finfo))
+ if (directDOS.isEndOnByteBoundary) {
+ // We cannot use putLong like below below because it's possible
+ // that the fragment byte has a different bitOrder than the
+ // finfo passed in since that came from a suspension. However,
+ // if the directDOS ended on a byte boundary, that means that
+ // its new fragment byte should be exactly the same as the
+ // buffered DOS fragment byte. So in this case, just copy the
+ // frag byte information from buffered to direct.
+ directDOS.setFragmentLastByte(bufDOS.fragmentLastByte,
bufDOS.fragmentLastByteLimit)
+ } else {
+ // If the direct DOS wasn't byte aligned, then we need logic
+ // logic to write the buffered DOS fragment after the direct
+ // DOS fragment. Fortunately putLong has all of this logic.
+ // Like above, the call the putLong potentially uses the wrong
+ // finfo since it may have come from a suspensio. However, all
Review comment:
Missed an 'n' on suspension.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services