mbeckerle commented on a change in pull request #16: Implemented packed binary
formats
URL: https://github.com/apache/incubator-daffodil/pull/16#discussion_r155307088
##########
File path:
daffodil-runtime1/src/main/scala/edu/illinois/ncsa/daffodil/processors/parsers/DelimitedParsers.scala
##########
@@ -183,3 +185,257 @@ class HexBinaryDelimitedParser(
}
}
}
+
+
+class PackedIntegerDelimitedParser(
+ erd: ElementRuntimeData,
+ textParser: TextDelimitedParserBase,
+ fieldDFAEv: FieldDFAParseEv,
+ isDelimRequired: Boolean,
+ signed: Boolean)
+ extends StringDelimitedParser(erd, TextJustificationType.None,
MaybeChar.Nope, textParser, fieldDFAEv, isDelimRequired) {
+
+ /**
+ * HexBinary is just a string in iso-8859-1 encoding.
+ *
+ * This works because java/scala's decoder for iso-8859-1 does not implement
any
+ * unmapping error detection. The official definition of iso-8859-1 has a
few unmapped
+ * characters, but most interpretations of iso-8859-1 implement these code
points anyway, with
+ * their unicode code points being exactly the byte values (interpreted
unsigned).
+ *
+ * So, in scala/java anyway, it appears one can use iso-8859-1 as characters
corresponding to
+ * raw byte values.
+ */
+
+ override def processResult(parseResult: Maybe[dfa.ParseResult], state:
PState): Unit = {
+ Assert.invariant(erd.encodingInfo.isKnownEncoding &&
erd.encodingInfo.knownEncodingCharset.charset =:= StandardCharsets.ISO_8859_1)
+
+ if (!parseResult.isDefined) this.PE(state, "%s - %s - Parse failed.",
this.toString(), erd.diagnosticDebugName)
+ else {
+ val result = parseResult.get
+ val field = if (result.field.isDefined) result.field.get else ""
+ val fieldBytes = field.getBytes(StandardCharsets.ISO_8859_1)
+ captureValueLength(state, ULong(0), ULong(fieldBytes.length * 8))
+ if (field == "") {
+ this.PE(state, "%s - %s - Parse failed.", this.toString(),
erd.diagnosticDebugName)
+ return
+ } else {
+ val num = packedToBigDecimal(fieldBytes, 0)
+ state.simpleElement.setDataValue(num)
+ if (result.matchedDelimiterValue.isDefined)
state.saveDelimitedParseResult(parseResult)
+ }
+ return
+ }
+ }
Review comment:
I second the motion! Lots of seemingly repeated code here. A base
trait/class is needed.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services