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_r203360722
 
 

 ##########
 File path: 
daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/ConvertBinaryCalendarUnparser.scala
 ##########
 @@ -82,3 +95,110 @@ case class ConvertBinaryCalendarSecMilliUnparser(
     }
   }
 }
+
+abstract class BinaryCalendarBCDUnparser (
+  override val context: ElementRuntimeData,
+  pattern: String,
+  localeEv: CalendarLanguageEv,
+  calendarEv: CalendarEv)
+  extends ConvertTextCalendarProcessorBase {
+
+  protected def fromBigInteger(bigInt: JBigInteger, nBits: Int): Array[Byte] = 
DecimalUtils.bcdFromBigInteger(bigInt, nBits)
+
+  protected def putNumber(dos: DataOutputStream, bigDec: JBigDecimal, nBits: 
Int, finfo: FormatInfo): Boolean = {
+    val packedNum = fromBigInteger(bigDec.unscaledValue, nBits)
+    dos.putByteArray(packedNum, packedNum.length * 8, finfo)
+  }
 
 Review comment:
   It looks like the second parameter to fromBigInteger is the minimum number 
of bits. So it could create an array with more bytes than expected. Which means 
packedNum.length * 8 might be larger than nBits. I think this means we 
potentially write more bits than we are supposed to? Do we need to check for 
that a throw a parse error?

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