stevedlawrence commented on a change in pull request #30: Performance improvements around FormatInfo change. URL: https://github.com/apache/incubator-daffodil/pull/30#discussion_r164105491
########## File path: daffodil-io/src/main/scala/edu/illinois/ncsa/daffodil/processors/charset/BitsCharset.scala ########## @@ -0,0 +1,317 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package edu.illinois.ncsa.daffodil.processors.charset + +import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.BitOrder +import edu.illinois.ncsa.daffodil.exceptions.Assert +import java.nio.charset.CoderResult +import java.nio.charset.CodingErrorAction +import java.nio.charset.{ CharsetEncoder => JavaCharsetEncoder } +import java.nio.charset.{ CharsetDecoder => JavaCharsetDecoder } +import java.nio.charset.{ StandardCharsets => JavaStandardCharsets } +import java.nio.charset.{ Charset => JavaCharset } +import java.nio.CharBuffer +import java.nio.ByteBuffer +import edu.illinois.ncsa.daffodil.util.MaybeULong +import edu.illinois.ncsa.daffodil.util.MaybeInt + +/** + * Charset enhanced with features allowing it to work with Daffodil's Bit-wise + * DataInputStream and DataOutputStream. + * + * Daffodil uses BitsCharset as its primary abstraction for dealing with + * character sets, which enables it to support character sets where the code + * units are smaller than 1 byte. + * + * Note that BitsCharset is NOT derived from java.nio.charset.Charset, nor + * are BitsCharsetDecoder or BitsCharsetEncoder derived from + * java.nio.charset.CharsetDecoder or CharsetEncoder respectively. This is because + * these Java classes have many final methods that make it impossible for us + * to implement what we need by extending them. Hence, a BitsCharset is its own + * interface that has some similarities to the Java charset-related classes. + * + * For regular byte-centric charsets a BitsCharset is layered on top of + * Java's java.nio.charset.Charset. + */ +trait BitsCharset extends Serializable { + final override def hashCode = name.hashCode + final override def equals(other: Any) = other match { + case bcs: BitsCharset => this.name == bcs.name + case _ => false + } + def name: String + def bitWidthOfACodeUnit: Int // in units of bits + def requiredBitOrder: BitOrder + def mandatoryBitAlignment: Int + def newDecoder(): BitsCharsetDecoder + def newEncoder(): BitsCharsetEncoder + + def maybeFixedWidth: MaybeInt + + final def padCharWidthInBits = { + if (maybeFixedWidth.isDefined) + maybeFixedWidth.get + else { + this match { + case StandardBitsCharsets.UTF_8 => 8 + case _ => Assert.invariantFailed("Getting pad char width for unsupported variable-width charset: " + name) + } + } + } +} + +object BitsCharset { + +} Review comment: Is this empty object intentional? ---------------------------------------------------------------- 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
