ZlibCompress 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); outputStream = new DeflaterOutputStream(outputStream); CodedOutputStream codedOutputStream = CodedOutputStream.newInstance(outputStream, protoSize); rpcMethodInfo.inputWriteToStream(proto, codedOutputStream); outputStream.close(); return resBuf; }  @Override ByteBuf compressInput(Object proto, RpcMethodInfo rpcMethodInfo); @Override Object uncompressOutput(ByteBuf byteBuf, RpcMethodInfo rpcMethodInfo); @Override Object uncompressOutput(byte[] bytes, RpcMethodInfo rpcMethodInfo); @Override Object uncompressOutput(DynamicCompositeByteBuf byteBuf, RpcMethodInfo rpcMethodInfo); @Override Object uncompressInput(ByteBuf byteBuf, RpcMethodInfo rpcMethodInfo); @Override Object uncompressInput(byte[] bytes, RpcMethodInfo rpcMethodInfo); @Override Object uncompressInput(DynamicCompositeByteBuf byteBuf, RpcMethodInfo rpcMethodInfo); @Override ByteBuf compressOutput(Object proto, RpcMethodInfo rpcMethodInfo);  }
@Test public void testCompressInputForProtobuf() throws IOException { Echo.EchoRequest request = Echo.EchoRequest.newBuilder().setMessage("hello").build(); ByteBuf byteBuf = compress.compressInput(request, protobufRpcMethodInfo); System.out.println(byteBuf.readableBytes()); }
@Test public void testCompressInputForJprotobuf() throws IOException { EchoRequest request = new EchoRequest(); request.setMessage("hello"); ByteBuf byteBuf = compress.compressInput(request, jprotobufRpcMethodInfo); System.out.println(byteBuf.readableBytes()); }