Skip to content

Commit

Permalink
misc:add zip encode to serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
lindzh committed Jul 30, 2015
1 parent a682792 commit 34aa47e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public RpcNioConnector(){
}

private void initBuf(){
channelWriteBuffer = ByteBuffer.allocate(RpcUtils.MEM_8KB);
channelReadBuffer = ByteBuffer.allocate(RpcUtils.MEM_8KB);
rpcNioReadBuffer = new RpcNioBuffer(RpcUtils.MEM_8KB);
rpcNioWriteBuffer = new RpcNioBuffer(RpcUtils.MEM_8KB);
channelWriteBuffer = ByteBuffer.allocate(RpcUtils.MEM_32KB);
channelReadBuffer = ByteBuffer.allocate(RpcUtils.MEM_32KB);
rpcNioReadBuffer = new RpcNioBuffer(RpcUtils.MEM_32KB);
rpcNioWriteBuffer = new RpcNioBuffer(RpcUtils.MEM_32KB);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.ObjectOutputStream;

import com.linda.framework.rpc.exception.RpcException;
import com.linda.framework.rpc.utils.NioUtils;

public class JdkSerializer implements RpcSerializer {

Expand All @@ -16,7 +17,9 @@ public byte[] serialize(Object obj) {
ObjectOutputStream stream = new ObjectOutputStream(bis);
stream.writeObject(obj);
stream.close();
return bis.toByteArray();
byte[] bytes = bis.toByteArray();
//使用zip压缩,缩小网络包
return NioUtils.zip(bytes);
} catch (Exception e) {
throw new RpcException(e);
}
Expand All @@ -25,7 +28,9 @@ public byte[] serialize(Object obj) {
@Override
public Object deserialize(byte[] bytes) {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
//使用zip解压缩
byte[] unzip = NioUtils.unzip(bytes);
ByteArrayInputStream bis = new ByteArrayInputStream(unzip);
ObjectInputStream stream = new ObjectInputStream(bis);
return stream.readObject();
} catch (Exception e) {
Expand Down

0 comments on commit 34aa47e

Please sign in to comment.