예제 #1
0
  @Override
  protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    in.markReaderIndex();
    if (!Utils.checkHeaderAvailability(in)) {
      in.resetReaderIndex();
      return;
    }
    in.resetReaderIndex();

    byte messageType = Utils.readMessageType(in);

    DemuxDecoder decoder = m_decoderMap.get(messageType);
    if (decoder == null) {
      throw new CorruptedFrameException(
          "Can't find any suitable decoder for message type: " + messageType);
    }
    decoder.decode(ctx, in, out);
  }
예제 #2
0
  private void initHeaderQos(ByteBuf buff, int messageID, AbstractMessage.QOSType... qoss)
      throws IllegalAccessException {
    buff.clear()
        .writeByte(AbstractMessage.SUBACK << 4)
        .writeBytes(Utils.encodeRemainingLength(2 + qoss.length));

    buff.writeShort(messageID);
    for (AbstractMessage.QOSType qos : qoss) {
      buff.writeByte(qos.ordinal());
    }
  }
예제 #3
0
파일: Utils.java 프로젝트: GayashanNA/andes
  static boolean checkHeaderAvailability(ByteBuf in) {
    if (in.readableBytes() < 1) {
      return false;
    }
    // byte h1 = in.get();
    // byte messageType = (byte) ((h1 & 0x00F0) >> 4);
    in.skipBytes(1); // skip the messageType byte

    int remainingLength = Utils.decodeRemainingLenght(in);
    if (remainingLength == -1) {
      return false;
    }

    // check remaining length
    if (in.readableBytes() < remainingLength) {
      return false;
    }

    // return messageType == type ? MessageDecoderResult.OK : MessageDecoderResult.NOT_OK;
    return true;
  }