private ByteBuf tryDecodeChallenge(ByteBuf in, int offset, int readableBytes) throws IOException { if (readableBytes < 4) { return null; } int len = in.getInt(offset); if (len <= 0) { // fall back to simple in.readerIndex(offset + 4); return in.retainedSlice(offset, 4); } if (len > MAX_CHALLENGE_SIZE) { throw new IOException( "Sasl challenge too large(" + len + "), max allowed is " + MAX_CHALLENGE_SIZE); } int totalLen = 4 + len; if (readableBytes < totalLen) { return null; } in.readerIndex(offset + totalLen); return in.retainedSlice(offset, totalLen); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int readableBytes = in.readableBytes(); if (readableBytes < 4) { return; } int offset = in.readerIndex(); int status = in.getInt(offset); if (status == SaslStatus.SUCCESS.state) { ByteBuf challenge = tryDecodeChallenge(in, offset + 4, readableBytes - 4); if (challenge != null) { out.add(challenge); } } else { tryDecodeError(in, offset + 4, readableBytes - 4); } } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int readableBytes = in.readableBytes(); if (readableBytes < 4) { return; } int offset = in.readerIndex(); int status = in.getInt(offset); if (status == SaslStatus.SUCCESS.state) { ByteBuf challenge = tryDecodeChallenge(in, offset + 4, readableBytes - 4); if (challenge != null) { out.add(challenge); } } else { tryDecodeError(in, offset + 4, readableBytes - 4); } } }
private ByteBuf tryDecodeChallenge(ByteBuf in, int offset, int readableBytes) throws IOException { if (readableBytes < 4) { return null; } int len = in.getInt(offset); if (len <= 0) { // fall back to simple in.readerIndex(offset + 4); return in.retainedSlice(offset, 4); } if (len > MAX_CHALLENGE_SIZE) { throw new IOException( "Sasl challenge too large(" + len + "), max allowed is " + MAX_CHALLENGE_SIZE); } int totalLen = 4 + len; if (readableBytes < totalLen) { return null; } in.readerIndex(offset + totalLen); return in.retainedSlice(offset, totalLen); }
@Override public int getInt(int index) { return buf.getInt(index); }
/** * Hashes the 4 bytes located at index, shifting the resulting hash into * the appropriate range for our hash table. * * @param in The input buffer to read 4 bytes from * @param index The index to read at * @param shift The shift value, for ensuring that the resulting value is * withing the range of our hash table size * @return A 32-bit hash of 4 bytes located at index */ private static int hash(ByteBuf in, int index, int shift) { return in.getInt(index) * 0x1e35a7bd >>> shift; }
@Override public int getIntLE(int index) { return buf.getInt(index); }
@Override public int getInt(int index) { checkIndex(index, 4); return buffer.getInt(index); }
@Override public int getInt(int index) { return unwrap().getInt(index); }
@Override public int getInt(int index) { return unwrap().getInt(index); }
@Override protected int _getInt(int index) { return unwrap().getInt(index); }
@Override public int getInt(int index) { return ByteBufUtil.swapInt(buf.getInt(index)); }
@Override protected int _getInt(int index) { return unwrap().getInt(index); }
@Override protected int _getInt(int index) { return unwrap().getInt(idx(index)); }
@Override public int getInt(int index) { checkIndex0(index, 4); return unwrap().getInt(idx(index)); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int readableBytes = in.readableBytes(); if (readableBytes < 4) { return; } int offset = in.readerIndex(); int status = in.getInt(offset); if (status == SaslStatus.SUCCESS.state) { ByteBuf challenge = tryDecodeChallenge(in, offset + 4, readableBytes - 4); if (challenge != null) { out.add(challenge); } } else { tryDecodeError(in, offset + 4, readableBytes - 4); } } }
@Override protected int _getInt(int index) { Component c = findComponent(index); if (index + 4 <= c.endOffset) { return c.buf.getInt(index - c.offset); } else if (order() == ByteOrder.BIG_ENDIAN) { return (_getShort(index) & 0xffff) << 16 | _getShort(index + 2) & 0xffff; } else { return _getShort(index) & 0xFFFF | (_getShort(index + 2) & 0xFFFF) << 16; } }
@Override protected int _getInt(int index) { Component c = findComponent(index); if (index + 4 <= c.endOffset) { return c.buf.getInt(index - c.offset); } else if (order() == ByteOrder.BIG_ENDIAN) { return (_getShort(index) & 0xffff) << 16 | _getShort(index + 2) & 0xffff; } else { return _getShort(index) & 0xFFFF | (_getShort(index + 2) & 0xFFFF) << 16; } }