@Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        in.markReaderIndex();
        ProtocolCode protocolCode;
        Protocol protocol;
        try {
            protocolCode = decodeProtocolCode(in);
            if (protocolCode == null) {
                // read to end
                return;
            }

            byte protocolVersion = decodeProtocolVersion(in);
            if (ctx.channel().attr(Connection.PROTOCOL).get() == null) {
                ctx.channel().attr(Connection.PROTOCOL).set(protocolCode);
                if (DEFAULT_ILLEGAL_PROTOCOL_VERSION_LENGTH != protocolVersion) {
                    ctx.channel().attr(Connection.VERSION).set(protocolVersion);
                }
            }

            protocol = ProtocolManager.getProtocol(protocolCode);
        } finally {
            // reset the readerIndex before throwing an exception or decoding content
            // to ensure that the packet is complete
            in.resetReaderIndex();
        }

        if (protocol == null) {
            throw new CodecException("Unknown protocol code: [" + protocolCode
                                     + "] while decode in ProtocolDecoder.");
        }

        protocol.getDecoder().decode(ctx, in, out);
    }
decode the protocol version

@param in input byte buf
@return a byte to represent protocol version
src/main/java/com/alipay/remoting/codec/ProtocolCodeBasedDecoder.java