Ejemplo n.º 1
0
 protected int putNumber(String name, Number n) {
   int start = _buf.position();
   if (n instanceof Integer) {
     _put(NUMBER_INT, name);
     _buf.putInt(n.intValue());
   } else if (n instanceof Long) {
     _put(NUMBER_LONG, name);
     _buf.putLong(n.longValue());
   } else {
     _put(NUMBER, name);
     _buf.putDouble(n.doubleValue());
   }
   return _buf.position() - start;
 }
Ejemplo n.º 2
0
 protected void putNumber(String name, Number n) {
   if (n instanceof Integer
       || n instanceof Short
       || n instanceof Byte
       || n instanceof AtomicInteger) {
     _put(NUMBER_INT, name);
     _buf.writeInt(n.intValue());
   } else if (n instanceof Long || n instanceof AtomicLong) {
     _put(NUMBER_LONG, name);
     _buf.writeLong(n.longValue());
   } else if (n instanceof Float || n instanceof Double) {
     _put(NUMBER, name);
     _buf.writeDouble(n.doubleValue());
   } else {
     throw new IllegalArgumentException("can't serialize " + n.getClass());
   }
 }