stevedlawrence commented on code in PR #1170:
URL: https://github.com/apache/daffodil/pull/1170#discussion_r1507591407


##########
daffodil-runtime1-layers/src/main/scala/org/apache/daffodil/layers/runtime1/ByteSwapTransformer.scala:
##########
@@ -22,53 +22,27 @@ import java.io.OutputStream
 import java.util.ArrayDeque
 import java.util.Deque
 
-import org.apache.daffodil.io.ExplicitLengthLimitingStream
 import org.apache.daffodil.lib.exceptions.Assert
-import org.apache.daffodil.lib.schema.annotation.props.gen.LayerLengthKind
-import org.apache.daffodil.runtime1.layers._
-import org.apache.daffodil.runtime1.processors.ParseOrUnparseState
-
-final class FourByteSwapLayerCompiler extends LayerCompiler("fourbyteswap") {
-
-  override def compileLayer(layerCompileInfo: LayerCompileInfo): 
LayerTransformerFactory = {
-
-    layerCompileInfo.optLayerLengthKind match {
-      case Some(LayerLengthKind.Explicit) => // ok
-      case None =>
-        layerCompileInfo.SDE(
-          "The property dfdlx:layerLengthKind must be defined and have value 
'explicit'.",
-        )
-      case Some(other) =>
-        layerCompileInfo.SDE(
-          "The property dfdlx:layerLengthKind must be 'explicit' but was 
'$other'.",
-        )
-    }
+import org.apache.daffodil.runtime1.layers.api.Layer
+import org.apache.daffodil.runtime1.layers.api.LayerRuntime
 
-    layerCompileInfo.SDEUnless(
-      layerCompileInfo.optLayerLengthOptConstantValue.isDefined,
-      "The property dfdlx:layerLength must be defined.",
-    )
+final class TwoByteSwapLayer extends ByteSwap("twobyteswap", 2)
+final class FourByteSwapLayer extends ByteSwap("fourbyteswap", 4)

Review Comment:
   It looks like the byte swap algorithm works for any number. So it should 
work fine for 3, 5 ,1000, etc. without any changes. I would be surprised if any 
format actually needed any of those, but I could imagine a format having a word 
size of 8 or 16 or something. I think the only check we would need is that it's 
non-zero, which could be enforced by making the variable an unsignedInt, or 
unsignedByte if there are concerns with very large swaps.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to