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_r251584674
 
 

 ##########
 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:
   Does it make sense to modify XSHexBinary to call this function now so as to 
minimize duplicate code? So XSHexBInary basically just calls 
StringToHexBinary.computeValue(...), and all the actual conversion logic is 
only in this object?  This looks like how we do other conversions like XSTime 
vs StringToTime

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

Reply via email to