stevedlawrence closed pull request #89: Adding binaryCalendarRep="ibm4690Packed"
URL: https://github.com/apache/incubator-daffodil/pull/89
 
 
   

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/grammar/ElementBaseGrammarMixin.scala
 
b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/ElementBaseGrammarMixin.scala
index db1e65aac..7eb79b0ad 100644
--- 
a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/ElementBaseGrammarMixin.scala
+++ 
b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/ElementBaseGrammarMixin.scala
@@ -703,6 +703,48 @@ trait ElementBaseGrammarMixin
     ConvertZonedCombinator(this, new BCDIntegerDelimitedEndOfData(this), 
ConvertTextTimePrim(this))
   }
 
+  private lazy val ibm4690PackedKnownLengthCalendar = 
prod("ibm4690PackedKnownLengthCalendar", binaryCalendarRep == 
BinaryCalendarRep.Ibm4690Packed) {
+    ibm4690PackedDateKnownLength | ibm4690PackedTimeKnownLength | 
ibm4690PackedDateTimeKnownLength
+  }
+  private lazy val ibm4690PackedRuntimeLengthCalendar = 
prod("ibm4690PackedRuntimeLengthCalendar", binaryCalendarRep == 
BinaryCalendarRep.Ibm4690Packed) {
+    ibm4690PackedDateRuntimeLength | ibm4690PackedTimeRuntimeLength | 
ibm4690PackedDateTimeRuntimeLength
+  }
+  private lazy val ibm4690PackedDelimitedLengthCalendar = 
prod("ibm4690PackedDelimitedLengthCalendar", binaryCalendarRep == 
BinaryCalendarRep.Ibm4690Packed) {
+    ibm4690PackedDateDelimitedLength | ibm4690PackedTimeDelimitedLength | 
ibm4690PackedDateTimeDelimitedLength
+  }
+
+    // ibm4690Packed calendar with known length
+  private lazy val ibm4690PackedDateKnownLength = 
prod("ibm4690PackedDateKnownLength", primType == PrimType.Date) {
+    ConvertZonedCombinator(this, new IBM4690PackedIntegerKnownLength(this, 
false, binaryNumberKnownLengthInBits), ConvertTextDatePrim(this))
+  }
+  private lazy val ibm4690PackedDateTimeKnownLength = 
prod("ibm4690PackedDateTimeKnownLength", primType == PrimType.DateTime) {
+    ConvertZonedCombinator(this, new IBM4690PackedIntegerKnownLength(this, 
false, binaryNumberKnownLengthInBits), ConvertTextDateTimePrim(this))
+  }
+  private lazy val ibm4690PackedTimeKnownLength = 
prod("ibm4690PackedTimeKnownLength", primType == PrimType.Time) {
+    ConvertZonedCombinator(this, new IBM4690PackedIntegerKnownLength(this, 
false, binaryNumberKnownLengthInBits), ConvertTextTimePrim(this))
+  }
+
+  // ibm4690Packed calendar with runtime length
+  private lazy val ibm4690PackedDateRuntimeLength = 
prod("ibm4690PackedDateRuntimeLength", primType == PrimType.Date) {
+    ConvertZonedCombinator(this, new IBM4690PackedIntegerRuntimeLength(this, 
false), ConvertTextDatePrim(this))
+  }
+  private lazy val ibm4690PackedDateTimeRuntimeLength = 
prod("ibm4690PackedDateTimeRuntimeLength", primType == PrimType.DateTime) {
+    ConvertZonedCombinator(this, new IBM4690PackedIntegerRuntimeLength(this, 
false), ConvertTextDateTimePrim(this))
+  }
+  private lazy val ibm4690PackedTimeRuntimeLength = 
prod("ibm4690PackedTimeRuntimeLength", primType == PrimType.Time) {
+    ConvertZonedCombinator(this, new IBM4690PackedIntegerRuntimeLength(this, 
false), ConvertTextTimePrim(this))
+  }
+
+  // ibm4690Packed calendar with delimited length
+  private lazy val ibm4690PackedDateDelimitedLength = 
prod("ibm4690PackedDateDelimitedLength", primType == PrimType.Date) {
+    ConvertZonedCombinator(this, new 
IBM4690PackedIntegerDelimitedEndOfData(this, false), ConvertTextDatePrim(this))
+  }
+  private lazy val ibm4690PackedDateTimeDelimitedLength = 
prod("ibm4690PackedDateTimeDelimitedLength", primType == PrimType.DateTime) {
+    ConvertZonedCombinator(this, new 
IBM4690PackedIntegerDelimitedEndOfData(this, false), 
ConvertTextDateTimePrim(this))
+  }
+  private lazy val ibm4690PackedTimeDelimitedLength = 
prod("ibm4690PackedTimeDelimitedLength", primType == PrimType.Time) {
+    ConvertZonedCombinator(this, new 
IBM4690PackedIntegerDelimitedEndOfData(this, false), ConvertTextTimePrim(this))
+  }
 
   private lazy val textDouble = prod("textDouble", impliedRepresentation == 
Representation.Text) {
     standardTextDouble || zonedTextDouble
@@ -881,19 +923,30 @@ trait ElementBaseGrammarMixin
             case (_, n) => SDE("binary xs:dateTime must be 64 bits when 
binaryCalendarRep='binaryMilliseconds'. Length in bits was %s.", n)
           }
           case (_, BinaryCalendarRep.BinaryMilliseconds) => 
SDE("binaryCalendarRep='binaryMilliseconds' is not allowed with type %s", 
primType.name)
-          case (_, BinaryCalendarRep.Bcd) => {
+          case _ => { // Packed Decimal representations
             if ((binaryNumberKnownLengthInBits != -1) && 
(binaryNumberKnownLengthInBits % 4) != 0)
               SDE("The given length (%s bits) must be a multiple of 4 when 
using binaryCalendarRep='%s'.", binaryNumberKnownLengthInBits, 
binaryCalendarRep)
             if (calendarPatternKind != CalendarPatternKind.Explicit)
               SDE("calendarPatternKind must be 'explicit' when 
binaryCalendarRep='%s'", binaryCalendarRep)
 
-            (lengthKind, binaryNumberKnownLengthInBits) match {
-              case (LengthKind.Delimited, -1) => bcdDelimitedLengthCalendar
-              case (_, -1) => bcdRuntimeLengthCalendar
-              case (_, _) => bcdKnownLengthCalendar
+            binaryCalendarRep match {
+              case (BinaryCalendarRep.Bcd) => {
+                (lengthKind, binaryNumberKnownLengthInBits) match {
+                  case (LengthKind.Delimited, -1) => bcdDelimitedLengthCalendar
+                  case (_, -1) => bcdRuntimeLengthCalendar
+                  case (_, _) => bcdKnownLengthCalendar
+                }
+              }
+              case (BinaryCalendarRep.Ibm4690Packed) => {
+                (lengthKind, binaryNumberKnownLengthInBits) match {
+                  case (LengthKind.Delimited, -1) => 
ibm4690PackedDelimitedLengthCalendar
+                  case (_, -1) => ibm4690PackedRuntimeLengthCalendar
+                  case (_, _) => ibm4690PackedKnownLengthCalendar
+                }
+              }
+              case _ =>  notYetImplemented("Type %s when 
representation='binary' and binaryCalendarRep=%s", primType.name, 
binaryCalendarRep.toString)
             }
           }
-          case _ =>  notYetImplemented("Type %s when representation='binary' 
and binaryCalendarRep=%s", primType.name, binaryCalendarRep.toString)
         }
       }
 
diff --git 
a/daffodil-test/src/test/resources/org/apache/daffodil/section05/simple_types/SimpleTypes.tdml
 
b/daffodil-test/src/test/resources/org/apache/daffodil/section05/simple_types/SimpleTypes.tdml
index 61cf5698b..349dfadae 100644
--- 
a/daffodil-test/src/test/resources/org/apache/daffodil/section05/simple_types/SimpleTypes.tdml
+++ 
b/daffodil-test/src/test/resources/org/apache/daffodil/section05/simple_types/SimpleTypes.tdml
@@ -323,6 +323,43 @@
       </xs:complexType>
     </xs:element>
 
+    <xs:element name="dateBinIBM4690Packed" type="xs:date" 
dfdl:calendarPattern="MMddyy" dfdl:calendarPatternKind="explicit"
+      dfdl:lengthKind="explicit" dfdl:length="{ 3 }" dfdl:lengthUnits="bytes" 
dfdl:binaryCalendarRep="ibm4690Packed" />
+    <xs:element name="dateBinIBM4690Packed2" type="xs:date" 
dfdl:calendarPattern="MMddyy" dfdl:calendarPatternKind="explicit"
+      dfdl:lengthKind="explicit" dfdl:length="{ 18 }" dfdl:lengthUnits="bits" 
dfdl:binaryCalendarRep="ibm4690Packed"/>
+
+    <xs:element name="dateTimeBinIBM4690Packed">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element name="length" type="xs:int" dfdl:representation="binary"
+            dfdl:lengthKind="explicit" dfdl:length="{ 1 }" 
dfdl:lengthUnits="bytes" />
+          <xs:element name="datetime" type="xs:dateTime" 
dfdl:calendarPattern="MMddyyHHmmss" dfdl:calendarPatternKind="explicit"
+            dfdl:lengthKind="explicit" dfdl:length="{ ../ex:length }" 
dfdl:lengthUnits="bytes" dfdl:binaryCalendarRep="ibm4690Packed" />
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+
+    <xs:element name="dateTimeBinIBM4690Packed2" type="xs:dateTime" 
dfdl:calendarPattern="MMddyyyyHHmmss" dfdl:calendarPatternKind="explicit"
+      dfdl:lengthKind="explicit" dfdl:length="{ 56 }" dfdl:lengthUnits="bits" 
dfdl:binaryCalendarRep="ibm4690Packed" />
+    <xs:element name="dateTimeBinIBM4690Packed3" type="xs:dateTime" 
dfdl:calendarPattern="MMddyyyyhhmmss" dfdl:calendarPatternKind="explicit"
+      dfdl:lengthKind="implicit" dfdl:lengthUnits="bytes" 
dfdl:binaryCalendarRep="ibm4690Packed"/>
+
+    <xs:element name="timeBinIBM4690Packed">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:element name="num1" type="xs:decimal" dfdl:encoding="ISO-8859-1" 
dfdl:representation="binary" dfdl:binaryNumberRep="ibm4690Packed"
+            dfdl:lengthKind="delimited" dfdl:terminator=";" 
dfdl:binaryDecimalVirtualPoint="0"/>
+          <xs:element name="time" type="xs:time" dfdl:calendarPattern="HHmmss" 
dfdl:encoding="ISO-8859-1"
+            dfdl:calendarPatternKind="explicit" 
dfdl:binaryCalendarRep="ibm4690Packed" dfdl:lengthKind="delimited" 
dfdl:terminator=";"/>
+          <xs:element name="num2" type="xs:decimal" dfdl:encoding="ISO-8859-1" 
dfdl:representation="binary" dfdl:binaryNumberRep="ibm4690Packed"
+            dfdl:lengthKind="delimited" dfdl:terminator=";" 
dfdl:binaryDecimalVirtualPoint="0"/>
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+
+    <xs:element name="timeBinIBM4690Packed2" type="xs:time" 
dfdl:calendarPatternKind="implicit"
+      dfdl:lengthKind="explicit" dfdl:length="{ 5 }" dfdl:lengthUnits="bytes" 
dfdl:binaryCalendarRep="ibm4690Packed"/>
+
     <xs:element name="dateBinInvalid" type="xs:date" 
dfdl:calendarPattern="yyyy.MM.dd" dfdl:calendarPatternKind="explicit" 
dfdl:lengthKind="explicit"
       dfdl:length="{ 4 }" dfdl:lengthUnits="bytes" 
dfdl:binaryCalendarRep="binarySeconds" 
dfdl:binaryCalendarEpoch="1970-01-01T00:00:00+00:00"/>
 
@@ -2570,6 +2607,118 @@
     </tdml:infoset>
   </tdml:parserTestCase>
 
+  <tdml:parserTestCase name="dateBinIBM4690Packed" root="dateBinIBM4690Packed"
+    model="SimpleTypes-binary" description="Section 5 Schema types-dateTime - 
DFDL-5-016R"
+    roundTrip="true">
+
+    <tdml:document>
+      <tdml:documentPart type="byte">12 14 23</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <dateBinIBM4690Packed>2023-12-14</dateBinIBM4690Packed>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="dateBinIBM4690Packed2" 
root="dateBinIBM4690Packed2"
+    model="SimpleTypes-binary" description="Section 5 Schema types-dateTime - 
DFDL-5-016R" >
+
+    <tdml:document>
+      <tdml:documentPart type="bits">0000 0000 00000 0000 
00</tdml:documentPart>
+    </tdml:document>
+    <tdml:errors>
+      <tdml:error>Schema Definition Error</tdml:error>
+      <tdml:error>The given length (18 bits) must be a multiple of 4 when 
using binaryCalendarRep='ibm4690Packed'</tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="dateBinIBM4690Packed3" root="dateBinIBM4690Packed"
+    model="SimpleTypes-binary" description="Section 5 Schema types-dateTime - 
DFDL-5-016R"
+    roundTrip="true">
+
+    <tdml:document>
+      <tdml:documentPart type="byte">D2 14 23</tdml:documentPart>
+    </tdml:document>
+    <tdml:errors>
+      <tdml:error>Parse Error</tdml:error>
+      <tdml:error>Expected unsigned data but parsed a negative 
number</tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="dateTimeBinIBM4690Packed" 
root="dateTimeBinIBM4690Packed"
+    model="SimpleTypes-binary" description="Section 5 Schema types-dateTime - 
DFDL-5-016R"
+    roundTrip="true">
+
+    <tdml:document>
+      <tdml:documentPart type="byte">06 11 30 07 04 15 08</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <dateTimeBinIBM4690Packed>
+          <length>6</length>
+          <datetime>2007-11-30T04:15:08.000000</datetime>
+        </dateTimeBinIBM4690Packed>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="dateTimeBinIBM4690Packed2" 
root="dateTimeBinIBM4690Packed2"
+    model="SimpleTypes-binary" description="Section 5 Schema types-dateTime - 
DFDL-5-016R"
+    roundTrip="twoPass">
+
+    <tdml:document>
+      <tdml:documentPart type="byte">03 20 18 56 09 51 38</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        
<dateTimeBinIBM4690Packed2>1856-03-20T09:51:38.000000</dateTimeBinIBM4690Packed2>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="dateTimeBinIBM4690Packed3" 
root="dateTimeBinIBM4690Packed3"
+    model="SimpleTypes-binary" description="Section 5 Schema types-dateTime - 
DFDL-5-016R" >
+
+    <tdml:document>
+      <tdml:documentPart type="byte">01 45 00 99 87</tdml:documentPart>
+    </tdml:document>
+    <tdml:errors>
+      <tdml:error>Schema Definition Error</tdml:error>
+      <tdml:error>Length of binary data 'DateTime' with 
binaryCalendarRep='ibm4690Packed' cannot be determined implicitly</tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="timeBinIBM4690Packed" root="timeBinIBM4690Packed"
+    model="SimpleTypes-binary" description="Section 5 Schema types-dateTime - 
DFDL-5-016R"
+    roundTrip="true">
+
+    <tdml:document>
+      <tdml:documentPart type="byte">27 3B 10 32 49 3B 19 
3B</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <timeBinIBM4690Packed>
+          <num1>27</num1>
+          <time>10:32:49.000000</time>
+          <num2>19</num2>
+        </timeBinIBM4690Packed>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="timeBinIBM4690Packed2" 
root="timeBinIBM4690Packed2"
+    model="SimpleTypes-binary" description="Section 5 Schema types-dateTime - 
DFDL-5-016R" >
+
+    <tdml:document>
+      <tdml:documentPart type="byte">01 45 00 99 87</tdml:documentPart>
+    </tdml:document>
+    <tdml:errors>
+      <tdml:error>Schema Definition Error</tdml:error>
+      <tdml:error>calendarPatternKind must be 'explicit' when 
binaryCalendarRep='ibm4690Packed'</tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
+
   <tdml:parserTestCase name="dateBinInvalid" root="dateBinInvalid"
     model="SimpleTypes-binary" description="Section 5 Schema types-dateTime - 
DFDL-5-016R" >
 
diff --git 
a/daffodil-test/src/test/scala/org/apache/daffodil/section05/simple_types/TestSimpleTypes.scala
 
b/daffodil-test/src/test/scala/org/apache/daffodil/section05/simple_types/TestSimpleTypes.scala
index c5a0ed44b..55c5b4355 100644
--- 
a/daffodil-test/src/test/scala/org/apache/daffodil/section05/simple_types/TestSimpleTypes.scala
+++ 
b/daffodil-test/src/test/scala/org/apache/daffodil/section05/simple_types/TestSimpleTypes.scala
@@ -209,6 +209,16 @@ class TestSimpleTypes {
   @Test def test_dateTimeBinBCD2() { runner.runOneTest("dateTimeBinBCD2") }
   @Test def test_dateTimeBinBCD3() { runner.runOneTest("dateTimeBinBCD3") }
   @Test def test_dateTimeBinBCD4() { runner.runOneTest("dateTimeBinBCD4") }
+
+  @Test def test_dateBinIBM4690Packed() { 
runner.runOneTest("dateBinIBM4690Packed") }
+  @Test def test_dateBinIBM4690Packed2() { 
runner.runOneTest("dateBinIBM4690Packed2") }
+  @Test def test_dateBinIBM4690Packed3() { 
runner.runOneTest("dateBinIBM4690Packed3") }
+  @Test def test_dateTimeBinIBM4690Packed() { 
runner.runOneTest("dateTimeBinIBM4690Packed") }
+  @Test def test_dateTimeBinIBM4690Packed2() { 
runner.runOneTest("dateTimeBinIBM4690Packed2") }
+  @Test def test_dateTimeBinIBM4690Packed3() { 
runner.runOneTest("dateTimeBinIBM4690Packed3") }
+  @Test def test_timeBinIBM4690Packed() { 
runner.runOneTest("timeBinIBM4690Packed") }
+  @Test def test_timeBinIBM4690Packed2() { 
runner.runOneTest("timeBinIBM4690Packed2") }
+
   @Test def test_dateBinInvalid() { runner.runOneTest("dateBinInvalid") }
 
   @Test def test_dateTimeImplicitPattern() { 
runner.runOneTest("dateTimeImplicitPattern") }


 

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