jadams-tresys commented on a change in pull request #16: Implemented packed binary formats URL: https://github.com/apache/incubator-daffodil/pull/16#discussion_r161832556
########## File path: daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/util/DecimalUtils.scala ########## @@ -0,0 +1,342 @@ +/* + * Licensed 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.util + +import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.BinaryNumberCheckPolicy + +import java.math.{ BigInteger => JBigInteger, BigDecimal => JBigDecimal } + +object DecimalUtils { + + def signCodesToHex(signCodes: String, policy: BinaryNumberCheckPolicy): Map[String, List[Int]] = { + // remove all spaces from the string + val str: String = signCodes.replaceAll("\\s", "") + val chars: Array[Char] = str.toCharArray() Review comment: I was originally going to do more validation here, but when I was testing things it seemed that any invalid string in the binaryPackedSignCodes field would simply get picked up by the general schema validation before the test would even run: [debug] Test edu.illinois.ncsa.daffodil.section13.packed.TestPacked.testPackedCharset01 started [error] Test edu.illinois.ncsa.daffodil.section13.packed.TestPacked.testPackedCharset01 failed: edu.illinois.ncsa.daffodil.tdml.TDMLException: org.xml.sax.SAXParseException; systemId: file:/home/jadams/Programming/tresys/daffodil/daffodil-test/target/scala-2.11/test-classes/edu/illinois/ncsa/daffodil/section13/packed/packed.tdml; lineNumber: 59; columnNumber: 114; cvc-attribute.3: The value 'C DFC' of attribute 'binaryPackedSignCodes' on element 'dfdl:format' is not valid with respect to its type, 'BinaryPackedSignCodes'. [error] org.xml.sax.SAXParseException; systemId: file:/home/jadams/Programming/tresys/daffodil/daffodil-test/target/scala-2.11/test-classes/edu/illinois/ncsa/daffodil/section13/packed/packed.tdml; lineNumber: 59; columnNumber: 114; cvc-pattern-valid: Value 'C DFC' is not facet-valid with respect to pattern '(A|C|E|F) (B|D) (F) (A|C|E|F|0)' for type 'BinaryPackedSignCodes'., took 0.001 sec So, I wasn't sure if more validation in the code was necessary. If it is, let me know and I can add it in while I make some of the other improvements you have suggested. ---------------------------------------------------------------- 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
