stevedlawrence commented on a change in pull request #218: Implement 
dfdl:choiceLength='explicit'
URL: https://github.com/apache/incubator-daffodil/pull/218#discussion_r286259767
 
 

 ##########
 File path: 
daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SpecifiedLength2.scala
 ##########
 @@ -460,6 +463,64 @@ class ElementUnusedUnparser(
 
 }
 
+/**
+ * This is basically a simplified version of the 
ElementUnusedUnparserSuspendableOperation.
+ * For explicit length choices, we do not need to handle length expressions, 
choiceLength is
+ * simply a non-negative integer.
+ */
+class ChoiceUnusedUnparserSuspendableOperation(
+  override val rd: TermRuntimeData,
+  targetLengthInBits: Long)
+  extends SuspendableOperation {
+
+  /**
+   * determine delta between value length and target length
+   *
+   * and skip that many bits.
+   */
+  override def continuation(ustate: UState) {
+    val e = ustate.currentInfosetNode.asInstanceOf[DIElement]
+    val vl = e.valueLength.lengthInBits.longValue
+    val skipInBits = targetLengthInBits - vl
+    if (skipInBits < 0)
+      UE(ustate, "Data too long by %s bits. Unable to truncate.", -skipInBits)
+    skipTheBits(ustate, skipInBits)
+  }
+
+  protected final def skipTheBits(ustate: UState, skipInBits: Long) {
+    if (skipInBits > 0) {
+      val dos = ustate.dataOutputStream
+      if (!dos.skip(skipInBits, ustate))
+        UE(ustate, "Unable to skip %s(bits).", skipInBits)
+    }
+    if (skipInBits == 0) {
+      log(LogLevel.Debug, "%s no fill for %s DOS %s.",
+        Misc.getNameFromClass(this), rd.diagnosticDebugName, 
ustate.dataOutputStream)
+    } else {
+      log(LogLevel.Debug, "%s filled %s bits for %s DOS %s.",
+        Misc.getNameFromClass(this), skipInBits, rd.diagnosticDebugName, 
ustate.dataOutputStream)
+    }
+  }
+
+  override def test(ustate: UState): Boolean = {
+    val e = ustate.currentInfosetNode.asInstanceOf[DIElement]
+    e.valueLength.maybeLengthInBits().isDefined
+  }
+}
+
+class ChoiceUnusedUnparser(
+  override val context: TermRuntimeData,
 
 Review comment:
   Can this be a ChoiceRuntimeData?

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

Reply via email to