class GzipCompress implements Compress {

    @Override
    public ByteBuf compressInput(Object proto, RpcMethodInfo rpcMethodInfo) throws IOException {
        int protoSize = rpcMethodInfo.getInputSerializedSize(proto);
        ByteBuf resBuf = Unpooled.buffer(protoSize);
        OutputStream outputStream = new ByteBufOutputStream(resBuf);
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream);

        if (protoSize > CodedOutputStream.DEFAULT_BUFFER_SIZE) {
            protoSize = CodedOutputStream.DEFAULT_BUFFER_SIZE;
        }
        final CodedOutputStream codedOutputStream =
                CodedOutputStream.newInstance(gzipOutputStream, protoSize);
        rpcMethodInfo.inputWriteToStream(proto, codedOutputStream);
        gzipOutputStream.close();
        return resBuf;
    }

}