Example #1
0
 @Override
 public long getUnsignedInt(int index) {
   return buf.getUnsignedInt(index);
 }
  public long decodeLength(ByteBuf in, int offset) throws Exception {
    if (discardingTooLongFrame) {
      long bytesToDiscard = this.bytesToDiscard;
      int localBytesToDiscard = (int) Math.min(bytesToDiscard, in.readableBytes());
      in.skipBytes(localBytesToDiscard);
      bytesToDiscard -= localBytesToDiscard;
      this.bytesToDiscard = bytesToDiscard;

      failIfNecessary(false);
    }

    int readerIndex = in.readerIndex() + offset;
    short b = in.getUnsignedByte(readerIndex);
    int ubyte = b & 0xff;

    LOGGER.trace("message: " + toHex(ubyte));

    switch (ubyte) {
      case NIL:
        return 1L;
      case FALSE:
        return 1L;
      case TRUE:
        return 1L;
      case BIN8:
        {
          short length = in.getUnsignedByte(readerIndex + 1);
          return 2L + length;
        }
      case BIN16:
        {
          int length = in.getUnsignedShort(readerIndex + 1);
          return 3L + length;
        }
      case BIN32:
        {
          long length = in.getUnsignedInt(readerIndex + 1);
          return 5L + length;
        }
      case EXT8:
        {
          short length = in.getUnsignedByte(readerIndex + 1);
          return 3L + length;
        }
      case EXT16:
        {
          int length = in.getUnsignedShort(readerIndex + 1);
          return 4L + length;
        }
      case EXT32:
        {
          long length = in.getUnsignedInt(readerIndex + 1);
          return 6L + length;
        }

      case FLOAT32:
        return 5L;
      case FLOAT64:
        return 9L;
      case UINT8:
        return 2L;
      case UINT16:
        return 3L;
      case UINT32:
        return 5L;
      case UINT64:
        return 9L;
      case INT8:
        return 2L;
      case INT16:
        return 3L;
      case INT32:
        return 5L;
      case INT64:
        return 9L;
      case FIXEXT1:
        return 3L;
      case FIXEXT2:
        return 4L;
      case FIXEXT4:
        return 6L;
      case FIXEXT8:
        return 10L;
      case FIXEXT16:
        return 18L;
      case STR8:
        {
          short length = in.getUnsignedByte(readerIndex + 1);
          return 2L + length;
        }
      case STR16:
        {
          int length = in.getUnsignedShort(readerIndex + 1);
          return 3L + length;
        }
      case STR32:
        {
          long length = in.getUnsignedInt(readerIndex + 1);
          return 5L + length;
        }
      case ARRAY16:
        {
          int elemCount = in.getUnsignedShort(readerIndex + 1);
          return getArraySize(in, 3, offset, elemCount);
        }
      case ARRAY32:
        {
          long elemCount = in.getUnsignedInt(readerIndex + 1);
          return getArraySize(in, 5, offset, elemCount);
        }
      case MAP16:
        {
          int elemCount = in.getUnsignedShort(readerIndex + 1);
          return getArraySize(in, 3, offset, elemCount * 2);
        }
      case MAP32:
        {
          long elemCount = in.getUnsignedInt(readerIndex + 1);
          return getArraySize(in, 5, offset, elemCount * 2);
        }
      default:
        if ((ubyte >> 7) == 0) { // positive fixint
          return 1L;
        } else if ((ubyte >> 4) == 0b1000) { // fixmap
          int elemCount = ubyte & 0b00001111;
          return getArraySize(in, 1, offset, elemCount * 2);
        } else if ((ubyte >> 4) == 0b1001) { // fixarray
          int elemCount = ubyte & 0b00001111;
          return getArraySize(in, 1, offset, elemCount);
        } else if ((ubyte >> 5) == 0b101) { // fixstr
          int length = ubyte & 0b00011111;
          return 1L + length;
        } else if ((ubyte >> 5) == 0b111) { // negative fixint
          return 1L;
        } else {
          throw new CorruptedFrameException("Unknown header byte of message: " + toHex(ubyte));
        }
    }
  }
 @Override
 public long getUnsignedInt(int var1) {
   return a.getUnsignedInt(var1);
 }