stevedlawrence commented on a change in pull request #12: Revised daffodil-io 
module to require passing in a FormatInfo object.
URL: https://github.com/apache/incubator-daffodil/pull/12#discussion_r158040029
 
 

 ##########
 File path: 
daffodil-runtime1/src/main/scala/edu/illinois/ncsa/daffodil/processors/RuntimeData.scala
 ##########
 @@ -183,9 +191,126 @@ sealed abstract class TermRuntimeData(
     optIgnoreCase
     maybeFillByteEv
     tunable
+    maybeCheckByteAndBitOrderEv
+    maybeCheckBitOrderAndCharsetEv
   }
   @throws(classOf[java.io.IOException])
   final private def writeObject(out: java.io.ObjectOutputStream): Unit = 
serializeObject(out)
+
+  final def checkParseBitOrder(pstate: PState) = {
+    //
+    // TODO: This looks like a lot of overhead for every single parse call.
+    //
+    // We need to check for bitOrder change. If it is changing, we
+    // need to know if it is on a proper byte boundary.
+    //
+    val dis = pstate.dataInputStream.asInstanceOf[ByteBufferDataInputStream]
+    val isChanging = isParseBitOrderChanging(dis, pstate)
+    if (isChanging && !dis.isAligned(8))
+      pstate.SDE("Can only change dfdl:bitOrder on a byte boundary. Bit pos 
(1b) was %s.", dis.bitPos1b)
+  }
+
+  private def isParseBitOrderChanging(dis: ByteBufferDataInputStream, pstate: 
PState): Boolean = {
+    pstate.processor.context match {
+      case ntrd: NonTermRuntimeData => false
+      case _ => {
+        val priorBitOrder = dis.st.priorBitOrder
+        val newBitOrder = pstate.bitOrder
+        if (priorBitOrder eq newBitOrder) false
+        else {
+          //
+          // the bit order is changing. Let's be sure
+          // that it's legal to do so w.r.t. other properties
+          // These checks will have been evaluated at compile time if
+          // all the properties are static, so this is really just
+          // in case the charset or byteOrder are runtime-valued.
+          //
+          pstate.processor.context match {
+            case trd: TermRuntimeData => {
+              val mcboc = trd.maybeCheckBitOrderAndCharsetEv
+              val mcbbo = trd.maybeCheckByteAndBitOrderEv
+              if (mcboc.isDefined) mcboc.get.evaluate(pstate) // Expressions 
must be evaluated on the element, not before it is created.
+              if (mcbbo.isDefined) mcbbo.get.evaluate(pstate)
+            }
+            case _ => // ok
+          }
 
 Review comment:
   Does it make more sense to move these checks in the above checkParseBitOrder 
function? That way this function literally only determines if the bit order is 
changing, and then the above function can do any checks that are related to it 
changing (e.g. bit order, encoding, alignment, etc)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to