OSDir


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] stevedlawrence commented on a change in pull request #77: Modifications to IO layer to support streaming input data


stevedlawrence commented on a change in pull request #77: Modifications to IO layer to support streaming input data
URL: https://github.com/apache/incubator-daffodil/pull/77#discussion_r201097800
 
 

 ##########
 File path: daffodil-lib/src/main/scala/org/apache/daffodil/util/BitOrder.scala
 ##########
 @@ -213,4 +213,60 @@ object Bits {
     String.format("%8s", unsignedByte.toBinaryString).replace(' ', '0')
   }
 
+  def signExtend(l: Long, bitLength: Int): Long = {
+    Assert.usage(bitLength > 0 && bitLength <= 64)
+    if (bitLength == 1) return l // a single bit has no sign to extend
+    val shift = 64 - bitLength
+    val res = ((l << shift) >> shift) // arithmetic shift right extends sign.
+    res
+  }
+
+  def unSignExtend(l: Long, bitLength: Int): Long = {
+    Assert.usage(bitLength > 0 && bitLength <= 64)
+    val mask = if (bitLength == 64) -1L else (1L << bitLength) - 1
+    l & mask
+  }
+
+  /**
+   * Round up the bitPosition to the nearest byte position.
+   *
+   * For example, say we want to read up to a bit position that is not a full
+   * byte. That will require reading the full byte, leaving the bytePosition
+   * past our bit position. This function can be used to determine where that
+   * byte position will be. Essentially, if bitPos0b is not a multiple of 8, we
+   * round up one byte.
+   */
+  def roundUpToByte(bitPos0b: Long): Long = {
 
 Review comment:
   Agreed. This method isn't really used for aligning (though I guess it could be), but the second name is much more clear about what it's doing. Fixed.

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


With regards,
Apache Git Services