mbeckerle commented on code in PR #1176:
URL: https://github.com/apache/daffodil/pull/1176#discussion_r1516101654


##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/layers/api/ChecksumLayer.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.daffodil.runtime1.layers.api;
+
+import org.apache.daffodil.runtime1.layers.ChecksumLayerBase;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Suitable only for checksums computed over small sections of data, not large 
data streams or whole files.
+ *
+ * The entire region of data the checksum is being computed over, will be 
pulled into a byte buffer in memory.
+ */
+public abstract class ChecksumLayer extends ChecksumLayerBase {
+
+  public ChecksumLayer(String layerName, String layerNamespace, int 
checksumLayerLength) {
+    super(layerName, layerNamespace, checksumLayerLength);
+  }
+
+  /**
+   * Override to compute the checksum of a buffer of data. The value computed 
is assigned to the first
+   * DFDL variable defined by the layer in the LayerInfo object.
+   *
+   * @param layerRuntime layer context for the computation
+   * @param isUnparse true if the direction is unparsing. Used because in some 
cases the computed checksum must
+   *                  be written into the byte buffer in a specific location.
+   * @param byteBuffer the bytes over which the checksum is to be computed. 
This can be modified, (for example so as
+   *                   to embed the computed checksum in the middle of the 
data somewhere) and the resulting
+   *                   bytes become the data that is written when unparsing.
+   *                   If the bytes in this buffer are modified by the compute 
method, those modified bytes are what
+   *                   the parsing will parse from, and the unparsing will 
output.
+   * @return the checksum value as an Int (32-bit signed integer)
+   */
+  public abstract int compute(
+    LayerRuntime layerRuntime,
+    boolean isUnparse,
+    ByteBuffer byteBuffer
+  );
+}

Review Comment:
   Yes that's how it works. I plan to change this to a "group" setter call that 
sets all the parameters, and then a single result getter  retrieval call  that 
way the constructor is just a plain no-arg constructor. 
   
   One annoyance is that this has to return a JInt now, not just int. Same with 
the parameter args: they can't be int, they have to be JInt.  The types have to 
be the boxed ones. I will look into whether that is truly necessary or not. 
   
   I think the prefix "getDFDLResultVariable_" is probably wrong. It should 
mention that it's about layers, so maybe "getDaffodilLayerResult_"?



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