mbeckerle commented on a change in pull request #12: Revised daffodil-io module to require passing in a FormatInfo object. URL: https://github.com/apache/incubator-daffodil/pull/12#discussion_r157906811
########## File path: daffodil-runtime1/src/main/scala/edu/illinois/ncsa/daffodil/processors/ProcessorStateBases.scala ########## @@ -118,60 +141,104 @@ abstract class ParseOrUnparseState protected ( with LocalBufferMixin with EncoderDecoderMixin with Logging - with FormatInfo { - - final def replacingDecoder: CharsetDecoder = decoderEntry.replacingCoder - final def reportingDecoder: CharsetDecoder = decoderEntry.reportingCoder + with FormatInfo + with SetProcessorMixin { def this(vmap: VariableMap, diags: List[Diagnostic], dataProc: Maybe[DataProcessor], tunable: DaffodilTunables) = this(new VariableBox(vmap), diags, dataProc, tunable) - /* - * Implemnet the FormatInfo trait needed by the I/O layer. - */ def infoset: DIElement private def simpleElement = infoset.asInstanceOf[DISimple] - def binaryFloatRep: BinaryFloatRep = simpleElement.erd.maybeBinaryFloatRepEv.get.evaluate(this) - def bitOrder: BitOrder = infoset.runtimeData.defaultBitOrder - def byteOrder: ByteOrder = infoset.erd.maybeByteOrderEv.get.evaluate(this) - def isFixedWidthEncoding: Boolean = { coderCacheEntry_.isFixedWidthEncoding } - def maybeCharWidthInBits: MaybeInt = { coderCacheEntry_.maybeCharWidthInBits } - def encodingMandatoryAlignmentInBits: Int = { decoder; coderCacheEntry_.encodingMandatoryAlignmentInBits } - def maybeUTF16Width: Maybe[UTF16Width] = infoset.runtimeData.encodingInfo.maybeUTF16Width - def fillByte: Byte = infoset.runtimeData.maybeFillByteEv.get.evaluate(this).toByte - def decoder = { + /* + * Implement the FormatInfo trait needed by the I/O layer. + */ + final def replacingDecoder: CharsetDecoder = decoderEntry.replacingCoder + final def reportingDecoder: CharsetDecoder = decoderEntry.reportingCoder + final def binaryFloatRep: BinaryFloatRep = simpleElement.erd.maybeBinaryFloatRepEv.get.evaluate(this) + + private def runtimeData = processor.context + private def termRuntimeData = runtimeData.asInstanceOf[TermRuntimeData] + + /** + * Returns bit order. If text, this is the bit order for the character set + * encoding. If binary, this is the bitOrder property value. + */ + final def bitOrder: BitOrder = { + val res = processor match { + case txtProc: TextProcessor => + encoder.charset() match { + case nbs: NonByteSizeCharset => nbs.requiredBitOrder + case _ => BitOrder.MostSignificantBitFirst + } + case _ => processor.context match { + case trd: TermRuntimeData => trd.defaultBitOrder + case ntrd: NonTermRuntimeData => + Assert.invariantFailed("NonTermRuntimeData: " + ntrd) + } + } + res + } + + final def byteOrder: ByteOrder = { + runtimeData match { + case erd: ElementRuntimeData => erd.maybeByteOrderEv.get.evaluate(this) + case mgrd: ModelGroupRuntimeData => { + // + // Model Groups can't have byte order. + // However, I/O layer still requests it because alignment regions + // use skip, which ultimately uses getLong/putLong, which asks for + // byteOrder. + // + // A model group DOES care about bit order however, so we + // pretend the byte order of the model group is Little Endian + // because that allows for both bit orders. + // + // (Big endian only allows MSBF bit order) + // Review comment: Improve comment above. Yes model groups can't have byteOrder properties, but they can have bitOrder due to characters in LSBF encodings, alignmentFills, etc. And since a change of bitOrder requires that we check that the new bitOrder works with the byteOrder (which can, after all, be an expression), we of necessity also need byteOrder, though if byteOrder isn't defined, we can just assume littleEndian since that works with all bitOrders. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services