Source:
protected void decode(ChannelHandlerContext chc, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() >= 4) { in.markReaderIndex(); int length = in.readInt(); if (in.readableBytes() < length) { in.resetReaderIndex(); } else { byte code = in.readByte(); byte[] protobuf = new byte[length - 1]; in.readBytes(protobuf); switch(state) { case TLS_WAIT: switch(code) { case RiakMessageCodes.MSG_RpbStartTls: logger.debug("Received MSG_RpbStartTls reply"); this.state = State.SSL_WAIT; SslHandler sslHandler = new SslHandler(sslEngine); Future<Channel> hsFuture = sslHandler.handshakeFuture(); hsFuture.addListener(new SslListener()); chc.channel().pipeline().addFirst("SSL", sslHandler); break; case RiakMessageCodes.MSG_ErrorResp: logger.debug("Received MSG_ErrorResp reply to startTls"); promise.tryFailure((riakErrorToException(protobuf))); break; default: promise.tryFailure(new RiakResponseException(0, "Invalid return code during StartTLS; " + code)); } break; case AUTH_WAIT: chc.channel().pipeline().remove(this); switch(code) { case RiakMessageCodes.MSG_RpbAuthResp: logger.debug("Received MSG_RpbAuthResp reply"); promise.trySuccess(null); break; case RiakMessageCodes.MSG_ErrorResp: logger.debug("Received MSG_ErrorResp reply to auth"); promise.tryFailure(riakErrorToException(protobuf)); break; default: promise.tryFailure(new RiakResponseException(0, "Invalid return code during Auth; " + code)); } break; default: logger.error("Received message while not in TLS_WAIT or AUTH_WAIT"); promise.tryFailure(new IllegalStateException("Received message while not in TLS_WAIT or AUTH_WAIT")); } } } }

Target:
protected void decode(ChannelHandlerContext chc, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() >= 4) { in.markReaderIndex(); int length = in.readInt(); if (in.readableBytes() < length) { in.resetReaderIndex(); } else { byte code = in.readByte(); byte[] protobuf = new byte[length - 1]; in.readBytes(protobuf); switch(state) { case TLS_WAIT: switch(code) { case RiakMessageCodes.MSG_StartTls: logger.debug("Received MSG_RpbStartTls reply"); this.state = State.SSL_WAIT; SslHandler sslHandler = new SslHandler(sslEngine); Future<Channel> hsFuture = sslHandler.handshakeFuture(); hsFuture.addListener(new SslListener()); chc.channel().pipeline().addFirst("SSL", sslHandler); break; case RiakMessageCodes.MSG_ErrorResp: logger.debug("Received MSG_ErrorResp reply to startTls"); promise.tryFailure((riakErrorToException(protobuf))); break; default: promise.tryFailure(new RiakResponseException(0, "Invalid return code during StartTLS; " + code)); } break; case AUTH_WAIT: chc.channel().pipeline().remove(this); switch(code) { case RiakMessageCodes.MSG_AuthResp: logger.debug("Received MSG_RpbAuthResp reply"); promise.trySuccess(null); break; case RiakMessageCodes.MSG_ErrorResp: logger.debug("Received MSG_ErrorResp reply to auth"); promise.tryFailure(riakErrorToException(protobuf)); break; default: promise.tryFailure(new RiakResponseException(0, "Invalid return code during Auth; " + code)); } break; default: logger.error("Received message while not in TLS_WAIT or AUTH_WAIT"); promise.tryFailure(new IllegalStateException("Received message while not in TLS_WAIT or AUTH_WAIT")); } } } }