Esempio n. 1
0
 public static void writeVLong(long i, FastOutputStream out) throws IOException {
   while ((i & ~0x7F) != 0) {
     out.writeByte((byte) ((i & 0x7f) | 0x80));
     i >>>= 7;
   }
   out.writeByte((byte) i);
 }
Esempio n. 2
0
 public void writeTag(byte tag, int size) throws IOException {
   if ((tag & 0xe0) != 0) {
     if (size < 0x1f) {
       daos.writeByte(tag | size);
     } else {
       daos.writeByte(tag | 0x1f);
       writeVInt(size - 0x1f, daos);
     }
   } else {
     daos.writeByte(tag);
     writeVInt(size, daos);
   }
 }
Esempio n. 3
0
 public void writeLong(long val) throws IOException {
   if ((val & 0xff00000000000000L) == 0) {
     int b = SLONG | ((int) val & 0x0f);
     if (val >= 0x0f) {
       b |= 0x10;
       daos.writeByte(b);
       writeVLong(val >>> 4, daos);
     } else {
       daos.writeByte(b);
     }
   } else {
     daos.writeByte(LONG);
     daos.writeLong(val);
   }
 }
Esempio n. 4
0
  public void writeInt(int val) throws IOException {
    if (val > 0) {
      int b = SINT | (val & 0x0f);

      if (val >= 0x0f) {
        b |= 0x10;
        daos.writeByte(b);
        writeVInt(val >>> 4, daos);
      } else {
        daos.writeByte(b);
      }

    } else {
      daos.writeByte(INT);
      daos.writeInt(val);
    }
  }
Esempio n. 5
0
  public boolean writePrimitive(Object val) throws IOException {
    if (val == null) {
      daos.writeByte(NULL);
      return true;
    } else if (val instanceof String) {
      writeStr((String) val);
      return true;
    } else if (val instanceof Number) {

      if (val instanceof Integer) {
        writeInt(((Integer) val).intValue());
        return true;
      } else if (val instanceof Long) {
        writeLong(((Long) val).longValue());
        return true;
      } else if (val instanceof Float) {
        writeFloat(((Float) val).floatValue());
        return true;
      } else if (val instanceof Double) {
        daos.writeByte(DOUBLE);
        daos.writeDouble(((Double) val).doubleValue());
        return true;
      } else if (val instanceof Byte) {
        daos.writeByte(BYTE);
        daos.writeByte(((Byte) val).intValue());
        return true;
      } else if (val instanceof Short) {
        daos.writeByte(SHORT);
        daos.writeShort(((Short) val).intValue());
        return true;
      }
      return false;

    } else if (val instanceof Date) {
      daos.writeByte(DATE);
      daos.writeLong(((Date) val).getTime());
      return true;
    } else if (val instanceof Boolean) {
      if ((Boolean) val) daos.writeByte(BOOL_TRUE);
      else daos.writeByte(BOOL_FALSE);
      return true;
    } else if (val instanceof byte[]) {
      writeByteArray((byte[]) val, 0, ((byte[]) val).length);
      return true;
    } else if (val instanceof ByteBuffer) {
      ByteBuffer buf = (ByteBuffer) val;
      writeByteArray(buf.array(), buf.position(), buf.limit() - buf.position());
      return true;
    } else if (val == END_OBJ) {
      writeTag(END);
      return true;
    }
    return false;
  }
Esempio n. 6
0
 public void marshal(Object nl, OutputStream os) throws IOException {
   assert !alreadyMarshalled;
   init(FastOutputStream.wrap(os));
   try {
     daos.writeByte(VERSION);
     writeVal(nl);
   } finally {
     daos.flushBuffer();
     alreadyMarshalled = true;
   }
 }
Esempio n. 7
0
 public void writeFloat(float val) throws IOException {
   daos.writeByte(FLOAT);
   daos.writeFloat(val);
 }
Esempio n. 8
0
 public void writeTag(byte tag) throws IOException {
   daos.writeByte(tag);
 }