Class DenselyPackedDecimalCodec
- java.lang.Object
- 
- org.firebirdsql.extern.decimal.DenselyPackedDecimalCodec
 
- 
 public final class DenselyPackedDecimalCodec extends java.lang.ObjectProvides conversion between Densely Packed Decimal encoding andBigInteger.Densely packed decimals are encoded in groups of three digits, which are encoded in 10 bits per group. See: A Summary of Densely Packed Decimal encoding The implementation is tied to the needs of the IEEE-754 decimal encoding and decoding of this library, so it may be quirky for other purposes. This implementation can be made to behave as for n * 3digits by constructing it forn * 3 + 1digits and callingdecodeValue(int, int, byte[])with0for the second parameter (firstDigit).- Author:
- Mark Rotteveel
 
- 
- 
Constructor SummaryConstructors Constructor Description DenselyPackedDecimalCodec(int numberOfDigits)Creates a densely packed decimal coder for the specified number of digits.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description java.math.BigIntegerdecodeValue(int signum, int firstDigit, byte[] decBytes)Decodes a densely packed decimal from a byte array to aBigInteger.java.math.BigIntegerdecodeValue(int signum, int firstDigit, byte[] decBytes, int lsbIndex)Decodes a densely packed decimal from a byte array to aBigInteger.intencodeValue(java.math.BigInteger value, byte[] decBytes)Encodes aBigIntegerto a densely packed decimal in a byte array.intencodeValue(java.math.BigInteger value, byte[] decBytes, int lsbIndex)Encodes aBigIntegerto a densely packed decimal in a byte array.
 
- 
- 
- 
Constructor Detail- 
DenselyPackedDecimalCodecpublic DenselyPackedDecimalCodec(int numberOfDigits) Creates a densely packed decimal coder for the specified number of digits.Current implementation only supports decoding and encoding n * 3 + 1number of digits withn > 0, where the most significant digit is provided by the caller during decoding.- Parameters:
- numberOfDigits- Number of digits that this coder will decode or encode
- Throws:
- java.lang.IllegalArgumentException- When- numberOfDigitsis not- n * 3 + 1with- n > 0
 
 
- 
 - 
Method Detail- 
decodeValuepublic java.math.BigInteger decodeValue(int signum, int firstDigit, byte[] decBytes)Decodes a densely packed decimal from a byte array to aBigInteger.Digits are read from the end of the array to the front. - Parameters:
- signum- Signum value (values other than- Signum.NEGATIVEare considered positive!)
- firstDigit- First, most significant, digit (- 0 <= firstDigit <= 9)
- decBytes- Byte array with the densely packed decimal, with the least significant byte at index- length - 1
- Returns:
- A BigIntegerwith the decoded value
- Throws:
- java.lang.IllegalArgumentException- When- firstDigitis out of range, or- decBytesis too small for the necessary number of bytes
- See Also:
- decodeValue(int, int, byte[], int)
 
 - 
decodeValuepublic java.math.BigInteger decodeValue(int signum, int firstDigit, byte[] decBytes, int lsbIndex)Decodes a densely packed decimal from a byte array to aBigInteger.Digits are read from lsbIndexof the array to the front.- Parameters:
- signum- Signum value (values other than- Signum.NEGATIVEare considered positive!)
- firstDigit- First, most significant, digit (- 0 <= firstDigit <= 9)
- decBytes- Byte array with the densely packed decimal, with the least significant byte at index- lsbIndex
- lsbIndex- Index of the least significant byte (or the last byte)
- Returns:
- A BigIntegerwith the decoded value
- Throws:
- java.lang.IndexOutOfBoundsException- If- lsbIndexis not valid for- decBytes
- java.lang.IllegalArgumentException- When- firstDigitis out of range, or- lsbIndexis too small for the necessary number of bytes
 
 - 
encodeValuepublic int encodeValue(java.math.BigInteger value, byte[] decBytes)Encodes aBigIntegerto a densely packed decimal in a byte array.Digits are written from the end of the array to the front. The most significant digit is not encoded into the array, but instead returned to the caller. - Parameters:
- value-- BigIntegerwith the value to encode
- decBytes- Target byte array for the densely packed decimal, with the least significant byte to be written at index- length - 1. The implementation assumes the array is zero-filled for the bits to be populated by this method.
- Returns:
- First, most significant, digit (0 <= firstDigit <= 9) to be encoded separately
- Throws:
- java.lang.IndexOutOfBoundsException- If- lsbIndexis not valid for- decBytes
- java.lang.IllegalArgumentException- When- lsbIndexis too small for the necessary number of bytes
- See Also:
- encodeValue(BigInteger, byte[], int)
 
 - 
encodeValuepublic int encodeValue(java.math.BigInteger value, byte[] decBytes, int lsbIndex)Encodes aBigIntegerto a densely packed decimal in a byte array.Digits are written from lsbIndexof the array to the front. The most significant digit is not encoded into the array, but instead returned to the caller.- Parameters:
- value-- BigIntegerwith the value to encode
- decBytes- Target byte array for the densely packed decimal, with the least significant byte to be written at index- lsbIndex. The implementation assumes the array is zero-filled for the bits to be populated by this method.
- lsbIndex- Index for the least significant byte (or the last byte)
- Returns:
- First, most significant, digit (0 <= firstDigit <= 9) to be encoded separately
- Throws:
- java.lang.IndexOutOfBoundsException- If- lsbIndexis not valid for- decBytes
- java.lang.IllegalArgumentException- When- lsbIndexis too small for the necessary number of bytes
 
 
- 
 
-