You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2019/12/13 03:45:17 UTC

[GitHub] [incubator-daffodil] mbeckerle commented on a change in pull request #301: DAFFODIL-2169 Add typesafty to our handling of infoset data values.

mbeckerle commented on a change in pull request #301: DAFFODIL-2169 Add typesafty to our handling of infoset data values.
URL: https://github.com/apache/incubator-daffodil/pull/301#discussion_r357474841
 
 

 ##########
 File path: daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/ConverterOps3.scala
 ##########
 @@ -20,37 +20,54 @@ package org.apache.daffodil.dpath
 import org.apache.daffodil.util.Numbers._
 import org.apache.daffodil.util.Misc
 import java.math.{ BigInteger => JBigInt }
+import org.apache.daffodil.infoset.DataValue.DataValueInt
+import org.apache.daffodil.infoset.DataValue.DataValueLong
+import org.apache.daffodil.infoset.DataValue.DataValuePrimitive
+import org.apache.daffodil.infoset.DataValue.DataValueString
+import org.apache.daffodil.infoset.DataValue.DataValueString
+import org.apache.daffodil.infoset.DataValue.DataValueBigInt
+import org.apache.daffodil.infoset.DataValue.DataValuePrimitive
+import org.apache.daffodil.infoset.DataValue.DataValuePrimitive
+import org.apache.daffodil.infoset.DataValue.DataValueLong
+import org.apache.daffodil.infoset.DataValue.DataValuePrimitive
+import org.apache.daffodil.infoset.DataValue.DataValueLong
+import org.apache.daffodil.infoset.DataValue.DataValueShort
+import org.apache.daffodil.infoset.DataValue.DataValueLong
+import org.apache.daffodil.infoset.DataValue.DataValueInt
+import org.apache.daffodil.infoset.DataValue.DataValueByte
+import org.apache.daffodil.infoset.DataValue.DataValueShort
+import org.apache.daffodil.infoset.DataValue.DataValuePrimitive
 
 case object NumericToString extends ToString
 case object DateTimeToString extends ToString
 case object HexBinaryToString extends Converter {
-  override def computeValue(a: AnyRef, dstate: DState): AnyRef = {
-    val bytes = a.asInstanceOf[Array[Byte]]
+  override def computeValue(a: DataValuePrimitive, dstate: DState): DataValueString = {
+    val bytes = a.getByteArray
     val hex = Misc.bytes2Hex(bytes)
     hex
   }
 }
 case object HexStringToLong extends Converter {
-  override def computeValue(a: AnyRef, dstate: DState): AnyRef = {
+  override def computeValue(a: DataValuePrimitive, dstate: DState): DataValueLong = {
     val res =
       try {
-        val str = a.asInstanceOf[String]
+        val str = a.getString
         java.lang.Long.parseLong(str, 16)
       } catch {
         case nfe: NumberFormatException => {
           val e = new NumberFormatException("Cannot convert to type long: " + nfe.getMessage())
           throw e
         }
       }
-    asAnyRef(res)
+    res
   }
 }
 case object HexStringToUnsignedLong extends Converter {
-  override def computeValue(a: AnyRef, dstate: DState): AnyRef = {
-    val res =
+  override def computeValue(a: DataValuePrimitive, dstate: DState): DataValueBigInt = {
+    val res: DataValueBigInt =
       try {
-        val str = a.asInstanceOf[String]
-        BigInt(str, 16)
+        val str = a.getString
+        new JBigInt(str, 16)
 
 Review comment:
   So do we have a test that verifies that enums using the typecalc stuff all work properly now?
   That's the *real* reason this was revisited. 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services