You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@daffodil.apache.org by GitBox <gi...@apache.org> on 2019/01/28 20:53:16 UTC

[GitHub] jadams-tresys commented on a change in pull request #173: Allow implicit conversion of string to HexBinary

jadams-tresys 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_r251588290
 
 

 ##########
 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:
   I wasn't sure that it would, since the XSHexBinary computeValue also accepts reading in a Byte array, so I thought it might be confusing if the StringToHexBinary converter also allows reading in both a String or a Byte array.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services