mbeckerle commented on a change in pull request #218: Implement
dfdl:choiceLength='explicit'
URL: https://github.com/apache/incubator-daffodil/pull/218#discussion_r287000392
##########
File path:
daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SpecifiedLengthUnparsers.scala
##########
@@ -428,3 +429,20 @@ class SpecifiedLengthPrefixedUnparser(
}
}
+
+class ChoiceLengthUnparser(
+ eUnparser: Unparser,
+ rd: TermRuntimeData)
+ extends CombinatorUnparser(rd)
+ with CaptureUnparsingValueLength {
+
+ override lazy val runtimeDependencies = Vector()
+ override lazy val childProcessors = Vector(eUnparser)
+
+ override def unparse(state: UState): Unit = {
+ val elem = state.currentInfosetNode.asInstanceOf[DIElement]
+ captureValueLengthStart(state, elem)
+ eUnparser.unparse1(state)
+ captureValueLengthEnd(state, elem)
+ }
Review comment:
You probably want ChoiceLengthUnparser to recursively unparse
1) a splitter unparser - like in the separator thing, you just need to split
the infoset. (Yes this could be hoisted out to a more general class name, since
it really has nothing to do with separators per se.)
2) the choice branch itself, and then
3) a suspendable unparser for the ChoiceUnusedRegion that comes after the
choice branch. This will be a new suspendable unparser. The constructor for
this unparser will take the DOS from after the split(1) above as an argument.
The test for the suspendable operation of this ChoiceUnusedRegion unparser
is going to use the dataOutputStream from the split (1) above. The test will
pass when that data stream, and all subsequent ones up until but not including
the current one (the ChoiceUnusedRegion is suspendable, so will also create a
split of its own) are final. The current DOS is waiting for us to put the
skip(n) into it for the unused region, so this one will NOT be final.
The continuation method of the suspendable operations can then compute the
exact length in bits of the data from the split (1) to just before the
ChoiceUnusedRegion unparser (3) by following the chain of DOS from the first
one created after the split (1) to current. That's the key value you need to
then decide how many bits to skip based on the choiceLength value.
You skip(n) those, then finalize the DOS.
Hope that makes sense. Happy to discuss by phone.
----------------------------------------------------------------
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