mbeckerle commented on a change in pull request #651:
URL: https://github.com/apache/daffodil/pull/651#discussion_r723507554
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/layers/LayerTransformer.scala
##########
@@ -282,4 +234,234 @@ case class LayerNotEnoughDataException(layerSRD:
SequenceRuntimeData, state: PSt
extends LayerException(layerSRD, state, One(cause), None, nBytesRequired) {
override def isError = true
override def modeName = "Parse"
- }
\ No newline at end of file
+ }
+
+
+
+class LayerRuntimeInfoImpl(val srd: SequenceRuntimeData,
+ maybeLayerCharsetEv: Maybe[LayerCharsetEv],
+ maybeLayerLengthKind: Maybe[LayerLengthKind],
+ maybeLayerLengthEv: Maybe[LayerLengthEv],
+ maybeLayerLengthUnits: Maybe[LayerLengthUnits],
+ maybeLayerBoundaryMarkEv: Maybe[LayerBoundaryMarkEv])
+ extends LayerRuntimeInfo {
+
+ def evaluatables: Seq[Evaluatable[AnyRef]] =
+ maybeLayerCharsetEv.toScalaOption.toSeq ++
+ maybeLayerLengthEv.toScalaOption.toSeq ++
+ maybeLayerBoundaryMarkEv.toScalaOption.toSeq
+
+
+ def layerInfo(state: ParseOrUnparseState): LayerInfo =
+ new LayerInfoImpl(state, srd,
+ maybeLayerCharsetEv,
+ maybeLayerLengthKind,
+ maybeLayerLengthEv,
+ maybeLayerLengthUnits,
+ maybeLayerBoundaryMarkEv)
+}
+
+/**
+ * Allows access to all the layer properties, if defined, including
+ * evaluating expressions if the properties values are defined as expressions.
+ */
+sealed trait LayerInfo {
+ def optLayerCharset: Option[java.nio.charset.Charset]
+ def optLayerLengthKind: Option[LayerLengthKind]
+ def optLayerLength: Option[Long]
+ def optLayerLengthUnits: Option[LayerLengthUnits]
+ def optLayerBoundaryMark: Option[String]
+}
+
+class LayerInfoImpl(state: ParseOrUnparseState,
+ srd: SequenceRuntimeData,
+ maybeLayerCharsetEv: Maybe[LayerCharsetEv],
+ maybeLayerLengthKind: Maybe[LayerLengthKind],
+ maybeLayerLengthEv: Maybe[LayerLengthEv],
+ maybeLayerLengthUnits: Maybe[LayerLengthUnits],
+ maybeLayerBoundaryMarkEv: Maybe[LayerBoundaryMarkEv])
+extends LayerInfo {
+
+ override def optLayerCharset: Option[Charset] =
maybeLayerCharsetEv.toScalaOption.map {
+ _.evaluate(state)
+ } match {
+ case Some(bitsCharsetJava: BitsCharsetJava) =>
Some(bitsCharsetJava.javaCharset)
+ case None => None
+ case Some(other) => None // only java charsets are supported.
+ }
+
+ override def optLayerLengthKind: Option[LayerLengthKind] =
maybeLayerLengthKind.toScalaOption
+
+ override def optLayerLength: Option[Long] =
maybeLayerLengthEv.toScalaOption.map{ _.evaluate(state) }
+
+ override def optLayerLengthUnits: Option[LayerLengthUnits] =
maybeLayerLengthUnits.toScalaOption
+
+ override def optLayerBoundaryMark: Option[String] =
maybeLayerBoundaryMarkEv.toScalaOption.map{ _.evaluate(state) }
+}
+
+
+abstract class ByteBufferExplicitLengthLayerTransform[T](
+ layerRuntimeInfoArg: LayerRuntimeInfo,
+ layerName: String,
+ variablesNamespace: String,
+ variablesPreferredNamespacePrefix: String,
+ localNamesAndTypesOfVariablesToRead: Seq[(String, String)],
+ localNameOfVariableToWrite: String,
+ outputVariableTypeLocalNameAsString: String)
+ extends LayerTransformer(layerName, layerRuntimeInfoArg) {
Review comment:
Well there are two ways you can get output from a layer calculation. By
changing the data that gets parsed, so that something comes through in that
data, and by writing DFDL variables.
There are 2 ways to get input to a layer. One is the data stream, but you
have no control of that. The other is via DFDL variables.
The common uses of input DFDL variables would be to pass parameters to the
layer transform algorithm, or to propagate output from an earlier layer
transform for incorporation into a subsequent layer transform. This is really
just another parameter to the algorithm.
Other kinds of output from transform layer algorithms would be DFDL
variables that indicate statistics about the data such as the
degree-of-compression of the data if compressed, or a string giving the
language codes for the natural-languages found by heuristic in the text (for a
text layer).
The fully general thing would take a list of variables as input, and a list
of variables as output. But we're able to finess the writing of the variable,
and exposing the stuff about DataPrimitiveValue, because we know in this idiom
we are producing exactly one value.
So I do expect base classes that make various families of layer transforms,
to emerge.
--
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]