class CompatibleCodec implements Codec {
    private Codec v1 = new DefaultRpcCodec();
    private Codec v1Compress = new CompressRpcCodec();
    private Codec v2 = new MotanV2Codec();

    @Override
    public byte[] encode(Channel channel, Object message) throws IOException {
        if (message instanceof Response) {// depends on the request protocol in server end.
            byte version = ((Response) message).getRpcProtocolVersion();
            if (version == RpcProtocolVersion.VERSION_1.getVersion()) {
                return v1.encode(channel, message);
            } else if (version == RpcProtocolVersion.VERSION_1_Compress.getVersion()) {
                return v1Compress.encode(channel, message);
            }
        }
        return v2.encode(channel, message);// v2 codec as default.
    }

    @Override
    public Object decode(Channel channel, String remoteIp, byte[] buffer) throws IOException {<FILL_FUNCTION_BODY>}
}

        if (buffer.length < 2) {
            throw new MotanServiceException("not enough bytes for decode. length:" + buffer.length);
        }
        short type = ByteUtil.bytes2short(buffer, 0);
        if (type == DefaultRpcCodec.MAGIC) {
            return v1Compress.decode(channel, remoteIp, buffer);
        } else if (type == MotanV2Header.MAGIC) {
            return v2.decode(channel, remoteIp, buffer);
        }
        throw new MotanFrameworkException("decode error: magic error. magic:" + type);
    
<no_super_class>