mbeckerle commented on code in PR #1337:
URL: https://github.com/apache/daffodil/pull/1337#discussion_r1819818172
##########
daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/unparsers/runtime1/BinaryNumberUnparsers.scala:
##########
@@ -78,17 +76,61 @@ abstract class BinaryNumberBaseUnparser(override val
context: ElementRuntimeData
}
-abstract class BinaryIntegerBaseUnparser(e: ElementRuntimeData, signed:
Boolean)
+abstract class BinaryIntegerBaseUnparser(e: ElementRuntimeData)
extends BinaryNumberBaseUnparser(e) {
+ private val primNumeric =
e.optPrimType.get.asInstanceOf[NodeInfo.PrimType.PrimNumeric]
+
override def putNumber(
dos: DataOutputStream,
value: JNumber,
nBits: Int,
finfo: FormatInfo
): Boolean = {
+ val state = finfo.asInstanceOf[UState]
+ if (primNumeric.minWidth.isDefined) {
+ val isSigned = primNumeric.isSigned
+ val signedStr = if (isSigned) "signed" else "unsigned"
+ val minWidth = primNumeric.minWidth.get
+ if(nBits < minWidth) {
+ val outOfRangeFmtStr =
+ "Minimum length for a %s binary integer is %d bit(s), number of bits
%d out of range. " +
+ "An unsigned integer with length 1 bit could be used instead."
+ if (isSigned && state.tunable.allowSignedIntegerLength1Bit) {
+ state.SDW(
+ WarnID.SignedBinaryIntegerLength1Bit,
+ outOfRangeFmtStr,
+ signedStr,
+ minWidth,
+ nBits
+ )
+ return false
Review Comment:
> So it looks like we parse data that is -1 to an infoset containing 0,
which I think we should be unparsing to 0 instead of 1 here since the max value
is 0?
What does "parse data that is -1" mean? How can the data aka bits be -1.
Let's use this terminology: data means the representation, aka the "bit
stream".
The value, logical value, or infoset value is a number with no concept of
representation.
Unparse logical value -1 should give a single '1' bit in the data stream.
Unparse 0 should give a single '0' bit in the data stream. Parsing is
symmetric.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]