stevedlawrence commented on a change in pull request #83: Adding value of 'bcd' 
to binaryCalendarRep
URL: https://github.com/apache/incubator-daffodil/pull/83#discussion_r203368789
 
 

 ##########
 File path: 
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/PrimitivesDateTime1.scala
 ##########
 @@ -207,3 +230,94 @@ case class ConvertBinaryCalendarSecMilliParser(
     start.simpleElement.overwriteDataValue(newCal)
   }
 }
+
+abstract class BinaryCalendarBCDParser(
+  override val context: ElementRuntimeData,
+  hasTZ: Boolean,
+  pattern: String,
+  localeEv: CalendarLanguageEv,
+  calendarEv: CalendarEv,
+  xsdType: String,
+  prettyType: String)
+  extends CalendarParser {
+
+  def toBigDecimal(num: Array[Byte], scale: Int): JBigDecimal = 
DecimalUtils.bcdToBigDecimal(num, scale)
+
+  def getBitLength(start: ParseOrUnparseState): Int
+
+  def parse(start: PState): Unit = {
+
+    val dis = start.dataInputStream
+    val nBits = getBitLength(start)
+    if (nBits == 0) return // zero length is used for outputValueCalc often.
+
+    if (!dis.isDefinedForLength(nBits)) {
+      PE(start, "Insufficient bits in data. Needed %d bit(s) but found only %d 
available.", nBits, dis.remainingBits.get)
+      return
+    }
+
+    try {
+      // Use '0' for the binaryDecimalVirtualPoint because its location will 
be implied by the pattern
+      val bigDec: BigDecimal = toBigDecimal(dis.getByteArray(nBits, start), 0)
 
 Review comment:
   What happens if the result is negative? That will never match the calendar 
pattern, so maybe we should just return a ParseError here instead of trying and 
failing to parse?

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