stevedlawrence commented on a change in pull request #173: Allow implicit
conversion of string to HexBinary
URL: https://github.com/apache/incubator-daffodil/pull/173#discussion_r251809757
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/ConverterOps2.scala
##########
@@ -78,3 +78,15 @@ case object StringToTime extends Converter {
result
}
}
+
+case object StringToHexBinary extends Converter with HexBinaryKind{
+ val name = "StringToHexBinary"
+
+ override def computeValue(a: AnyRef, dstate: DState): AnyRef = {
+ val result = a match {
+ case s: String => hexStringToByteArray(s)
+ case x => throw new NumberFormatException("%s cannot be cast to
dfdl:hexBinary\ndfdl:hexBinary received an unrecognized type! Must be String or
HexBinary.".format(x.toString))
+ }
+ result
+ }
+}
Review comment:
That is a little confusing, but is at least consistent with the
StringTo{Date,Time,DateTime} objects. I'd vote for consistency and less
duplication. Maybe create a bug to try to figure out why the StringTo* objects
will also convert things that aren't Strings? Maybe that's correct behavior and
they just need to be renamed to ConverToDateTime, for example.
----------------------------------------------------------------
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