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 2018/12/14 19:39:09 UTC

[GitHub] jadams-tresys closed pull request #155: Don't require binaryNumberRep for hexBinary

jadams-tresys closed pull request #155: Don't require binaryNumberRep for hexBinary
URL: https://github.com/apache/incubator-daffodil/pull/155
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ElementBase.scala b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ElementBase.scala
index e318f0686..f93e8a62d 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ElementBase.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ElementBase.scala
@@ -657,25 +657,43 @@ trait ElementBase
     (theRepresentation, thePrimType) match {
       case (Representation.Text, PrimType.HexBinary) => Assert.impossible("type xs:hexBinary with representation='text'")
       case (Representation.Text, _) => knownEncodingAlignmentInBits
+      case (Representation.Binary, PrimType.String) => Assert.impossible("type xs:string with representation='binary'")
+      // Boolean, Float, Double, and HexBinary do not require binaryNumberRep to be defined
       case (Representation.Binary, PrimType.Float | PrimType.Boolean) => 32
       case (Representation.Binary, PrimType.Double) => 64
-      case (Representation.Binary, _) => binaryNumberRep match {
-        case BinaryNumberRep.Packed | BinaryNumberRep.Bcd | BinaryNumberRep.Ibm4690Packed => 8
-        case _ => thePrimType match {
-          case PrimType.String => Assert.impossible("type xs:string with representation='binary'")
-          case PrimType.Double | PrimType.Long | PrimType.UnsignedLong => 64
-          case PrimType.Float | PrimType.Int | PrimType.UnsignedInt | PrimType.Boolean => 32
-          case PrimType.Short | PrimType.UnsignedShort => 16
-          case PrimType.Integer | PrimType.Decimal | PrimType.Byte | PrimType.UnsignedByte | PrimType.NonNegativeInteger => 8
-          case PrimType.DateTime | PrimType.Date | PrimType.Time =>
-            binaryCalendarRep match {
-              case BinaryCalendarRep.BinaryMilliseconds => 64
-              case BinaryCalendarRep.BinarySeconds => 32
-              case _ => schemaDefinitionError("Implicit Alignment: binaryCalendarRep was %s but we expected BinarySeconds or BinaryMilliseconds.", binaryCalendarRep)
-            }
-          case PrimType.HexBinary => 8
+      case (Representation.Binary, PrimType.HexBinary) => 8
+      // Handle 64 bit types
+      case (Representation.Binary, PrimType.Long | PrimType.UnsignedLong) => 
+        binaryNumberRep match {
+          case BinaryNumberRep.Packed | BinaryNumberRep.Bcd | BinaryNumberRep.Ibm4690Packed => 8
+          case _ => 64
+        }
+      // Handle 32 bit types
+      case (Representation.Binary, PrimType.Int | PrimType.UnsignedInt | PrimType.Boolean) => 
+        binaryNumberRep match {
+          case BinaryNumberRep.Packed | BinaryNumberRep.Bcd | BinaryNumberRep.Ibm4690Packed => 8
+          case _ => 32
+        }
+      // Handle 16 bit types
+      case (Representation.Binary, PrimType.Short | PrimType.UnsignedShort) => 
+        binaryNumberRep match {
+          case BinaryNumberRep.Packed | BinaryNumberRep.Bcd | BinaryNumberRep.Ibm4690Packed => 8
+          case _ => 16
+        }
+      // Handle 8 bit types
+      case (Representation.Binary, PrimType.Integer | PrimType.Decimal | PrimType.Byte |
+        PrimType.UnsignedByte | PrimType.NonNegativeInteger) => 
+        binaryNumberRep match {
+          case BinaryNumberRep.Packed | BinaryNumberRep.Bcd | BinaryNumberRep.Ibm4690Packed => 8
+          case _ => 8
+        }
+      // Handle date types
+      case (Representation.Binary, PrimType.DateTime | PrimType.Date | PrimType.Time) =>
+        binaryCalendarRep match {
+          case BinaryCalendarRep.BinaryMilliseconds => 64
+          case BinaryCalendarRep.BinarySeconds => 32
+          case _ => schemaDefinitionError("Implicit Alignment: binaryCalendarRep was %s but we expected BinarySeconds or BinaryMilliseconds.", binaryCalendarRep)
         }
-      }
     }
   }
 
@@ -701,7 +719,7 @@ trait ElementBase
                   alignInBits, implicitAlignmentInBits, primType.name, this.knownEncodingName)
             }
             case Representation.Binary => primType match {
-              case PrimType.Float | PrimType.Double | PrimType.Boolean => /* Non textual data, no need to compare alignment to encoding's expected alignment */
+              case PrimType.Float | PrimType.Double | PrimType.Boolean | PrimType.HexBinary=> /* Non textual data, no need to compare alignment to encoding's expected alignment */
               case _ => binaryNumberRep match {
                 case BinaryNumberRep.Packed | BinaryNumberRep.Bcd | BinaryNumberRep.Ibm4690Packed => {
                   if ((alignInBits % 4) != 0)
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section10/representation_properties/RepProps.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section10/representation_properties/RepProps.tdml
index 2b5bd186c..9537bce00 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section10/representation_properties/RepProps.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section10/representation_properties/RepProps.tdml
@@ -243,4 +243,39 @@
     </tdml:errors>
   </tdml:parserTestCase>
 
+	<tdml:defineSchema name="noBinaryNumberRep">
+		<xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+    <dfdl:format lengthKind="implicit" leadingSkip="0" sequenceKind="ordered" representation="text"
+      trailingSkip="0" encoding="US-ASCII" alignment="1" alignmentUnits="bytes" initiator=""
+      terminator="" separator="" ignoreCase="no" occursCountKind="implicit" lengthUnits="bytes"
+      initiatedContent="no" textPadKind="none" truncateSpecifiedLengthString="no" textTrimKind="none"
+      escapeSchemeRef="" encodingErrorPolicy="replace" textBidi="no" floating="no"
+      byteOrder="bigEndian"/>
+
+    <xs:element name="hb_01" type="xs:hexBinary"
+      dfdl:lengthKind="explicit" dfdl:lengthUnits="bytes" dfdl:length="4"/>
+  </tdml:defineSchema>
+
+
+  <!--
+    Test name: hexBinary_01
+    Schema: noBinaryNumberRep
+    Purpose: This test demonstrates that when using hexBinary the property
+    "binaryNumberRep" is not requried.
+  -->
+
+  <tdml:parserTestCase name="hexBinary_01" root="hb_01"
+      model="noBinaryNumberRep" description="Don't require binaryNumberRep for hexBinary" roundTrip="true">
+    <tdml:document>
+      <tdml:documentPart type="byte"><![CDATA[a1b1c1d1]]></tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <hb_01>A1B1C1D1</hb_01>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+
 </tdml:testSuite>
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section10/representation_properties/TestRepProps.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section10/representation_properties/TestRepProps.scala
index b4af055b7..dee89bc6c 100644
--- a/daffodil-test/src/test/scala/org/apache/daffodil/section10/representation_properties/TestRepProps.scala
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section10/representation_properties/TestRepProps.scala
@@ -39,6 +39,8 @@ class TestRepProps {
   @Test def test_repPropMissing2() { runner.runOneTest("repPropMissing2") }
   @Test def test_repPropMissing3() { runner.runOneTest("repPropMissing3") }
 
+  @Test def test_hexBinary_01() { runner.runOneTest("hexBinary_01") }
+
   //These tests are temporary - see DFDL-994
   @Test def test_temporaryDefaultProps_01() { runner.runOneTest("temporaryDefaultProps_01") }
   @Test def test_temporaryDefaultProps_02() { runner.runOneTest("temporaryDefaultProps_02") }


 

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