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

 ##########
 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)
 
 Review comment:
   I might be worth mention an explicit length choice here in this error 
message to make it clear that the choice content was too long for the specified 
length.

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