Ejemplo n.º 1
0
    protected static void _encodeBigInteger(NSCoder coder, BigInteger bigInteger) {
      BigInteger integer = bigInteger;
      boolean isNegative = integer.signum() < 0;
      if (isNegative) {
        integer = integer.negate();
      }

      byte[] bytes = integer.toByteArray();
      int length = bytes.length;
      short shortCount = (short) (length / 2 + length % 2);

      coder.encodeShort(shortCount);
      coder.encodeBoolean(isNegative);
      coder.encodeBoolean(false);
      coder.encodeInt(8);

      for (int i = 0; i < _MaxShortArrayLength; ++i)
        if (i < shortCount) coder.encodeShort(_shortFromByteArray(bytes, length - (2 * (i + 1))));
        else coder.encodeShort((short) 0);
    }
Ejemplo n.º 2
0
    public void encodeWithCoder(Object receiver, NSCoder coder) {
      int scale = ((BigDecimal) receiver).scale();
      BigInteger mantissa = ((BigDecimal) receiver).movePointRight(scale).toBigInteger();

      int byteLength = mantissa.bitLength();

      while (++byteLength / 8 > _MaxMantissaSize) {
        int byteDifference = byteLength - _MaxMantissaSize;

        if (byteDifference > _MaxByteDifference) {
          byteDifference = _MaxByteDifference;
        }

        int exponentDelta = (int) _logBaseTen(Math.pow(2.0D, 8 * byteDifference));
        BigInteger divisor = new BigInteger("10").pow(exponentDelta);

        scale -= exponentDelta;
        mantissa = mantissa.divide(divisor);
      }

      coder.encodeInt(-scale);
      _encodeBigInteger(coder, mantissa);
    }
Ejemplo n.º 3
0
 public void encodeWithCoder(Object receiver, NSCoder coder) {
   coder.encodeInt(0);
   _encodeBigInteger(coder, (BigInteger) receiver);
 }
Ejemplo n.º 4
0
 public void encodeWithCoder(Object receiver, NSCoder coder) {
   _encodeUTF8("i", coder);
   coder.encodeInt(((Integer) receiver).intValue());
 }