示例#1
0
 protected short[] readFlags(IDataInput input) {
   boolean hasNextFlag = true;
   short[] flagsArray = new short[2];
   int i = 0;
   while (hasNextFlag) {
     short flags = (short) input.readUnsignedByte();
     log.debug("Unsigned byte: {}", flags);
     if (i == flagsArray.length) {
       short[] tempArray = new short[i * 2];
       System.arraycopy(flagsArray, 0, tempArray, 0, flagsArray.length);
       flagsArray = tempArray;
     }
     flagsArray[i] = flags;
     if ((flags & 0x80) != 0) {
       hasNextFlag = true;
     } else {
       hasNextFlag = false;
     }
     ++i;
   }
   log.debug("Flag count: {}", flagsArray.length);
   return flagsArray;
 }
示例#2
0
  @SuppressWarnings("rawtypes")
  public void readExternal(IDataInput input) {
    log.debug("AbstractMessage - Read external");
    short[] flagsArray = readFlags(input);
    for (int i = 0; i < flagsArray.length; ++i) {
      short flags = flagsArray[i];
      short reservedPosition = 0;
      if (i == 0) {
        if ((flags & 0x1) != 0) {
          Object obj = input.readObject();
          log.debug("Body object: {} name: {}", obj, obj.getClass().getName());

          body = obj;
        }
        if ((flags & 0x2) != 0) {
          Object obj = input.readObject();
          log.debug("Client id object: {} name: {}", obj, obj.getClass().getName());

          clientId = ((String) obj);
        }
        if ((flags & 0x4) != 0) {
          Object obj = input.readObject();
          log.debug("Destination object: {} name: {}", obj, obj.getClass().getName());

          destination = ((String) obj);
        }
        if ((flags & 0x8) != 0) {
          Object obj = input.readObject();
          log.debug("Headers object: {} name: {}", obj, obj.getClass().getName());

          headers = ((ObjectMap) obj);
        }
        if ((flags & 0x10) != 0) {
          Object obj = input.readUTF();
          log.debug("Message id object: {} name: {}", obj, obj.getClass().getName());

          messageId = ((String) obj);
        }
        if ((flags & 0x20) != 0) {
          Object obj = input.readObject();
          log.debug("Timestamp object: {} name: {}", obj, obj.getClass().getName());

          timestamp = ((Number) obj).longValue();
        }
        if ((flags & 0x40) != 0) {
          Object obj = input.readObject();
          log.debug("TTL object: {} name: {}", obj, obj.getClass().getName());
          timeToLive = ((Number) obj).longValue();
        }
        reservedPosition = 7;
      } else if (i == 1) {
        if ((flags & 0x1) != 0) {
          Object obj = input.readObject();
          log.debug("Client id (bytes) object: {} name: {}", obj, obj.getClass().getName());
          if (obj instanceof ByteArray) {
            ByteArray ba = (ByteArray) obj;
            clientIdBytes = new byte[ba.length()];
            ba.readBytes(clientIdBytes);
            clientId = RandomGUID.fromByteArray(clientIdBytes);
          }
        }
        if ((flags & 0x2) != 0) {
          Object obj = input.readObject();
          log.debug("Message id (bytes) object: {} name: {}", obj, obj.getClass().getName());
          if (obj instanceof ByteArray) {
            ByteArray ba = (ByteArray) obj;
            messageIdBytes = new byte[ba.length()];
            ba.readBytes(messageIdBytes);
            messageId = RandomGUID.fromByteArray(messageIdBytes);
          }
        }
        reservedPosition = 2;
      }
      if (flags >> reservedPosition == 0) {
        continue;
      }
      for (short j = reservedPosition; j < 6; j = (short) (j + 1)) {
        if ((flags >> j & 0x1) == 0) {
          continue;
        }
        input.readObject();
      }
    }
  }